diff --git a/core/state/statedb.go b/core/state/statedb.go index 646216c194..8aa610c1b6 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -921,14 +921,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { prefetcher := s.prefetcher if s.prefetcher != nil { defer func() { - // TODO: need to wait for read accounts to be resolved in prefetcher main trie? - s.prefetcher.close() - + s.prefetcher.wait() if s.witness != nil { // TODO: move read prefetcher logic into Commit? s.collectReadStorageAccessLists() s.collectReadAccountsAccessLists() } + s.prefetcher.close() s.prefetcher = nil }() } diff --git a/core/state/trie_prefetcher.go b/core/state/trie_prefetcher.go index 6e3a594bd6..f8258b51ae 100644 --- a/core/state/trie_prefetcher.go +++ b/core/state/trie_prefetcher.go @@ -210,6 +210,14 @@ func (sf *subfetcher) schedule(keys [][]byte) { } } +// wait instructs all subfetchers to finish their tasks +// and stop receiving new requests. +func (p *triePrefetcher) wait() { + for _, fetcher := range p.fetchers { + fetcher.wait() + } +} + // wait waits for the subfetcher to finish it's task. It is safe to call wait multiple // times but it is not thread safe. func (sf *subfetcher) wait() {