core/state: add bounds check in heap eviction loop (#33712)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

core/state: add bounds check in heap eviction loop

Add len(h) > 0 check before accessing h[0] to prevent potential panic
and align with existing heap access patterns in txpool, p2p, and mclock
packages.
This commit is contained in:
Noisy 2026-01-29 14:08:04 +01:00 committed by GitHub
parent c974722dc0
commit a179ccf6f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -346,7 +346,7 @@ func (t *SizeTracker) run() {
// Evict the stale statistics
heap.Push(&h, stats[u.root])
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
for len(h) > 0 && u.blockNumber-h[0].BlockNumber > statEvictThreshold {
delete(stats, h[0].StateRoot)
heap.Pop(&h)
}