Skip to content

Commit cd7bc93

Browse files
holimanzzyalbert
authored andcommitted
eth/protocols/snap, trie: better error-handling (ethereum#23657)
1 parent 879b45d commit cd7bc93

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

eth/protocols/snap/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func handleMessage(backend Backend, peer *Peer) error {
469469
// Storage slots requested, open the storage trie and retrieve from there
470470
account, err := snap.Account(common.BytesToHash(pathset[0]))
471471
loads++ // always account database reads, even for failures
472-
if err != nil {
472+
if err != nil || account == nil {
473473
break
474474
}
475475
stTrie, err := trie.NewSecure(common.BytesToHash(account.Root), triedb)

trie/trie.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ func (t *Trie) TryGetNode(path []byte) ([]byte, int, error) {
176176
}
177177

178178
func (t *Trie) tryGetNode(origNode node, path []byte, pos int) (item []byte, newnode node, resolved int, err error) {
179+
// If non-existent path requested, abort
180+
if origNode == nil {
181+
return nil, nil, 0, nil
182+
}
179183
// If we reached the requested path, return the current node
180184
if pos >= len(path) {
181185
// 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
195199
}
196200
// Path still needs to be traversed, descend into children
197201
switch n := (origNode).(type) {
198-
case nil:
199-
// Non-existent path requested, abort
200-
return nil, nil, 0, nil
201-
202202
case valueNode:
203203
// Path prematurely ended, abort
204204
return nil, nil, 0, nil

0 commit comments

Comments
 (0)