Skip to content

Commit

Permalink
merkledb comment accuracy fixes (#2780)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Laine <daniel.laine@avalabs.org>
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
  • Loading branch information
Dan Laine and darioush authored Feb 29, 2024
1 parent c691cfd commit d1312cb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions x/merkledb/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ func verifyProofPath(proof []ProofNode, key maybe.Maybe[Key]) error {
currentProofNode := proof[i]
nodeKey := currentProofNode.Key

// Because the interface only support []byte keys,
// a key with a partial byte should store a value
// Because the interface only supports []byte keys,
// a key with a partial byte may not store a value
if nodeKey.hasPartialByte() && proof[i].ValueOrHash.HasValue() {
return ErrPartialByteLengthWithValue
}
Expand Down
5 changes: 2 additions & 3 deletions x/merkledb/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ type View interface {
CommitToDB(ctx context.Context) error
}

// Returns the nodes along the path to [key].
// Calls [visitNode] on the nodes along the path to [key].
// The first node is the root, and the last node is either the node with the
// given [key], if it's in the trie, or the node with the largest prefix of
// the [key] if it isn't in the trie.
// Always returns at least the root node.
// Assumes [t] doesn't change while this function is running.
func visitPathToKey(t Trie, key Key, visitNode func(*node) error) error {
maybeRoot := t.getRoot()
Expand Down Expand Up @@ -137,7 +136,7 @@ func visitPathToKey(t Trie, key Key, visitNode func(*node) error) error {
return nil
}

// Returns a proof that [bytesPath] is in or not in trie [t].
// Returns a proof that [key] is in or not in trie [t].
// Assumes [t] doesn't change while this function is running.
func getProof(t Trie, key []byte) (*Proof, error) {
root := t.getRoot()
Expand Down
11 changes: 4 additions & 7 deletions x/merkledb/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (v *view) getValue(key Key) ([]byte, error) {
}
v.db.metrics.ViewChangesValueMiss()

// if we don't have local copy of the key, then grab a copy from the parent trie
// if we don't have local copy of the value, then grab a copy from the parent trie
value, err := v.getParentTrie().getValue(key)
if err != nil {
return nil, err
Expand Down Expand Up @@ -542,15 +542,12 @@ func (v *view) remove(key Key) error {
return v.compressNodePath(grandParent, parent)
}

// merge this node and its descendants into a single node if possible
// merge this node and its parent into a single node if possible
return v.compressNodePath(parent, nodeToDelete)
}

// Merges together nodes in the inclusive descendants of [n] that
// have no value and a single child into one node with a compressed
// path until a node that doesn't meet those criteria is reached.
// [parent] is [n]'s parent. If [parent] is nil, [n] is the root
// node and [v.root] is updated to [n].
// Merges [n] with its [parent] if [n] has only one child and no value.
// If [parent] is nil, [n] is the root node and [v.root] is updated to [n].
// Assumes at least one of the following is true:
// * [n] has a value.
// * [n] has children.
Expand Down

0 comments on commit d1312cb

Please sign in to comment.