Skip to content

Commit

Permalink
Merge pull request #147 from SiaFoundation/nate/update-core-utils
Browse files Browse the repository at this point in the history
Update for core and coreutils changes
  • Loading branch information
n8maninger authored Jun 27, 2024
2 parents 5d26510 + c126224 commit 6d4ca79
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 51 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions persist/sqlite/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions persist/sqlite/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
37 changes: 8 additions & 29 deletions wallet/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
24 changes: 12 additions & 12 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
)

Expand Down Expand Up @@ -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
}
Expand All @@ -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
})
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6d4ca79

Please sign in to comment.