Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this dropped?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be true, but it isn't true now. If the root is not a prefix of the key we're looking for, the root will not be visited.

// 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.ViewValueCacheMiss()

// 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 @@ -541,15 +541,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