blockchain: ensure state exists for prefetcher #20627, fix #1738 (#1742)

This commit is contained in:
Daniel Liu 2025-11-14 22:28:35 +08:00 committed by GitHub
parent b31cbfed40
commit 1eec428928
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1782,18 +1782,19 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
var followupInterrupt atomic.Bool
if !bc.cacheConfig.TrieCleanNoPrefetch {
if followup, err := it.peek(); followup != nil && err == nil {
go func(start time.Time) {
throwaway, _ := state.New(parent.Root, bc.stateCache)
throwaway, _ := state.New(parent.Root, bc.stateCache)
go func(start time.Time, followup *types.Block, throwaway *state.StateDB, interrupt *atomic.Bool) {
// Disable tracing for prefetcher executions.
vmCfg := bc.vmConfig
vmCfg.Tracer = nil
bc.prefetcher.Prefetch(followup, throwaway, vmCfg, &followupInterrupt)
bc.prefetcher.Prefetch(followup, throwaway, vmCfg, interrupt)
blockPrefetchExecuteTimer.Update(time.Since(start))
if followupInterrupt.Load() {
if interrupt.Load() {
blockPrefetchInterruptMeter.Mark(1)
}
}(time.Now())
}(time.Now(), followup, throwaway, &followupInterrupt)
}
}