{"id":"XE-0317","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"247","source_url":"https://github.com/xeprotocol/xe/issues/247","reporter_id":134,"title":"store grows forever — messages map never cleaned","area":null,"claimed_tier":null,"assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-03T12:06:36.591205+00:00","updated_at":"2026-11-24T09:05:14.204403+00:00","source_created_at":"2026-11-03T12:04:36+00:00","told_at":null,"status_changed_at":"2026-11-05T04:17:39.692334+00:00","url":"https://bounty.xe.network/XE-0317","body":"## What happens\n\nIn `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.\n\nSo a client with one valid keypair can keep minting new \"accounts\" and the node just grows.\n\n## Repro\n\nRan this against the store directly (same path the `account_chat` handler uses):\n\ngo\nfor i := 0; i < 20000; i++ {\n    kp, _ := core.GenerateKeyPair()\n    from := kp.Address()\n    to := fmt.Sprintf(\"%064x\", i) // fresh \"account\" every time\n    env, _ := chat.NewEnvelope(from, to, \"x\", kp, 0)\n    env.VerifyFull(0)\n    store.Store(env)\n}\n\nOutput:\nenvelopes accepted: 20000 / 20000 in 2.39s\nheap allocated during attack: 51.41 MB\ndistinct account keys in messages map: 40000 (expected ~40000 = 2N, never pruned)\n\n\n20k envelopes -> 40k permanent map keys, ~20MB heap kept after GC. Nothing stops me from doing this continuously for hours.\n\n## Notes\n\n- If `ChatDifficulty` is 0 the PoW check is skipped entirely (chat/envelope.go: `difficulty > 0 && ...`), so each envelope costs basically nothing.\n- `maxPerAccount` (1000) only caps messages *per existing key*, it doesn't stop new keys being added.\n- Happens both via the HTTP `POST /chat/send` path and the p2p `account_chat` handler, so peers can also fill each other up.\n\n## Suggested fix\n\nEvict 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.\n\nWorst case is a node eating RAM until OOM, which lands in the Track 2 \"load that exhausts a node's memory\" bucket.\n\n\n","patch_refs":[{"id":249,"repo":"xeprotocol/xe","kind":"pr","ref":"7","title":"fix(core,statechain,perf,directory,chat): harden multisig threshold & conflict unwind, certificate verification, directory & chat bounds","url":"https://github.com/xeprotocol/xe/pull/7","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-04T01:36:24.869505+00:00"},{"id":479,"repo":"xeprotocol/xe","kind":"pr","ref":"313","title":"fix(chat): prune stale messages and bound accounts map (fixes #247)","url":"https://github.com/xeprotocol/xe/pull/313","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-10T00:12:01.832547+00:00"},{"id":723,"repo":"xeprotocol/xe","kind":"pr","ref":"782","title":"chat: prune stale per-account message buckets (fixes #247)","url":"https://github.com/xeprotocol/xe/pull/782","note":"","state":"open","author":"adli582","added_by":"desk","created_at":"2026-11-17T22:40:35.121963+00:00"}],"thread":[{"id":20636,"source":"web","source_ref":"reporter:134:7fe050e912de1139","author":"adli582","team":false,"body":"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!","created_at":"2026-11-24T09:05:14.189837+00:00"}]}