Skip to content

Commit

Permalink
consensus: Set Spent flag in RevertUpdate.ForEachTreeNode
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Dec 31, 2023
1 parent 7505ca1 commit 38ae2e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 0 additions & 3 deletions consensus/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ func (acc *ElementAccumulator) applyBlock(updated, added []elementLeaf) (eau ele
// elements. All of the elements will be marked unspent. The accumulator itself
// is not modified.
func (acc *ElementAccumulator) revertBlock(updated, added []elementLeaf) (eru elementRevertUpdate) {
for i := range updated {
updated[i].Spent = false // reverting a block can never cause an element to become spent
}
eru.updated = updateLeaves(updated)
eru.numLeaves = acc.NumLeaves
for i := range added {
Expand Down
2 changes: 2 additions & 0 deletions consensus/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ 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) {
el.Spent = false // reverting a block can never cause an element to become spent
row, col := uint64(0), el.LeafIndex
h := el.hash()
fn(row, col, h)
Expand Down Expand Up @@ -831,6 +832,7 @@ func RevertBlock(s State, b types.Block, bs V1BlockSupplement) RevertUpdate {
// compute updated elements
var updated, added []elementLeaf
ms.forEachElementLeaf(func(el elementLeaf) {
el.Spent = false // reverting a block can never cause an element to become spent
if el.MerkleProof != nil {
updated = append(updated, el)
} else {
Expand Down

0 comments on commit 38ae2e7

Please sign in to comment.