diff --git a/core/state/statedb.go b/core/state/statedb.go index 2182a2f648..dad82c30c4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -223,6 +223,9 @@ func (s *StateDB) StopPrefetcher() { } func (s *StateDB) TriePrefetchInAdvance(block *types.Block, signer types.Signer) { + if s.prefetcher == nil { + return + } accounts := make(map[common.Address]struct{}, block.Transactions().Len()<<1) for _, tx := range block.Transactions() { from, err := types.Sender(signer, tx) @@ -240,7 +243,7 @@ func (s *StateDB) TriePrefetchInAdvance(block *types.Block, signer types.Signer) addressesToPrefetch = append(addressesToPrefetch, common.CopyBytes(addr[:])) // Copy needed for closure } - if s.prefetcher != nil && len(addressesToPrefetch) > 0 { + if len(addressesToPrefetch) > 0 { s.prefetcher.prefetch(s.originalRoot, addressesToPrefetch, emptyAddr) } } diff --git a/core/state_processor.go b/core/state_processor.go index ba32022304..e2d3d8e03f 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -406,7 +406,10 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg statedb.MarkFullProcessed() // do trie prefetch for the big state trie tree in advance based transaction's From/To address. - statedb.TriePrefetchInAdvance(block, signer) + go func() { + // trie prefetcher is thread safe now, ok now to prefetch in a separate routine + statedb.TriePrefetchInAdvance(block, signer) + }() // usually do have two tx, one for validator set contract, another for system reward contract. systemTxs := make([]*types.Transaction, 0, 2)