Skip to content

Commit

Permalink
MerkleDB Remove GetNodeFromParent (ava-labs#2041)
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Laine <[email protected]>
  • Loading branch information
dboehm-avalabs and Dan Laine authored Sep 19, 2023
1 parent bd83641 commit 326a59a
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions x/merkledb/trieview.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,11 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) {
return proof, nil
}

childPath := closestNode.key + path(nextIndex) + child.compressedPath
childNode, err := t.getNodeFromParent(closestNode, childPath, child.hasValue)
childNode, err := t.getNodeWithID(
child.id,
closestNode.key+path(nextIndex)+child.compressedPath,
child.hasValue,
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -688,7 +691,7 @@ func (t *trieView) compressNodePath(parent, node *node) error {
childEntry = entry
}

nextNode, err := t.getNodeFromParent(node, childPath, childEntry.hasValue)
nextNode, err := t.getNodeWithID(childEntry.id, childPath, childEntry.hasValue)
if err != nil {
return err
}
Expand Down Expand Up @@ -997,19 +1000,6 @@ func (t *trieView) recordValueChange(key path, value maybe.Maybe[[]byte]) error
return nil
}

// Retrieves the node with the given [key], which is a child of [parent], and
// uses the [parent] node to initialize the child node's ID.
// If the node is loaded from the baseDB, [hasValue] determines which database the node is stored in.
// Returns database.ErrNotFound if the child doesn't exist.
func (t *trieView) getNodeFromParent(parent *node, key path, hasValue bool) (*node, error) {
// confirm the child exists and get its ID before attempting to load it
if child, exists := parent.children[key[len(parent.key)]]; exists {
return t.getNodeWithID(child.id, key, hasValue)
}

return nil, database.ErrNotFound
}

// Retrieves a node with the given [key].
// If the node is fetched from [t.parentTrie] and [id] isn't empty,
// sets the node's ID to [id].
Expand Down

0 comments on commit 326a59a

Please sign in to comment.