store grows forever — messages map never cleaned
Report
What happens
In chat/chat.go there are two maps: seen (dedupe) and messages. The seen map gets pruned in pruneSeenLocked() (drops entries older than 2x MaxEnvelopeSkew) but messages is never cleaned at all. Every envelope that passes VerifyFull gets stored under the To address and also under From (unless self-send), and those map keys stay forever even after the envelope would be considered stale.
So a client with one valid keypair can keep minting new "accounts" and the node just grows.
Repro
Ran this against the store directly (same path the account_chat handler uses):
go for i := 0; i < 20000; i++ { kp, _ := core.GenerateKeyPair() from := kp.Address() to := fmt.Sprintf("%064x", i) // fresh "account" every time env, _ := chat.NewEnvelope(from, to, "x", kp, 0) env.VerifyFull(0) store.Store(env) }
Output: envelopes accepted: 20000 / 20000 in 2.39s heap allocated during attack: 51.41 MB distinct account keys in messages map: 40000 (expected ~40000 = 2N, never pruned)
20k envelopes -> 40k permanent map keys, ~20MB heap kept after GC. Nothing stops me from doing this continuously for hours.
Notes
- If
ChatDifficultyis 0 the PoW check is skipped entirely (chat/envelope.go:difficulty > 0 && ...), so each envelope costs basically nothing. maxPerAccount(1000) only caps messages per existing key, it doesn't stop new keys being added.- Happens both via the HTTP
POST /chat/sendpath and the p2paccount_chathandler, so peers can also fill each other up.
Suggested fix
Evict per-account buckets whose newest message is older than the freshness window, similar to how seen is pruned. Or don't store anything for accounts that were never seen on-chain.
Worst case is a node eating RAM until OOM, which lands in the Track 2 "load that exhausts a node's memory" bucket.
Thread
Hi, following up on this one — the fix shipped in testnet-0006 (Nov 16) and #247 is still open as triaged. Is there anything else you need from me for the tier to be assigned? Thanks!