eth/protocols/snap, trie: better error-handling (#23657)

This commit is contained in:
Martin Holst Swende 2021-09-29 15:19:40 +02:00 committed by GitHub
parent 42bc1944a1
commit 3a6fe69f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -469,7 +469,7 @@ func handleMessage(backend Backend, peer *Peer) error {
// Storage slots requested, open the storage trie and retrieve from there // Storage slots requested, open the storage trie and retrieve from there
account, err := snap.Account(common.BytesToHash(pathset[0])) account, err := snap.Account(common.BytesToHash(pathset[0]))
loads++ // always account database reads, even for failures loads++ // always account database reads, even for failures
if err != nil { if err != nil || account == nil {
break break
} }
stTrie, err := trie.NewSecure(common.BytesToHash(account.Root), triedb) stTrie, err := trie.NewSecure(common.BytesToHash(account.Root), triedb)

View File

@ -176,6 +176,10 @@ func (t *Trie) TryGetNode(path []byte) ([]byte, int, error) {
} }
func (t *Trie) tryGetNode(origNode node, path []byte, pos int) (item []byte, newnode node, resolved int, err error) { func (t *Trie) tryGetNode(origNode node, path []byte, pos int) (item []byte, newnode node, resolved int, err error) {
// If non-existent path requested, abort
if origNode == nil {
return nil, nil, 0, nil
}
// If we reached the requested path, return the current node // If we reached the requested path, return the current node
if pos >= len(path) { if pos >= len(path) {
// Although we most probably have the original node expanded, encoding // Although we most probably have the original node expanded, encoding
@ -195,10 +199,6 @@ func (t *Trie) tryGetNode(origNode node, path []byte, pos int) (item []byte, new
} }
// Path still needs to be traversed, descend into children // Path still needs to be traversed, descend into children
switch n := (origNode).(type) { switch n := (origNode).(type) {
case nil:
// Non-existent path requested, abort
return nil, nil, 0, nil
case valueNode: case valueNode:
// Path prematurely ended, abort // Path prematurely ended, abort
return nil, nil, 0, nil return nil, nil, 0, nil