Skip to content

Commit

Permalink
consensus: Apply ForEachTreeNode fix to RevertUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Dec 12, 2023
1 parent 77190f0 commit 3d9547b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions consensus/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,22 @@ func (ru RevertUpdate) ForEachV2FileContractElement(fn func(fce types.V2FileCont
func (ru RevertUpdate) ForEachTreeNode(fn func(row, col uint64, h types.Hash256)) {
seen := make(map[[2]uint64]bool)
ru.ms.forEachElementLeaf(func(el elementLeaf) {
for i, h := range el.MerkleProof {
row, col := uint64(i), (el.LeafIndex>>i)^1
row, col := uint64(0), el.LeafIndex
h := el.hash()
fn(row, col, h)
for i, sibling := range el.MerkleProof {
if el.LeafIndex&(1<<i) == 0 {
h = blake2b.SumPair(h, sibling)
} else {
h = blake2b.SumPair(sibling, h)
}
row++
col >>= 1
fn(row, col, h)
if seen[[2]uint64{row, col}] {
break
return // already seen everything above this
}
seen[[2]uint64{row, col}] = true
fn(row, col, h)
}
})
}
Expand Down

0 comments on commit 3d9547b

Please sign in to comment.