From e7f20145322d97b2eda81591e84a625737904838 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:25:23 +0000 Subject: [PATCH 1/2] Bump the all-dependencies group with 3 updates Bumps the all-dependencies group with 3 updates: [go.sia.tech/core](https://github.com/SiaFoundation/core), [go.sia.tech/coreutils](https://github.com/SiaFoundation/coreutils) and [go.sia.tech/jape](https://github.com/SiaFoundation/jape). Updates `go.sia.tech/core` from 0.2.7 to 0.3.0 - [Commits](https://github.com/SiaFoundation/core/compare/v0.2.7...v0.3.0) Updates `go.sia.tech/coreutils` from 0.0.6 to 0.1.0 - [Commits](https://github.com/SiaFoundation/coreutils/compare/v0.0.6...v0.1.0) Updates `go.sia.tech/jape` from 0.11.1 to 0.12.0 - [Commits](https://github.com/SiaFoundation/jape/compare/v0.11.1...v0.12.0) --- updated-dependencies: - dependency-name: go.sia.tech/core dependency-type: direct:production update-type: version-update:semver-minor dependency-group: all-dependencies - dependency-name: go.sia.tech/coreutils dependency-type: direct:production update-type: version-update:semver-minor dependency-group: all-dependencies - dependency-name: go.sia.tech/jape dependency-type: direct:production update-type: version-update:semver-minor dependency-group: all-dependencies ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 7fdffb00..4e016470 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,9 @@ toolchain go1.22.4 require ( github.com/mattn/go-sqlite3 v1.14.22 go.etcd.io/bbolt v1.3.10 - go.sia.tech/core v0.2.7 - go.sia.tech/coreutils v0.0.6 - go.sia.tech/jape v0.11.1 + go.sia.tech/core v0.3.0 + go.sia.tech/coreutils v0.1.0 + go.sia.tech/jape v0.12.0 go.uber.org/zap v1.27.0 lukechampine.com/frand v1.4.2 lukechampine.com/upnp v0.3.0 diff --git a/go.sum b/go.sum index 5415b3c1..0edf962a 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,12 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ= -go.sia.tech/core v0.2.7 h1:9Q/3BHL6ziAMPeiko863hhTD/Zs2s7OqEUiPKouDny8= -go.sia.tech/core v0.2.7/go.mod h1:BMgT/reXtgv6XbDgUYTCPY7wSMbspDRDs7KMi1vL6Iw= -go.sia.tech/coreutils v0.0.6 h1:xLpv3JyvbOoXcX3gC6a6Y3zQ/MZn/fyFvuPIzv/e/Eg= -go.sia.tech/coreutils v0.0.6/go.mod h1:EiDcQk2qLuP32Qoj/XphY9fbjTXphJhJZMERoC4LF0c= -go.sia.tech/jape v0.11.1 h1:M7IP+byXL7xOqzxcHUQuXW+q3sYMkYzmMlMw+q8ZZw0= -go.sia.tech/jape v0.11.1/go.mod h1:4QqmBB+t3W7cNplXPj++ZqpoUb2PeiS66RLpXmEGap4= +go.sia.tech/core v0.3.0 h1:PDfAQh9z8PYD+oeVS7rS9SEnTMOZzwwFfAH45yktmko= +go.sia.tech/core v0.3.0/go.mod h1:BMgT/reXtgv6XbDgUYTCPY7wSMbspDRDs7KMi1vL6Iw= +go.sia.tech/coreutils v0.1.0 h1:WQL7iT+jK1BiMx87bASXrZJZf4N2fbQkIOW8rS7wkh4= +go.sia.tech/coreutils v0.1.0/go.mod h1:ybaFgewKXrlxFW71LqsyQlxjG6yWL6BSePrbZYnrprU= +go.sia.tech/jape v0.12.0 h1:13fBi7c5X8zxTQ05Cd9ZsIfRJgdvGoZqbEzH861z7BU= +go.sia.tech/jape v0.12.0/go.mod h1:wU+h6Wh5olDjkPXjF0tbZ1GDgoZ6VTi4naFw91yyWC4= go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU= go.sia.tech/mux v1.2.0/go.mod h1:Yyo6wZelOYTyvrHmJZ6aQfRoer3o4xyKQ4NmQLJrBSo= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= From 9c190cfb6dc194a4e8cbde63cb6a307765dda7c0 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Mon, 1 Jul 2024 11:12:56 -0400 Subject: [PATCH 2/2] remove code to figure out what is ephemeral and use new core feature instead --- explorer/events.go | 18 ++++++++-------- explorer/update.go | 54 +++++++++------------------------------------- 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/explorer/events.go b/explorer/events.go index 73d2073f..9f539275 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -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. @@ -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 }) @@ -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 } diff --git a/explorer/update.go b/explorer/update.go index c375fd2a..ee8688a7 100644 --- a/explorer/update.go +++ b/explorer/update.go @@ -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)], @@ -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 } @@ -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, @@ -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, }) @@ -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 } @@ -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,