Skip to content

Commit

Permalink
merkledb -- move compressedKey declaration to avoid usage of stale …
Browse files Browse the repository at this point in the history
…values in loop (#2777)
  • Loading branch information
Dan Laine authored Feb 29, 2024
1 parent e9ca612 commit 97900f7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions x/merkledb/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,17 @@ func addPathInfo(

// Add [proofNode]'s children which are outside the range
// [insertChildrenLessThan, insertChildrenGreaterThan].
compressedKey := Key{}
for index, childID := range proofNode.Children {
var compressedKey Key
if existingChild, ok := n.children[index]; ok {
compressedKey = existingChild.compressedKey
}
childKey := key.Extend(ToToken(index, v.tokenSize), compressedKey)
if (shouldInsertLeftChildren && childKey.Less(insertChildrenLessThan.Value())) ||
(shouldInsertRightChildren && childKey.Greater(insertChildrenGreaterThan.Value())) {
// We didn't set the other values on the child entry, but it doesn't matter.
// We only need the IDs to be correct so that the calculated hash is correct.
// We don't set the [hasValue] field of the child but that's OK.
// We only need the compressed key and ID to be correct so that the
// calculated hash is correct.
n.setChildEntry(
index,
&child{
Expand Down

0 comments on commit 97900f7

Please sign in to comment.