From f9ac41a562c6c5af869f929fa45b7563a1660624 Mon Sep 17 00:00:00 2001 From: Bo Du Date: Mon, 14 Mar 2022 23:13:34 -0400 Subject: [PATCH] fix: handle inline child in getFromDB --- lib/trie/database.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/trie/database.go b/lib/trie/database.go index ab9b7f26d6..cbc107f269 100644 --- a/lib/trie/database.go +++ b/lib/trie/database.go @@ -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(