<!-- XE-0317 · store grows forever — messages map never cleaned · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0317>. The page is the record; this is the same page for reading.*

XE-0317 · Bounty

# store grows forever — messages map never cleaned

Triaging
[xe#247](https://github.com/xeprotocol/xe/issues/247)
filed 2026-11-03 12:04 UTC
by adli582

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   —

Area
:   —

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-24 09:05 UTC

### Patches

- [xe#7](https://github.com/xeprotocol/xe/pull/7) open by Khanhtnq
  fix(core,statechain,perf,directory,chat): harden multisig threshold \& conflict unwind, certificate verification, directory \& chat bounds
- [xe#313](https://github.com/xeprotocol/xe/pull/313) open by arturbarszcz78
  fix(chat): prune stale messages and bound accounts map (fixes #247)
- [xe#782](https://github.com/xeprotocol/xe/pull/782) open by adli582
  chat: prune stale per-account message buckets (fixes #247)

### History

- [462562](https://bounty.xe.network/log/462562) 2026-11-17 22:40 UTC patch.linked
- [61313](https://bounty.xe.network/log/61313) 2026-11-10 00:12 UTC patch.linked
- [5061](https://bounty.xe.network/log/5061) 2026-11-05 04:18 UTC github.labels
- [5036](https://bounty.xe.network/log/5036) 2026-11-05 04:17 UTC ticket.status accepted → triaging
- [5035](https://bounty.xe.network/log/5035) 2026-11-05 04:17 UTC ticket.status fixing → accepted
- [2646](https://bounty.xe.network/log/2646) 2026-11-04 01:36 UTC github.labels
- [2642](https://bounty.xe.network/log/2642) 2026-11-04 01:36 UTC ticket.status accepted → fixing
- [2641](https://bounty.xe.network/log/2641) 2026-11-04 01:36 UTC ticket.status triaging → accepted
- [2640](https://bounty.xe.network/log/2640) 2026-11-04 01:36 UTC ticket.status new → triaging
- [2639](https://bounty.xe.network/log/2639) 2026-11-04 01:36 UTC patch.linked
- [2362](https://bounty.xe.network/log/2362) 2026-11-03 12:06 UTC note.added
- [2361](https://bounty.xe.network/log/2361) 2026-11-03 12:06 UTC ticket.created

[Full history](https://bounty.xe.network/log?ref=XE-0317) · [JSON](https://bounty.xe.network/v1/tickets/XE-0317) · [markdown](https://bounty.xe.network/XE-0317.md)

### 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 `ChatDifficulty` is 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/send` path and the p2p `account_chat` handler, 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

**adli582**2026-11-24 09:05 UTCweb

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!
