core/state: don't use the prefetcher for missing snapshot items

This commit is contained in:
Péter Szilágyi 2024-05-06 17:24:18 +03:00
parent f5ec2e7841
commit 6d3c6a1963
3 changed files with 13 additions and 8 deletions

View file

@ -165,7 +165,7 @@ func (s *StateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []
} }
if !conf.SkipStorage { if !conf.SkipStorage {
account.Storage = make(map[common.Hash]string) account.Storage = make(map[common.Hash]string)
tr, err := obj.getTrie() tr, err := obj.getTrie(true)
if err != nil { if err != nil {
log.Error("Failed to load storage trie", "err", err) log.Error("Failed to load storage trie", "err", err)
continue continue

View file

@ -130,11 +130,16 @@ func (s *stateObject) touch() {
// getTrie returns the associated storage trie. The trie will be opened // getTrie returns the associated storage trie. The trie will be opened
// if it's not loaded previously. An error will be returned if trie can't // if it's not loaded previously. An error will be returned if trie can't
// be loaded. // be loaded.
func (s *stateObject) getTrie() (Trie, error) { //
// The skipPrefetcher parameter is used to request a direct load from disk, even
// if a prefetcher is available. This path is used if snapshots are unavailable,
// since that requires reading the trie *during* execution, when the prefetchers
// cannot yet return data.
func (s *stateObject) getTrie(skipPrefetcher bool) (Trie, error) {
if s.trie == nil { if s.trie == nil {
// Try fetching from prefetcher first // Try fetching from prefetcher first, unless skipping it was explicitly
if s.data.Root != types.EmptyRootHash && s.db.prefetcher != nil { // requested
// When the miner is creating the pending state, there is no prefetcher if s.data.Root != types.EmptyRootHash && s.db.prefetcher != nil && !skipPrefetcher {
trie, err := s.db.prefetcher.trie(s.addrHash, s.data.Root) trie, err := s.db.prefetcher.trie(s.addrHash, s.data.Root)
if err != nil { if err != nil {
log.Error("Failed to retrieve storage pre-fetcher trie", "addr", s.address, "err", err) log.Error("Failed to retrieve storage pre-fetcher trie", "addr", s.address, "err", err)
@ -211,7 +216,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
// If the snapshot is unavailable or reading from it fails, load from the database. // If the snapshot is unavailable or reading from it fails, load from the database.
if s.db.snap == nil || err != nil { if s.db.snap == nil || err != nil {
start := time.Now() start := time.Now()
tr, err := s.getTrie() tr, err := s.getTrie(true)
if err != nil { if err != nil {
s.db.setError(err) s.db.setError(err)
return common.Hash{} return common.Hash{}
@ -315,7 +320,7 @@ func (s *stateObject) updateTrie() (Trie, error) {
storage map[common.Hash][]byte storage map[common.Hash][]byte
origin map[common.Hash][]byte origin map[common.Hash][]byte
) )
tr, err := s.getTrie() tr, err := s.getTrie(false)
if err != nil { if err != nil {
s.db.setError(err) s.db.setError(err)
return nil, err return nil, err

View file

@ -551,7 +551,7 @@ func forEachStorage(s *StateDB, addr common.Address, cb func(key, value common.H
if so == nil { if so == nil {
return nil return nil
} }
tr, err := so.getTrie() tr, err := so.getTrie(true)
if err != nil { if err != nil {
return err return err
} }