From 6394124d9c8afb084e474fd94f0d7e7798c7debb Mon Sep 17 00:00:00 2001 From: Herbert Jordan Date: Thu, 14 Dec 2023 17:50:46 +0100 Subject: [PATCH] Forward hash of next node if known --- go/state/mpt/nodes.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/go/state/mpt/nodes.go b/go/state/mpt/nodes.go index 263ced912..e1bb04f45 100644 --- a/go/state/mpt/nodes.go +++ b/go/state/mpt/nodes.go @@ -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 { @@ -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() { @@ -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) } @@ -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 { @@ -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.