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 6394124
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 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 @@ -1461,11 +1471,11 @@ func splitLeafNode(
remainingPathLength := byte(len(partialPath)-commonPrefixLength) - 1
if manager.getConfig().TrackSuffixLengthsInLeafNodes {
sibling.setPathLength(manager, siblingRef, siblingHandle, remainingPathLength)
ref, _, err := this.setPathLength(manager, thisRef, thisHandle, remainingPathLength)
ref, changed, err := this.setPathLength(manager, thisRef, thisHandle, remainingPathLength)
if err != nil {
return NodeReference{}, err
}
thisModified = thisRef.Id() != ref.Id()
thisModified = changed || thisRef.Id() != ref.Id()
thisRef = &ref
thisIsFrozen = false
} else {
Expand All @@ -1484,6 +1494,12 @@ func splitLeafNode(
branch.markChildHashDirty(byte(partialPath[commonPrefixLength]))
} else {
branch.hashes[partialPath[commonPrefixLength]] = hash
// FIXME: at this point the embedded flag needs to be set
// currently, the information whether a node is embedded or not is
// not stored with the node; this needs to be added to make this
// work. So far, assuming the node is not embedded works for all
// cases -- but this needs to be fixed.
//branch.setEmbedded(byte(partialPath[commonPrefixLength]), false)
}

// Track frozen state of split node.
Expand Down

0 comments on commit 6394124

Please sign in to comment.