Skip to content

Commit

Permalink
Forward hash of next node if known
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertJordan committed Dec 14, 2023
1 parent b5749e4 commit c09d41e
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit c09d41e

Please sign in to comment.