Skip to content

Commit

Permalink
fix: handle inline child in getFromDB
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Mar 15, 2022
1 parent 2f25c89 commit f9ac41a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,18 @@ func getFromDB(db chaindb.Database, n Node, key []byte) (

// childIndex is the nibble after the common prefix length in the key being searched.
childIndex := key[commonPrefixLength]
childWithHashOnly := branch.Children[childIndex]
if childWithHashOnly == nil {
child := branch.Children[childIndex]
if child == nil {
return nil, nil
}

childHash := childWithHashOnly.GetHash()
// Child can be either inlined or a hash pointer.
childHash := child.GetHash()
_, isLeaf := child.(*node.Leaf)
if len(childHash) == 0 && isLeaf {
return getFromDB(db, child, key[commonPrefixLength+1:])
}

encodedChild, err := db.Get(childHash)
if err != nil {
return nil, fmt.Errorf(
Expand Down

0 comments on commit f9ac41a

Please sign in to comment.