eth/txtracker: compact FIFO order slice to prevent memory leak

order = order[1:] reslices without releasing the backing array.
After N total insertions the array retains N hashes (32 bytes each)
but only the last maxTracked are live. On a long-running node
processing ~100 txs/s this leaks ~275 MB/day.

Compact by copying to a fresh array when capacity exceeds 2×maxTracked.
This commit is contained in:
Csaba Kiraly 2026-04-10 16:40:08 +02:00
parent 803ac3c641
commit 7f1720b3dc

View file

@ -137,6 +137,11 @@ func (t *Tracker) NotifyAccepted(peer string, hashes []common.Hash) {
t.order = t.order[1:]
delete(t.txs, oldest)
}
// Compact the backing array when it grows too large. Reslicing
// with order[1:] doesn't free earlier slots in the array.
if cap(t.order) > 2*maxTracked {
t.order = append([]common.Hash(nil), t.order...)
}
}
// GetAllPeerStats returns a snapshot of per-peer inclusion statistics.