Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward hash of next node if known #697

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
19 changes: 17 additions & 2 deletions go/state/mpt/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ func (n *BranchNode) setNextNode(
extension.next = remaining
extension.hashDirty = true
extension.nextHashDirty = n.isChildHashDirty(byte(remainingPos))
extension.nextHash = n.hashes[byte(remainingPos)]
if !extension.nextHashDirty {
// TODO: add unit test coverage for this!
extension.nextIsEmbedded = n.isEmbedded(byte(remainingPos))
extension.nextHash = n.hashes[byte(remainingPos)]
}
manager.update(extensionRef.Id(), handle)
newRoot = extensionRef
} else if manager.getConfig().TrackSuffixLengthsInLeafNodes {
Expand Down Expand Up @@ -1007,6 +1011,11 @@ func (n *ExtensionNode) setNextNode(
n.next = extension.next
n.hashDirty = true
n.nextHashDirty = extension.nextHashDirty
if !extension.nextHashDirty {
// TODO: add unit test coverage for this!
n.nextHash = extension.nextHash
n.nextIsEmbedded = extension.nextIsEmbedded
}
manager.update(thisRef.Id(), this)
manager.release(newRoot.Id())
} else if newRoot.Id().IsBranch() {
Expand Down Expand Up @@ -1100,6 +1109,7 @@ func (n *ExtensionNode) setNextNode(
branch.markChildHashDirty(pos)
} else {
branch.hashes[pos] = n.nextHash
branch.setEmbedded(pos, n.nextIsEmbedded)
}
branch.setChildFrozen(pos, isClone)
}
Expand Down Expand Up @@ -1465,7 +1475,7 @@ func splitLeafNode(
if err != nil {
return NodeReference{}, err
}
thisModified = thisRef.Id() != ref.Id()
thisModified = true
thisRef = &ref
thisIsFrozen = false
} else {
Expand All @@ -1484,6 +1494,11 @@ func splitLeafNode(
branch.markChildHashDirty(byte(partialPath[commonPrefixLength]))
} else {
branch.hashes[partialPath[commonPrefixLength]] = hash
// The embedded flag can be ignored in this case as long as direct
// hashing is used.
if manager.getConfig().Hashing.Name != DirectHashing.Name {
panic("unsupported mode: disabled TrackSuffixLengthsInLeafNodes is not (yet) supported with hash algorithms depending on embedded nodes.")
}
}

// Track frozen state of split node.
Expand Down