Skip to content

Commit

Permalink
get prefetcher before use to avoid been modified bwteen access and no…
Browse files Browse the repository at this point in the history
…t-nil condition
  • Loading branch information
qinglin89 committed Jul 22, 2022
1 parent d93211b commit e451b05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ func (s *StateObject) updateTrie(db Database) Trie {
}
wg.Wait()

if s.db.prefetcher != nil {
s.db.prefetcher.used(s.data.Root, usedStorage)
prefetcher := s.db.prefetcher
if prefetcher != nil {
prefetcher.used(s.data.Root, usedStorage)
}

if len(s.pendingStorage) > 0 {
s.pendingStorage = make(Storage)
}
Expand Down
10 changes: 6 additions & 4 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,9 @@ func (s *StateDB) Copy() *StateDB {
// If there's a prefetcher running, make an inactive copy of it that can
// only access data but does not actively preload (since the user will not
// know that they need to explicitly terminate an active copy).
if s.prefetcher != nil {
state.prefetcher = s.prefetcher.copy()
prefetcher := s.prefetcher
if prefetcher != nil {
state.prefetcher = prefetcher.copy()
}
if s.snaps != nil {
// In order for the miner to be able to use and make additions
Expand Down Expand Up @@ -970,8 +971,9 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
addressesToPrefetch = append(addressesToPrefetch, common.CopyBytes(addr[:])) // Copy needed for closure
}
}
if s.prefetcher != nil && len(addressesToPrefetch) > 0 {
s.prefetcher.prefetch(s.originalRoot, addressesToPrefetch, emptyAddr)
prefetcher := s.prefetcher
if prefetcher != nil && len(addressesToPrefetch) > 0 {
prefetcher.prefetch(s.originalRoot, addressesToPrefetch, emptyAddr)
}
// Invalidate journal because reverting across transactions is not allowed.
s.clearJournalAndRefund()
Expand Down

0 comments on commit e451b05

Please sign in to comment.