From d74dd391311fa99714d7178d76f22841fb1f14bf Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 25 Aug 2025 10:04:31 +0800 Subject: [PATCH] expose stats --- core/state/state_sizer.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/state/state_sizer.go b/core/state/state_sizer.go index ac9d007f1d..0d2a13bc96 100644 --- a/core/state/state_sizer.go +++ b/core/state/state_sizer.go @@ -235,6 +235,7 @@ type SizeTracker struct { abort chan struct{} aborted chan struct{} updateCh chan *stateUpdate + stats map[common.Hash]SizeStats // internal stats map } // NewSizeTracker creates a new state size tracker and starts it automatically @@ -248,6 +249,7 @@ func NewSizeTracker(db ethdb.KeyValueStore, triedb *triedb.Database) (*SizeTrack abort: make(chan struct{}), aborted: make(chan struct{}), updateCh: make(chan *stateUpdate), + stats: make(map[common.Hash]SizeStats), } go t.run() return t, nil @@ -286,13 +288,14 @@ func (t *SizeTracker) run() { if err != nil { return } + t.stats = stats h := sizeStatsHeap(slices.Collect(maps.Values(stats))) heap.Init(&h) for { select { case u := <-t.updateCh: - base, found := stats[u.originRoot] + base, found := t.stats[u.originRoot] if !found { continue } @@ -301,15 +304,14 @@ func (t *SizeTracker) run() { continue } stat := base.add(diff) - stats[u.root] = stat + t.stats[u.root] = stat t.upload(stat) - heap.Push(&h, stats[u.root]) - for u.blockNumber-h[0].BlockNumber > statEvictThreshold { - delete(stats, h[0].StateRoot) + heap.Push(&h, t.stats[u.root]) + for len(h) > 0 && u.blockNumber-h[0].BlockNumber > statEvictThreshold { + delete(t.stats, h[0].StateRoot) heap.Pop(&h) } - case <-t.abort: return } @@ -512,6 +514,8 @@ func (t *SizeTracker) Notify(update *stateUpdate) { case t.updateCh <- update: case <-t.abort: return + default: + // Drop update if channel is full } }