core: wait for prefetcher before reading PrefetchReadTimes

Forward prefetchStateReader.Wait() through *reader.WaitPrefetch and call
it before reading the read-time atomics. Eliminates the edge-case where
prefetcher goroutines outlast block execution + commit. For slow blocks
(the metric's target audience) this is a no-op; for fast blocks it
ensures the metric is complete rather than slightly under.
This commit is contained in:
CPerezz 2026-04-30 23:57:23 +02:00
parent 16e98f5d93
commit cd8ce62b40
No known key found for this signature in database
GPG key ID: 62045F34B97177DD
2 changed files with 11 additions and 0 deletions

View file

@ -683,6 +683,9 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
// Sum read times across per-tx execution, BAL state-transition, and
// prefetcher async fetches. Sum-of-CPU-time, not wall-clock.
if w, ok := prefetchReader.(interface{ WaitPrefetch() }); ok {
w.WaitPrefetch() // ensure all prefetcher reads are accounted for
}
var prefetchAccountReads, prefetchStorageReads time.Duration
if pr, ok := prefetchReader.(interface {
PrefetchReadTimes() (time.Duration, time.Duration)

View file

@ -576,3 +576,11 @@ func (r *reader) PrefetchReadTimes() (account, storage time.Duration) {
}
return 0, 0
}
// WaitPrefetch blocks until the wrapped prefetcher (if any) finishes its
// task list. No-op for non-prefetch readers.
func (r *reader) WaitPrefetch() {
if pr, ok := r.StateReader.(interface{ Wait() error }); ok {
_ = pr.Wait()
}
}