Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
** nil check refine
** create a separate routine for From/To prefetch, avoid blocking the cirtical path
  • Loading branch information
setunapo committed Jul 4, 2022
1 parent a5a7fa8 commit 0f24077
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0f24077

Please sign in to comment.