Skip to content

Commit

Permalink
chain: Workaround unexported consensus constant
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Jun 26, 2024
1 parent 4d8406d commit c62be52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions chain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,14 @@ func (m *Manager) computeParentMap() map[types.Hash256]int {
return m.txpool.parentMap
}

// bit of a hack
var ephemeralLeafIndex = consensus.UnassignedStateElement(types.Hash256{}).LeafIndex

Check failure on line 614 in chain/manager.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

undefined: consensus.UnassignedStateElement

func updateTxnProofs(txn *types.V2Transaction, updateElementProof func(*types.StateElement), numLeaves uint64) (valid bool) {
valid = true
updateProof := func(e *types.StateElement) {
valid = valid && e.LeafIndex < numLeaves
if !valid || e.LeafIndex == types.EphemeralLeafIndex {
if !valid || e.LeafIndex == ephemeralLeafIndex {
return
}
updateElementProof(e)
Expand All @@ -641,7 +644,7 @@ func (m *Manager) revertPoolUpdate(cru consensus.RevertUpdate, cs consensus.Stat
// restore ephemeral elements, if necessary
var uncreated map[types.Hash256]bool
replaceEphemeral := func(e *types.StateElement) {
if e.LeafIndex != types.EphemeralLeafIndex {
if e.LeafIndex != ephemeralLeafIndex {
return
} else if uncreated == nil {
uncreated = make(map[types.Hash256]bool)
Expand All @@ -667,7 +670,7 @@ func (m *Manager) revertPoolUpdate(cru consensus.RevertUpdate, cs consensus.Stat
})
}
if uncreated[e.ID] {
*e = types.StateElement{ID: e.ID, LeafIndex: types.EphemeralLeafIndex}
*e = consensus.UnassignedStateElement(e.ID)
}
}
for _, txn := range m.txpool.v2txns {
Expand Down Expand Up @@ -698,7 +701,7 @@ func (m *Manager) applyPoolUpdate(cau consensus.ApplyUpdate, cs consensus.State)
// replace ephemeral elements, if necessary
var newElements map[types.Hash256]types.StateElement
replaceEphemeral := func(e *types.StateElement) {
if e.LeafIndex != types.EphemeralLeafIndex {
if e.LeafIndex != ephemeralLeafIndex {
return
} else if newElements == nil {
newElements = make(map[types.Hash256]types.StateElement)
Expand Down

0 comments on commit c62be52

Please sign in to comment.