@@ -235,6 +235,7 @@ type SizeTracker struct {
235235 abort chan struct {}
236236 aborted chan struct {}
237237 updateCh chan * stateUpdate
238+ stats map [common.Hash ]SizeStats // internal stats map
238239}
239240
240241// NewSizeTracker creates a new state size tracker and starts it automatically
@@ -248,6 +249,7 @@ func NewSizeTracker(db ethdb.KeyValueStore, triedb *triedb.Database) (*SizeTrack
248249 abort : make (chan struct {}),
249250 aborted : make (chan struct {}),
250251 updateCh : make (chan * stateUpdate ),
252+ stats : make (map [common.Hash ]SizeStats ),
251253 }
252254 go t .run ()
253255 return t , nil
@@ -286,13 +288,14 @@ func (t *SizeTracker) run() {
286288 if err != nil {
287289 return
288290 }
291+ t .stats = stats
289292 h := sizeStatsHeap (slices .Collect (maps .Values (stats )))
290293 heap .Init (& h )
291294
292295 for {
293296 select {
294297 case u := <- t .updateCh :
295- base , found := stats [u .originRoot ]
298+ base , found := t . stats [u .originRoot ]
296299 if ! found {
297300 continue
298301 }
@@ -301,15 +304,14 @@ func (t *SizeTracker) run() {
301304 continue
302305 }
303306 stat := base .add (diff )
304- stats [u .root ] = stat
307+ t . stats [u .root ] = stat
305308 t .upload (stat )
306309
307- heap .Push (& h , stats [u .root ])
308- for u .blockNumber - h [0 ].BlockNumber > statEvictThreshold {
309- delete (stats , h [0 ].StateRoot )
310+ heap .Push (& h , t . stats [u .root ])
311+ for len ( h ) > 0 && u .blockNumber - h [0 ].BlockNumber > statEvictThreshold {
312+ delete (t . stats , h [0 ].StateRoot )
310313 heap .Pop (& h )
311314 }
312-
313315 case <- t .abort :
314316 return
315317 }
@@ -512,6 +514,8 @@ func (t *SizeTracker) Notify(update *stateUpdate) {
512514 case t .updateCh <- update :
513515 case <- t .abort :
514516 return
517+ default :
518+ // Drop update if channel is full
515519 }
516520}
517521
0 commit comments