diff --git a/go.mod b/go.mod index 37a1c77..8b9b1a0 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ toolchain go1.22.3 require ( github.com/mattn/go-sqlite3 v1.14.22 - go.sia.tech/core v0.2.9 - go.sia.tech/coreutils v0.0.8 + go.sia.tech/core v0.3.0 + go.sia.tech/coreutils v0.1.0 go.sia.tech/jape v0.12.0 go.sia.tech/web/walletd v0.22.1 go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index a13518a..c78a348 100644 --- a/go.sum +++ b/go.sum @@ -12,10 +12,10 @@ 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.9 h1:UnO+wXQ3w2dMaU3ULA95fLYspllxaYPSfVW08fFIxQU= -go.sia.tech/core v0.2.9/go.mod h1:BMgT/reXtgv6XbDgUYTCPY7wSMbspDRDs7KMi1vL6Iw= -go.sia.tech/coreutils v0.0.8 h1:eHrzR5s2J4Q1cX+VHLibjNuPTKNGRq/D6jhR+wSRHFE= -go.sia.tech/coreutils v0.0.8/go.mod h1:7VSwhyxoE3DqVFbcLUsN9zC4AnBZ9/QSz/ff+uEzGgc= +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= diff --git a/persist/sqlite/addresses.go b/persist/sqlite/addresses.go index 7a64f16..497742f 100644 --- a/persist/sqlite/addresses.go +++ b/persist/sqlite/addresses.go @@ -229,7 +229,7 @@ func (s *Store) AnnotateV1Events(index types.ChainIndex, timestamp time.Time, v1 sce := types.SiacoinElement{ StateElement: types.StateElement{ ID: types.Hash256(txn.SiacoinOutputID(i)), - LeafIndex: types.EphemeralLeafIndex, + LeafIndex: types.UnassignedLeafIndex, }, SiacoinOutput: output, } @@ -253,7 +253,7 @@ func (s *Store) AnnotateV1Events(index types.ChainIndex, timestamp time.Time, v1 sfe := types.SiafundElement{ StateElement: types.StateElement{ ID: types.Hash256(txn.SiafundOutputID(i)), - LeafIndex: types.EphemeralLeafIndex, + LeafIndex: types.UnassignedLeafIndex, }, SiafundOutput: output, } diff --git a/persist/sqlite/wallet.go b/persist/sqlite/wallet.go index 0b56101..0353dc6 100644 --- a/persist/sqlite/wallet.go +++ b/persist/sqlite/wallet.go @@ -476,7 +476,7 @@ func (s *Store) WalletUnconfirmedEvents(id wallet.ID, index types.ChainIndex, ti sce := types.SiacoinElement{ StateElement: types.StateElement{ ID: types.Hash256(txn.SiacoinOutputID(i)), - LeafIndex: types.EphemeralLeafIndex, + LeafIndex: types.UnassignedLeafIndex, }, SiacoinOutput: output, } @@ -515,7 +515,7 @@ func (s *Store) WalletUnconfirmedEvents(id wallet.ID, index types.ChainIndex, ti sfe := types.SiafundElement{ StateElement: types.StateElement{ ID: types.Hash256(txn.SiafundOutputID(i)), - LeafIndex: types.EphemeralLeafIndex, + LeafIndex: types.UnassignedLeafIndex, }, SiafundOutput: output, } diff --git a/wallet/update.go b/wallet/update.go index 83852b0..4f458dd 100644 --- a/wallet/update.go +++ b/wallet/update.go @@ -116,30 +116,9 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate, indexMode IndexMode) e NumLeaves: cau.State.Elements.NumLeaves, } - // determine which siacoin and siafund elements are ephemeral - // - // note: I thought we could use LeafIndex == EphemeralLeafIndex, but - // it seems to be set before the subscriber is called. - 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 - cau.ForEachSiacoinElement(func(se types.SiacoinElement, spent bool) { - if ephemeral[se.ID] { + cau.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) { + if created && spent { return } @@ -157,8 +136,8 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate, indexMode IndexMode) e } }) - cau.ForEachSiafundElement(func(se types.SiafundElement, spent bool) { - if ephemeral[se.ID] { + cau.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) { + if created && spent { return } @@ -221,8 +200,8 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types. } } - cru.ForEachSiacoinElement(func(se types.SiacoinElement, spent bool) { - if ephemeral[se.ID] { + cru.ForEachSiacoinElement(func(se types.SiacoinElement, created, spent bool) { + if created && spent { return } @@ -242,8 +221,8 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types. } }) - cru.ForEachSiafundElement(func(se types.SiafundElement, spent bool) { - if ephemeral[se.ID] { + cru.ForEachSiafundElement(func(se types.SiafundElement, created, spent bool) { + if created && spent { return } diff --git a/wallet/wallet.go b/wallet/wallet.go index fe79a3b..00d267f 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -41,10 +41,10 @@ type ( // A ChainUpdate is a set of changes to the consensus state. 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)) } ) @@ -116,12 +116,12 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f } anythingRelevant := func() (ok bool) { - cu.ForEachSiacoinElement(func(sce types.SiacoinElement, spent bool) { + cu.ForEachSiacoinElement(func(sce types.SiacoinElement, _, _ bool) { if ok || relevant(sce.SiacoinOutput.Address) { ok = true } }) - cu.ForEachSiafundElement(func(sfe types.SiafundElement, spent bool) { + cu.ForEachSiafundElement(func(sfe types.SiafundElement, _, _ bool) { if ok || relevant(sfe.SiafundOutput.Address) { ok = true } @@ -137,19 +137,19 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f 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, _, _ bool) { sce.MerkleProof = nil sces[types.SiacoinOutputID(sce.ID)] = sce }) - cu.ForEachSiafundElement(func(sfe types.SiafundElement, spent bool) { + cu.ForEachSiafundElement(func(sfe types.SiafundElement, _, _ 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, _ 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, _ bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { fce.MerkleProof = nil v2fces[types.FileContractID(fce.ID)] = fce }) @@ -266,7 +266,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f } // handle missed contracts - cu.ForEachFileContractElement(func(fce types.FileContractElement, rev *types.FileContractElement, resolved, valid bool) { + cu.ForEachFileContractElement(func(fce types.FileContractElement, _ bool, rev *types.FileContractElement, resolved, valid bool) { if !resolved { return } @@ -302,7 +302,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f } }) - cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { + cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, _ bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { if res == nil { return }