core/state: remove unused error from prefetcher trie method (#29768)
Co-authored-by: Gary Rong <garyrong0905@gmail.com> Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
e517183719
commit
171430c3f5
|
@ -150,11 +150,11 @@ func (s *stateObject) getTrie() (Trie, error) {
|
||||||
// trie in the state object. The caller might want to do that, but it's cleaner
|
// trie in the state object. The caller might want to do that, but it's cleaner
|
||||||
// to break the hidden interdependency between retrieving tries from the db or
|
// to break the hidden interdependency between retrieving tries from the db or
|
||||||
// from the prefetcher.
|
// from the prefetcher.
|
||||||
func (s *stateObject) getPrefetchedTrie() (Trie, error) {
|
func (s *stateObject) getPrefetchedTrie() Trie {
|
||||||
// If there's nothing to meaningfully return, let the user figure it out by
|
// If there's nothing to meaningfully return, let the user figure it out by
|
||||||
// pulling the trie from disk.
|
// pulling the trie from disk.
|
||||||
if s.data.Root == types.EmptyRootHash || s.db.prefetcher == nil {
|
if s.data.Root == types.EmptyRootHash || s.db.prefetcher == nil {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
// Attempt to retrieve the trie from the prefetcher
|
// Attempt to retrieve the trie from the prefetcher
|
||||||
return s.db.prefetcher.trie(s.addrHash, s.data.Root)
|
return s.db.prefetcher.trie(s.addrHash, s.data.Root)
|
||||||
|
@ -311,26 +311,21 @@ func (s *stateObject) updateTrie() (Trie, error) {
|
||||||
if len(s.pendingStorage) == 0 {
|
if len(s.pendingStorage) == 0 {
|
||||||
return s.trie, nil
|
return s.trie, nil
|
||||||
}
|
}
|
||||||
// Retrieve a prefetcher populated trie, or fall back to the database
|
// Retrieve a pretecher populated trie, or fall back to the database
|
||||||
tr, err := s.getPrefetchedTrie()
|
tr := s.getPrefetchedTrie()
|
||||||
switch {
|
if tr != nil {
|
||||||
case err != nil:
|
// Prefetcher returned a live trie, swap it out for the current one
|
||||||
// Fetcher retrieval failed, something's very wrong, abort
|
s.trie = tr
|
||||||
s.db.setError(err)
|
} else {
|
||||||
return nil, err
|
|
||||||
|
|
||||||
case tr == nil:
|
|
||||||
// Fetcher not running or empty trie, fallback to the database trie
|
// Fetcher not running or empty trie, fallback to the database trie
|
||||||
|
var err error
|
||||||
tr, err = s.getTrie()
|
tr, err = s.getTrie()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.db.setError(err)
|
s.db.setError(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
// Prefetcher returned a live trie, swap it out for the current one
|
|
||||||
s.trie = tr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The snapshot storage map for the object
|
// The snapshot storage map for the object
|
||||||
var (
|
var (
|
||||||
storage map[common.Hash][]byte
|
storage map[common.Hash][]byte
|
||||||
|
|
|
@ -878,9 +878,9 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
|
|
||||||
if s.prefetcher != nil {
|
if s.prefetcher != nil {
|
||||||
if trie, err := s.prefetcher.trie(common.Hash{}, s.originalRoot); err != nil {
|
if trie := s.prefetcher.trie(common.Hash{}, s.originalRoot); trie == nil {
|
||||||
log.Error("Failed to retrieve account pre-fetcher trie", "err", err)
|
log.Error("Failed to retrieve account pre-fetcher trie")
|
||||||
} else if trie != nil {
|
} else {
|
||||||
s.trie = trie
|
s.trie = trie
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,16 +145,16 @@ func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr comm
|
||||||
// trie returns the trie matching the root hash, blocking until the fetcher of
|
// trie returns the trie matching the root hash, blocking until the fetcher of
|
||||||
// the given trie terminates. If no fetcher exists for the request, nil will be
|
// the given trie terminates. If no fetcher exists for the request, nil will be
|
||||||
// returned.
|
// returned.
|
||||||
func (p *triePrefetcher) trie(owner common.Hash, root common.Hash) (Trie, error) {
|
func (p *triePrefetcher) trie(owner common.Hash, root common.Hash) Trie {
|
||||||
// Bail if no trie was prefetched for this root
|
// Bail if no trie was prefetched for this root
|
||||||
fetcher := p.fetchers[p.trieID(owner, root)]
|
fetcher := p.fetchers[p.trieID(owner, root)]
|
||||||
if fetcher == nil {
|
if fetcher == nil {
|
||||||
log.Error("Prefetcher missed to load trie", "owner", owner, "root", root)
|
log.Error("Prefetcher missed to load trie", "owner", owner, "root", root)
|
||||||
p.deliveryMissMeter.Mark(1)
|
p.deliveryMissMeter.Mark(1)
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
// Subfetcher exists, retrieve its trie
|
// Subfetcher exists, retrieve its trie
|
||||||
return fetcher.peek(), nil
|
return fetcher.peek()
|
||||||
}
|
}
|
||||||
|
|
||||||
// used marks a batch of state items used to allow creating statistics as to
|
// used marks a batch of state items used to allow creating statistics as to
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestUseAfterTerminate(t *testing.T) {
|
||||||
if err := prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()}); err == nil {
|
if err := prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()}); err == nil {
|
||||||
t.Errorf("Prefetch succeeded after terminate: %v", err)
|
t.Errorf("Prefetch succeeded after terminate: %v", err)
|
||||||
}
|
}
|
||||||
if _, err := prefetcher.trie(common.Hash{}, db.originalRoot); err != nil {
|
if tr := prefetcher.trie(common.Hash{}, db.originalRoot); tr == nil {
|
||||||
t.Errorf("Trie retrieval failed after terminate: %v", err)
|
t.Errorf("Prefetcher returned nil trie after terminate")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue