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

merkledb -- move compressedKey declaration to avoid usage of stale values in loop #2777

Merged
merged 3 commits into from
Feb 29, 2024
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
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
Loading