Skip to content

Commit

Permalink
remove code to figure out what is ephemeral and use new core feature …
Browse files Browse the repository at this point in the history
…instead
  • Loading branch information
chris124567 committed Jul 1, 2024
1 parent e7f2014 commit 9c190cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 53 deletions.
18 changes: 9 additions & 9 deletions explorer/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ type EventContractPayout struct {

// A ChainUpdate is a set of changes to the consensus state.
type ChainUpdate interface {
ForEachSiacoinElement(func(sce types.SiacoinElement, spent bool))
ForEachSiafundElement(func(sfe types.SiafundElement, spent bool))
ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool))
ForEachV2FileContractElement(func(fce types.V2FileContractElement, rev *types.V2FileContractElement, res types.V2FileContractResolutionType))
ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool))
ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool))
ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool))
ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType))
}

// AppliedEvents extracts a list of relevant events from a chain update.
Expand Down Expand Up @@ -139,19 +139,19 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {
sfes := make(map[types.SiafundOutputID]types.SiafundElement)
fces := make(map[types.FileContractID]types.FileContractElement)
v2fces := make(map[types.FileContractID]types.V2FileContractElement)
cu.ForEachSiacoinElement(func(sce types.SiacoinElement, spent bool) {
cu.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) {
sce.MerkleProof = nil
sces[types.SiacoinOutputID(sce.ID)] = sce
})
cu.ForEachSiafundElement(func(sfe types.SiafundElement, spent bool) {
cu.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) {
sfe.MerkleProof = nil
sfes[types.SiafundOutputID(sfe.ID)] = sfe
})
cu.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) {
cu.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fce.MerkleProof = nil
fces[types.FileContractID(fce.ID)] = fce
})
cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) {
fce.MerkleProof = nil
v2fces[types.FileContractID(fce.ID)] = fce
})
Expand Down Expand Up @@ -232,7 +232,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event {
}

// handle missed contracts
cu.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) {
cu.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
if !resolved {
return
}
Expand Down
54 changes: 10 additions & 44 deletions explorer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,11 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {
}
}

created := make(map[types.Hash256]bool)
ephemeral := make(map[types.Hash256]bool)
for _, txn := range cau.Block.Transactions {
for i := range txn.SiacoinOutputs {
created[types.Hash256(txn.SiacoinOutputID(i))] = true
}
for _, input := range txn.SiacoinInputs {
ephemeral[types.Hash256(input.ParentID)] = created[types.Hash256(input.ParentID)]
}
for i := range txn.SiafundOutputs {
created[types.Hash256(txn.SiafundOutputID(i))] = true
}
for _, input := range txn.SiafundInputs {
ephemeral[types.Hash256(input.ParentID)] = created[types.Hash256(input.ParentID)]
}
}

// add new siacoin elements to the store
var newSiacoinElements, spentSiacoinElements []SiacoinOutput
var ephemeralSiacoinElements []SiacoinOutput
cau.ForEachSiacoinElement(func(se types.SiacoinElement, spent bool) {
if ephemeral[se.ID] {
cau.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) {
if created && spent {
ephemeralSiacoinElements = append(ephemeralSiacoinElements, SiacoinOutput{
SiacoinElement: se,
Source: sources[types.SiacoinOutputID(se.StateElement.ID)],
Expand All @@ -124,8 +107,8 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {

var newSiafundElements, spentSiafundElements []types.SiafundElement
var ephemeralSiafundElements []types.SiafundElement
cau.ForEachSiafundElement(func(se types.SiafundElement, spent bool) {
if ephemeral[se.ID] {
cau.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) {
if created && spent {
ephemeralSiafundElements = append(ephemeralSiafundElements, se)
return
}
Expand All @@ -138,7 +121,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {
})

var fces []FileContractUpdate
cau.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) {
cau.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fces = append(fces, FileContractUpdate{
FileContractElement: fce,
Revision: rev,
Expand Down Expand Up @@ -180,28 +163,11 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error {

// revertChainUpdate atomically reverts a chain update from a store
func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types.ChainIndex) error {
created := make(map[types.Hash256]bool)
ephemeral := make(map[types.Hash256]bool)
for _, txn := range cru.Block.Transactions {
for i := range txn.SiacoinOutputs {
created[types.Hash256(txn.SiacoinOutputID(i))] = true
}
for _, input := range txn.SiacoinInputs {
ephemeral[types.Hash256(input.ParentID)] = created[types.Hash256(input.ParentID)]
}
for i := range txn.SiafundOutputs {
created[types.Hash256(txn.SiafundOutputID(i))] = true
}
for _, input := range txn.SiafundInputs {
ephemeral[types.Hash256(input.ParentID)] = created[types.Hash256(input.ParentID)]
}
}

// add new siacoin elements to the store
var newSiacoinElements, spentSiacoinElements []SiacoinOutput
var ephemeralSiacoinElements []SiacoinOutput
cru.ForEachSiacoinElement(func(se types.SiacoinElement, spent bool) {
if ephemeral[se.ID] {
cru.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) {
if created && spent {
ephemeralSiacoinElements = append(ephemeralSiacoinElements, SiacoinOutput{
SiacoinElement: se,
})
Expand All @@ -221,8 +187,8 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types.

var newSiafundElements, spentSiafundElements []types.SiafundElement
var ephemeralSiafundElements []types.SiafundElement
cru.ForEachSiafundElement(func(se types.SiafundElement, spent bool) {
if ephemeral[se.ID] {
cru.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) {
if created && spent {
ephemeralSiafundElements = append(ephemeralSiafundElements, se)
return
}
Expand All @@ -235,7 +201,7 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types.
})

var fces []FileContractUpdate
cru.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) {
cru.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) {
fces = append(fces, FileContractUpdate{
FileContractElement: fce,
Revision: rev,
Expand Down

0 comments on commit 9c190cf

Please sign in to comment.