From 9bfd8c7e52ddfdc6bbec65f7e4617a20a71e4091 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:12:05 +0000 Subject: [PATCH 1/4] Bump the all-dependencies group with 2 updates Bumps the all-dependencies group with 2 updates: [go.sia.tech/core](https://github.com/SiaFoundation/core) and [go.sia.tech/coreutils](https://github.com/SiaFoundation/coreutils). Updates `go.sia.tech/core` from 0.5.0 to 0.6.1 - [Commits](https://github.com/SiaFoundation/core/compare/v0.5.0...v0.6.1) Updates `go.sia.tech/coreutils` from 0.5.0 to 0.6.0 - [Commits](https://github.com/SiaFoundation/coreutils/compare/v0.5.0...v0.6.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 ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b62b0836..e033d62e 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,10 @@ go 1.23.1 toolchain go1.23.2 require ( + github.com/ip2location/ip2location-go v8.3.0+incompatible github.com/mattn/go-sqlite3 v1.14.24 - go.sia.tech/core v0.5.0 - go.sia.tech/coreutils v0.5.0 + go.sia.tech/core v0.6.1 + go.sia.tech/coreutils v0.6.0 go.sia.tech/jape v0.12.1 go.uber.org/zap v1.27.0 gopkg.in/yaml.v3 v3.0.1 @@ -16,7 +17,6 @@ require ( ) require ( - github.com/ip2location/ip2location-go v8.3.0+incompatible // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect diff --git a/go.sum b/go.sum index 19629693..8f141009 100644 --- a/go.sum +++ b/go.sum @@ -21,10 +21,10 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0= go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I= -go.sia.tech/core v0.5.0 h1:feLC7DSCF+PhU157s/94106hFKyiGrGQ9HC3/dF/l7E= -go.sia.tech/core v0.5.0/go.mod h1:P3C1BWa/7J4XgdzWuaYHBvLo2RzZ0UBaJM4TG1GWB2g= -go.sia.tech/coreutils v0.5.0 h1:/xKxdw83iZy0jjLzI2NGHyG4azyjK5DJscxpkr6nIGQ= -go.sia.tech/coreutils v0.5.0/go.mod h1:VYM4FcmlhVrpDGvglLHjRW+gitoaxPNLvp5mL2quilo= +go.sia.tech/core v0.6.1 h1:eaExM2E2eNr43su2XDkY5J24E3F54YGS7hcC3WtVjVk= +go.sia.tech/core v0.6.1/go.mod h1:P3C1BWa/7J4XgdzWuaYHBvLo2RzZ0UBaJM4TG1GWB2g= +go.sia.tech/coreutils v0.6.0 h1:r0IZt+aVdGG2uIHl7OtaWRYdVx4NQ7ezRoSGa0Ej8GY= +go.sia.tech/coreutils v0.6.0/go.mod h1:XlsnogeYU/Tdjzp/HUNAj5T7tZCdmeBHIBjymbPC+uQ= go.sia.tech/jape v0.12.1 h1:xr+o9V8FO8ScRqbSaqYf9bjj1UJ2eipZuNcI1nYousU= go.sia.tech/jape v0.12.1/go.mod h1:wU+h6Wh5olDjkPXjF0tbZ1GDgoZ6VTi4naFw91yyWC4= go.sia.tech/mux v1.3.0 h1:hgR34IEkqvfBKUJkAzGi31OADeW2y7D6Bmy/Jcbop9c= From 05b3cc215e6038195a7f92ccfc2de90fc7c29d92 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Mon, 4 Nov 2024 15:30:12 +0100 Subject: [PATCH 2/4] fix build --- explorer/events.go | 10 +++++----- explorer/update.go | 6 +++--- persist/sqlite/addresses.go | 10 +++++----- persist/sqlite/consensus.go | 20 ++++++++++---------- persist/sqlite/consensus_test.go | 4 ++-- persist/sqlite/contracts.go | 2 +- persist/sqlite/transactions.go | 12 ++++++------ 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/explorer/events.go b/explorer/events.go index 5d3f9aae..2ae7232e 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -146,19 +146,19 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { fces := make(map[types.FileContractID]types.FileContractElement) v2fces := make(map[types.FileContractID]types.V2FileContractElement) cu.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) { - sce.MerkleProof = nil + sce.StateElement.MerkleProof = nil sces[types.SiacoinOutputID(sce.ID)] = sce }) cu.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) { - sfe.MerkleProof = nil + sfe.StateElement.MerkleProof = nil sfes[types.SiafundOutputID(sfe.ID)] = sfe }) cu.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) { - fce.MerkleProof = nil + fce.StateElement.MerkleProof = nil fces[types.FileContractID(fce.ID)] = fce }) cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { - fce.MerkleProof = nil + fce.StateElement.MerkleProof = nil v2fces[types.FileContractID(fce.ID)] = fce }) @@ -220,7 +220,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { var e EventV2Transaction for _, a := range txn.Attestations { var ha chain.HostAnnouncement - if ha.FromAttestation(a) { + if ha.FromArbitraryData(a.Value) { e.HostAnnouncements = append(e.HostAnnouncements, ha) } } diff --git a/explorer/update.go b/explorer/update.go index f5447503..9e31d222 100644 --- a/explorer/update.go +++ b/explorer/update.go @@ -91,7 +91,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { if created && spent { ephemeralSiacoinElements = append(ephemeralSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.StateElement.ID)], + Source: sources[types.SiacoinOutputID(se.ID)], }) return } @@ -99,12 +99,12 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { if spent { spentSiacoinElements = append(spentSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.StateElement.ID)], + Source: sources[types.SiacoinOutputID(se.ID)], }) } else { newSiacoinElements = append(newSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.StateElement.ID)], + Source: sources[types.SiacoinOutputID(se.ID)], }) } }) diff --git a/persist/sqlite/addresses.go b/persist/sqlite/addresses.go index 296adb44..dbda4f6f 100644 --- a/persist/sqlite/addresses.go +++ b/persist/sqlite/addresses.go @@ -69,14 +69,14 @@ func scanEvent(tx *txn, s scanner) (ev explorer.Event, eventID int64, err error) FROM contract_payout_events ev JOIN siacoin_elements sce ON ev.output_id = sce.id JOIN file_contract_elements fce ON ev.contract_id = fce.id -WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), &m.SiacoinOutput.MaturityHeight, decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value), decode(&m.FileContract.StateElement.ID), decode(&m.FileContract.StateElement.LeafIndex), decode(&m.FileContract.FileContract.Filesize), decode(&m.FileContract.FileContract.FileMerkleRoot), decode(&m.FileContract.FileContract.WindowStart), decode(&m.FileContract.FileContract.WindowEnd), decode(&m.FileContract.FileContract.Payout), decode(&m.FileContract.FileContract.UnlockHash), decode(&m.FileContract.FileContract.RevisionNumber), &m.Missed) +WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), &m.SiacoinOutput.MaturityHeight, decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value), decode(&m.FileContract.ID), decode(&m.FileContract.StateElement.LeafIndex), decode(&m.FileContract.FileContract.Filesize), decode(&m.FileContract.FileContract.FileMerkleRoot), decode(&m.FileContract.FileContract.WindowStart), decode(&m.FileContract.FileContract.WindowEnd), decode(&m.FileContract.FileContract.Payout), decode(&m.FileContract.FileContract.UnlockHash), decode(&m.FileContract.FileContract.RevisionNumber), &m.Missed) ev.Data = &m case explorer.EventTypeMinerPayout: var m explorer.EventMinerPayout err = tx.QueryRow(`SELECT sc.output_id, sc.leaf_index, sc.maturity_height, sc.address, sc.value FROM siacoin_elements sc INNER JOIN miner_payout_events ev ON (ev.output_id = sc.id) -WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value)) +WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value)) if err != nil { return explorer.Event{}, 0, fmt.Errorf("failed to fetch miner payout event data: %w", err) } @@ -86,7 +86,7 @@ WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), err = tx.QueryRow(`SELECT sc.output_id, sc.leaf_index, sc.maturity_height, sc.address, sc.value FROM siacoin_elements sc INNER JOIN foundation_subsidy_events ev ON (ev.output_id = sc.id) -WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.StateElement.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value)) +WHERE ev.event_id = ?`, eventID).Scan(decode(&m.SiacoinOutput.ID), decode(&m.SiacoinOutput.StateElement.LeafIndex), decode(&m.SiacoinOutput.MaturityHeight), decode(&m.SiacoinOutput.SiacoinOutput.Address), decode(&m.SiacoinOutput.SiacoinOutput.Value)) ev.Data = &m default: return explorer.Event{}, 0, fmt.Errorf("unknown event type: %s", eventType) @@ -180,7 +180,7 @@ func (s *Store) AddressEvents(address types.Address, offset, limit uint64) (even func scanSiacoinOutput(s scanner) (sco explorer.SiacoinOutput, err error) { var spentIndex types.ChainIndex - err = s.Scan(decode(&sco.StateElement.ID), decode(&sco.StateElement.LeafIndex), &sco.Source, decodeNull(&spentIndex), &sco.MaturityHeight, decode(&sco.SiacoinOutput.Address), decode(&sco.SiacoinOutput.Value)) + err = s.Scan(decode(&sco.ID), decode(&sco.StateElement.LeafIndex), &sco.Source, decodeNull(&spentIndex), &sco.MaturityHeight, decode(&sco.SiacoinOutput.Address), decode(&sco.SiacoinOutput.Value)) if spentIndex != (types.ChainIndex{}) { sco.SpentIndex = &spentIndex } @@ -189,7 +189,7 @@ func scanSiacoinOutput(s scanner) (sco explorer.SiacoinOutput, err error) { func scanSiafundOutput(s scanner) (sfo explorer.SiafundOutput, err error) { var spentIndex types.ChainIndex - err = s.Scan(decode(&sfo.StateElement.ID), decode(&sfo.StateElement.LeafIndex), decodeNull(&spentIndex), decode(&sfo.ClaimStart), decode(&sfo.SiafundOutput.Address), decode(&sfo.SiafundOutput.Value)) + err = s.Scan(decode(&sfo.ID), decode(&sfo.StateElement.LeafIndex), decodeNull(&spentIndex), decode(&sfo.ClaimStart), decode(&sfo.SiafundOutput.Address), decode(&sfo.SiafundOutput.Value)) if spentIndex != (types.ChainIndex{}) { sfo.SpentIndex = &spentIndex } diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index bd3e0971..bf8b4ff9 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -507,7 +507,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme defer stmt.Close() for _, sce := range newElements { - result, err := stmt.Exec(encode(sce.StateElement.ID), encode(index.ID), encode(sce.StateElement.LeafIndex), int(sce.Source), sce.MaturityHeight, encode(sce.SiacoinOutput.Address), encode(sce.SiacoinOutput.Value), encode(sce.StateElement.LeafIndex)) + result, err := stmt.Exec(encode(sce.ID), encode(index.ID), encode(sce.StateElement.LeafIndex), int(sce.Source), sce.MaturityHeight, encode(sce.SiacoinOutput.Address), encode(sce.SiacoinOutput.Value), encode(sce.StateElement.LeafIndex)) if err != nil { return nil, fmt.Errorf("addSiacoinElements: failed to execute siacoin_elements statement: %w", err) } @@ -517,7 +517,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiacoinElements: failed to get last insert ID: %w", err) } - scDBIds[types.SiacoinOutputID(sce.StateElement.ID)] = dbID + scDBIds[types.SiacoinOutputID(sce.ID)] = dbID } } if len(spentElements) > 0 { @@ -531,7 +531,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme defer stmt.Close() for _, sce := range spentElements { - result, err := stmt.Exec(encode(sce.StateElement.ID), encode(index.ID), encode(sce.StateElement.LeafIndex), encode(index), int(sce.Source), sce.MaturityHeight, encode(sce.SiacoinOutput.Address), encode(sce.SiacoinOutput.Value), encode(index), encode(sce.StateElement.LeafIndex)) + result, err := stmt.Exec(encode(sce.ID), encode(index.ID), encode(sce.StateElement.LeafIndex), encode(index), int(sce.Source), sce.MaturityHeight, encode(sce.SiacoinOutput.Address), encode(sce.SiacoinOutput.Value), encode(index), encode(sce.StateElement.LeafIndex)) if err != nil { return nil, fmt.Errorf("addSiacoinElements: failed to execute siacoin_elements statement: %w", err) } @@ -541,7 +541,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiacoinElements: failed to get last insert ID: %w", err) } - scDBIds[types.SiacoinOutputID(sce.StateElement.ID)] = dbID + scDBIds[types.SiacoinOutputID(sce.ID)] = dbID } } @@ -561,7 +561,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme defer stmt.Close() for _, sfe := range newElements { - result, err := stmt.Exec(encode(sfe.StateElement.ID), encode(index.ID), encode(sfe.StateElement.LeafIndex), encode(sfe.ClaimStart), encode(sfe.SiafundOutput.Address), encode(sfe.SiafundOutput.Value), encode(sfe.StateElement.LeafIndex)) + result, err := stmt.Exec(encode(sfe.ID), encode(index.ID), encode(sfe.StateElement.LeafIndex), encode(sfe.ClaimStart), encode(sfe.SiafundOutput.Address), encode(sfe.SiafundOutput.Value), encode(sfe.StateElement.LeafIndex)) if err != nil { return nil, fmt.Errorf("addSiafundElements: failed to execute siafund_elements statement: %w", err) } @@ -571,7 +571,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err) } - sfDBIds[types.SiafundOutputID(sfe.StateElement.ID)] = dbID + sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID } } if len(spentElements) > 0 { @@ -585,7 +585,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme defer stmt.Close() for _, sfe := range spentElements { - result, err := stmt.Exec(encode(sfe.StateElement.ID), encode(index.ID), encode(sfe.StateElement.LeafIndex), encode(index), encode(sfe.ClaimStart), encode(sfe.SiafundOutput.Address), encode(sfe.SiafundOutput.Value), encode(sfe.StateElement.LeafIndex), encode(index)) + result, err := stmt.Exec(encode(sfe.ID), encode(index.ID), encode(sfe.StateElement.LeafIndex), encode(index), encode(sfe.ClaimStart), encode(sfe.SiafundOutput.Address), encode(sfe.SiafundOutput.Value), encode(sfe.StateElement.LeafIndex), encode(index)) if err != nil { return nil, fmt.Errorf("addSiafundElements: failed to execute siafund_elements statement: %w", err) } @@ -595,7 +595,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err) } - sfDBIds[types.SiafundOutputID(sfe.StateElement.ID)] = dbID + sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID } } return sfDBIds, nil @@ -732,7 +732,7 @@ func addEvents(tx *txn, scDBIds map[types.SiacoinOutputID]int64, fcDBIds map[exp case *explorer.EventMinerPayout: _, err = minerPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)]) case *explorer.EventContractPayout: - _, err = contractPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(v.SiacoinOutput.StateElement.ID)], fcDBIds[explorer.DBFileContract{ID: types.FileContractID(v.FileContract.StateElement.ID), RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed) + _, err = contractPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(v.SiacoinOutput.ID)], fcDBIds[explorer.DBFileContract{ID: types.FileContractID(v.FileContract.ID), RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed) case *explorer.EventFoundationSubsidy: _, err = foundationSubsidyEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)]) default: @@ -917,7 +917,7 @@ func updateFileContractElements(tx *txn, revert bool, b types.Block, fces []expl } if err := addFC( - types.FileContractID(fce.StateElement.ID), + types.FileContractID(fce.ID), fce.StateElement.LeafIndex, fce.FileContract, update.Resolved, diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index 30c4555c..9ce4d927 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -379,7 +379,7 @@ func TestSendTransactions(t *testing.T) { } testutil.SignTransaction(cm.TipState(), pk1, &parentTxn) - scOutputID = types.Hash256(parentTxn.SiacoinOutputID(2)) + scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2)) sfOutputID = parentTxn.SiafundOutputID(2) // Mine a block with the above transaction @@ -1438,7 +1438,7 @@ func TestRevertSendTransactions(t *testing.T) { } testutil.SignTransaction(cm.TipState(), pk1, &parentTxn) - scOutputID = types.Hash256(parentTxn.SiacoinOutputID(2)) + scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2)) sfOutputID = parentTxn.SiafundOutputID(2) // Mine a block with the above transaction diff --git a/persist/sqlite/contracts.go b/persist/sqlite/contracts.go index 2a487c1e..89a82096 100644 --- a/persist/sqlite/contracts.go +++ b/persist/sqlite/contracts.go @@ -18,7 +18,7 @@ func encodedIDs(ids []types.FileContractID) []any { func scanFileContract(s scanner) (contractID int64, fc explorer.FileContract, err error) { var confirmationIndex, proofIndex types.ChainIndex var confirmationTransactionID, proofTransactionID types.TransactionID - err = s.Scan(&contractID, decode(&fc.StateElement.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.FileContract.Filesize), decode(&fc.FileContract.FileMerkleRoot), decode(&fc.FileContract.WindowStart), decode(&fc.FileContract.WindowEnd), decode(&fc.FileContract.Payout), decode(&fc.FileContract.UnlockHash), decode(&fc.FileContract.RevisionNumber)) + err = s.Scan(&contractID, decode(&fc.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.FileContract.Filesize), decode(&fc.FileContract.FileMerkleRoot), decode(&fc.FileContract.WindowStart), decode(&fc.FileContract.WindowEnd), decode(&fc.FileContract.Payout), decode(&fc.FileContract.UnlockHash), decode(&fc.FileContract.RevisionNumber)) if confirmationIndex != (types.ChainIndex{}) { fc.ConfirmationIndex = &confirmationIndex diff --git a/persist/sqlite/transactions.go b/persist/sqlite/transactions.go index 412ed41c..683d8d32 100644 --- a/persist/sqlite/transactions.go +++ b/persist/sqlite/transactions.go @@ -17,7 +17,7 @@ func (s *Store) TransactionChainIndices(txnID types.TransactionID, offset, limit INNER JOIN block_transactions bt ON (bt.block_id = b.id) INNER JOIN transactions t ON (t.id = bt.transaction_id) WHERE t.transaction_id = ? -ORDER BY b.height DESC +ORDER BY b.height DESC LIMIT ? OFFSET ?`, encode(txnID), limit, offset) if err != nil { return err @@ -127,7 +127,7 @@ ORDER BY ts.transaction_order ASC` var txnID int64 var spentIndex types.ChainIndex var sco explorer.SiacoinOutput - if err := rows.Scan(&txnID, decode(&sco.StateElement.ID), decode(&sco.LeafIndex), decodeNull(&spentIndex), &sco.Source, &sco.MaturityHeight, decode(&sco.SiacoinOutput.Address), decode(&sco.SiacoinOutput.Value)); err != nil { + if err := rows.Scan(&txnID, decode(&sco.ID), decode(&sco.StateElement.LeafIndex), decodeNull(&spentIndex), &sco.Source, &sco.MaturityHeight, decode(&sco.SiacoinOutput.Address), decode(&sco.SiacoinOutput.Value)); err != nil { return nil, fmt.Errorf("failed to scan siacoin output: %w", err) } if spentIndex != (types.ChainIndex{}) { @@ -209,7 +209,7 @@ ORDER BY ts.transaction_order ASC` var txnID int64 var spentIndex types.ChainIndex var sfo explorer.SiafundOutput - if err := rows.Scan(&txnID, decode(&sfo.StateElement.ID), decode(&sfo.StateElement.LeafIndex), decodeNull(&spentIndex), decode(&sfo.ClaimStart), decode(&sfo.SiafundOutput.Address), decode(&sfo.SiafundOutput.Value)); err != nil { + if err := rows.Scan(&txnID, decode(&sfo.ID), decode(&sfo.StateElement.LeafIndex), decodeNull(&spentIndex), decode(&sfo.ClaimStart), decode(&sfo.SiafundOutput.Address), decode(&sfo.SiafundOutput.Value)); err != nil { return nil, fmt.Errorf("failed to scan siafund output: %w", err) } if spentIndex != (types.ChainIndex{}) { @@ -305,7 +305,7 @@ ORDER BY ts.transaction_order ASC` var confirmationIndex, proofIndex types.ChainIndex var confirmationTransactionID, proofTransactionID types.TransactionID - if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.StateElement.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.FileContract.Filesize), decode(&fc.FileContract.FileMerkleRoot), decode(&fc.FileContract.WindowStart), decode(&fc.FileContract.WindowEnd), decode(&fc.FileContract.Payout), decode(&fc.FileContract.UnlockHash), decode(&fc.FileContract.RevisionNumber)); err != nil { + if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.FileContract.Filesize), decode(&fc.FileContract.FileMerkleRoot), decode(&fc.FileContract.WindowStart), decode(&fc.FileContract.WindowEnd), decode(&fc.FileContract.Payout), decode(&fc.FileContract.UnlockHash), decode(&fc.FileContract.RevisionNumber)); err != nil { return nil, fmt.Errorf("failed to scan file contract: %w", err) } @@ -366,7 +366,7 @@ ORDER BY ts.transaction_order ASC` var confirmationIndex, proofIndex types.ChainIndex var confirmationTransactionID, proofTransactionID types.TransactionID - if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.ParentID), decode(&fc.UnlockConditions), decode(&fc.StateElement.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.FileContract.FileContract.Filesize), decode(&fc.FileContract.FileContract.FileMerkleRoot), decode(&fc.FileContract.FileContract.WindowStart), decode(&fc.FileContract.FileContract.WindowEnd), decode(&fc.FileContract.FileContract.Payout), decode(&fc.FileContract.FileContract.UnlockHash), decode(&fc.FileContract.FileContract.RevisionNumber)); err != nil { + if err := rows.Scan(&txnID, &contractID, decodeNull(&confirmationIndex), decodeNull(&confirmationTransactionID), decodeNull(&proofIndex), decodeNull(&proofTransactionID), decode(&fc.ParentID), decode(&fc.UnlockConditions), decode(&fc.ID), decode(&fc.StateElement.LeafIndex), &fc.Resolved, &fc.Valid, decode(&fc.TransactionID), decode(&fc.FileContract.FileContract.Filesize), decode(&fc.FileContract.FileContract.FileMerkleRoot), decode(&fc.FileContract.FileContract.WindowStart), decode(&fc.FileContract.FileContract.WindowEnd), decode(&fc.FileContract.FileContract.Payout), decode(&fc.FileContract.FileContract.UnlockHash), decode(&fc.FileContract.FileContract.RevisionNumber)); err != nil { return nil, fmt.Errorf("failed to scan file contract: %w", err) } @@ -477,7 +477,7 @@ ORDER BY mp.block_order ASC` for rows.Next() { var spentIndex types.ChainIndex var output explorer.SiacoinOutput - if err := rows.Scan(decode(&output.StateElement.ID), decode(&output.StateElement.LeafIndex), decodeNull(&spentIndex), &output.Source, &output.MaturityHeight, decode(&output.SiacoinOutput.Address), decode(&output.SiacoinOutput.Value)); err != nil { + if err := rows.Scan(decode(&output.ID), decode(&output.StateElement.LeafIndex), decodeNull(&spentIndex), &output.Source, &output.MaturityHeight, decode(&output.SiacoinOutput.Address), decode(&output.SiacoinOutput.Value)); err != nil { return nil, fmt.Errorf("failed to scan miner payout: %w", err) } if spentIndex != (types.ChainIndex{}) { From 6103436b0435b7fc1d3b33dac51361a895748657 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Tue, 5 Nov 2024 16:27:56 +0100 Subject: [PATCH 3/4] explorer: call FromAttestation in AppliedEvents --- explorer/events.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/explorer/events.go b/explorer/events.go index 2ae7232e..2dfc2551 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -219,9 +219,9 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { var e EventV2Transaction for _, a := range txn.Attestations { - var ha chain.HostAnnouncement - if ha.FromArbitraryData(a.Value) { - e.HostAnnouncements = append(e.HostAnnouncements, ha) + var ha chain.V2HostAnnouncement + if ha.FromAttestation(a) == nil { + panic("implement me") } } addEvent(types.Hash256(txn.ID()), cs.Index.Height, &e, relevant) // transaction maturity height is the current block height From dcba785774d80e07a7c8aaec1f3bf1e23ee4d4b5 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 6 Nov 2024 09:50:03 +0100 Subject: [PATCH 4/4] types: remove unnecessary casts --- explorer/events.go | 14 +++++++------- explorer/update.go | 10 +++++----- persist/sqlite/consensus.go | 10 +++++----- persist/sqlite/consensus_test.go | 14 +++++++------- persist/sqlite/init.sql | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/explorer/events.go b/explorer/events.go index 2dfc2551..74b919c8 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -147,19 +147,19 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { v2fces := make(map[types.FileContractID]types.V2FileContractElement) cu.ForEachSiacoinElement(func(sce types.SiacoinElement, created, spent bool) { sce.StateElement.MerkleProof = nil - sces[types.SiacoinOutputID(sce.ID)] = sce + sces[sce.ID] = sce }) cu.ForEachSiafundElement(func(sfe types.SiafundElement, created, spent bool) { sfe.StateElement.MerkleProof = nil - sfes[types.SiafundOutputID(sfe.ID)] = sfe + sfes[sfe.ID] = sfe }) cu.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) { fce.StateElement.MerkleProof = nil - fces[types.FileContractID(fce.ID)] = fce + fces[fce.ID] = fce }) cu.ForEachV2FileContractElement(func(fce types.V2FileContractElement, created bool, rev *types.V2FileContractElement, res types.V2FileContractResolutionType) { fce.StateElement.MerkleProof = nil - v2fces[types.FileContractID(fce.ID)] = fce + v2fces[fce.ID] = fce }) relevantTxn := func(txn types.Transaction) (addrs []types.Address) { @@ -221,7 +221,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { for _, a := range txn.Attestations { var ha chain.V2HostAnnouncement if ha.FromAttestation(a) == nil { - panic("implement me") + // TODO: handle attestation } } addEvent(types.Hash256(txn.ID()), cs.Index.Height, &e, relevant) // transaction maturity height is the current block height @@ -235,7 +235,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { if valid { for i := range fce.FileContract.ValidProofOutputs { - outputID := types.FileContractID(fce.ID).ValidOutputID(i) + outputID := fce.ID.ValidOutputID(i) addEvent(types.Hash256(outputID), cs.MaturityHeight(), &EventContractPayout{ FileContract: fce, SiacoinOutput: sces[outputID], @@ -244,7 +244,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { } } else { for i := range fce.FileContract.MissedProofOutputs { - outputID := types.FileContractID(fce.ID).MissedOutputID(i) + outputID := fce.ID.MissedOutputID(i) addEvent(types.Hash256(outputID), cs.MaturityHeight(), &EventContractPayout{ FileContract: fce, SiacoinOutput: sces[outputID], diff --git a/explorer/update.go b/explorer/update.go index 9e31d222..96f16395 100644 --- a/explorer/update.go +++ b/explorer/update.go @@ -91,7 +91,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { if created && spent { ephemeralSiacoinElements = append(ephemeralSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.ID)], + Source: sources[se.ID], }) return } @@ -99,12 +99,12 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { if spent { spentSiacoinElements = append(spentSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.ID)], + Source: sources[se.ID], }) } else { newSiacoinElements = append(newSiacoinElements, SiacoinOutput{ SiacoinElement: se, - Source: sources[types.SiacoinOutputID(se.ID)], + Source: sources[se.ID], }) } }) @@ -126,7 +126,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { fceMap := make(map[types.FileContractID]FileContractUpdate) cau.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) { - fceMap[types.FileContractID(fce.ID)] = FileContractUpdate{ + fceMap[fce.ID] = FileContractUpdate{ FileContractElement: fce, Revision: rev, Resolved: resolved, @@ -244,7 +244,7 @@ func revertChainUpdate(tx UpdateTx, cru chain.RevertUpdate, revertedIndex types. fceMap := make(map[types.FileContractID]FileContractUpdate) cru.ForEachFileContractElement(func(fce types.FileContractElement, created bool, rev *types.FileContractElement, resolved, valid bool) { - fceMap[types.FileContractID(fce.ID)] = FileContractUpdate{ + fceMap[fce.ID] = FileContractUpdate{ FileContractElement: fce, Revision: rev, Resolved: resolved, diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index bf8b4ff9..3ca93686 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -517,7 +517,7 @@ func addSiacoinElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiacoinElements: failed to get last insert ID: %w", err) } - scDBIds[types.SiacoinOutputID(sce.ID)] = dbID + scDBIds[sce.ID] = dbID } } if len(spentElements) > 0 { @@ -571,7 +571,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err) } - sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID + sfDBIds[sfe.ID] = dbID } } if len(spentElements) > 0 { @@ -595,7 +595,7 @@ func addSiafundElements(tx *txn, index types.ChainIndex, spentElements, newEleme return nil, fmt.Errorf("addSiafundElements: failed to get last insert ID: %w", err) } - sfDBIds[types.SiafundOutputID(sfe.ID)] = dbID + sfDBIds[sfe.ID] = dbID } } return sfDBIds, nil @@ -732,7 +732,7 @@ func addEvents(tx *txn, scDBIds map[types.SiacoinOutputID]int64, fcDBIds map[exp case *explorer.EventMinerPayout: _, err = minerPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)]) case *explorer.EventContractPayout: - _, err = contractPayoutEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(v.SiacoinOutput.ID)], fcDBIds[explorer.DBFileContract{ID: types.FileContractID(v.FileContract.ID), RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed) + _, err = contractPayoutEventStmt.Exec(eventID, scDBIds[v.SiacoinOutput.ID], fcDBIds[explorer.DBFileContract{ID: v.FileContract.ID, RevisionNumber: v.FileContract.FileContract.RevisionNumber}], v.Missed) case *explorer.EventFoundationSubsidy: _, err = foundationSubsidyEventStmt.Exec(eventID, scDBIds[types.SiacoinOutputID(event.ID)]) default: @@ -917,7 +917,7 @@ func updateFileContractElements(tx *txn, revert bool, b types.Block, fces []expl } if err := addFC( - types.FileContractID(fce.ID), + fce.ID, fce.StateElement.LeafIndex, fce.FileContract, update.Resolved, diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index 9ce4d927..141fe92f 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -163,7 +163,7 @@ func TestBalance(t *testing.T) { parentTxn := types.Transaction{ SiacoinInputs: []types.SiacoinInput{ { - ParentID: types.SiacoinOutputID(utxos[0].ID), + ParentID: utxos[0].ID, UnlockConditions: unlockConditions, }, }, @@ -240,7 +240,7 @@ func TestSiafundBalance(t *testing.T) { parentTxn := types.Transaction{ SiafundInputs: []types.SiafundInput{ { - ParentID: types.SiafundOutputID(genesisBlock.Transactions[0].SiafundOutputID(0)), + ParentID: genesisBlock.Transactions[0].SiafundOutputID(0), UnlockConditions: unlockConditions, }, }, @@ -356,7 +356,7 @@ func TestSendTransactions(t *testing.T) { parentTxn := types.Transaction{ SiacoinInputs: []types.SiacoinInput{ { - ParentID: types.SiacoinOutputID(scOutputID), + ParentID: scOutputID, UnlockConditions: unlockConditions, }, }, @@ -379,7 +379,7 @@ func TestSendTransactions(t *testing.T) { } testutil.SignTransaction(cm.TipState(), pk1, &parentTxn) - scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2)) + scOutputID = parentTxn.SiacoinOutputID(2) sfOutputID = parentTxn.SiafundOutputID(2) // Mine a block with the above transaction @@ -1220,7 +1220,7 @@ func TestRevertBalance(t *testing.T) { parentTxn := types.Transaction{ SiacoinInputs: []types.SiacoinInput{ { - ParentID: types.SiacoinOutputID(utxos2[0].ID), + ParentID: utxos2[0].ID, UnlockConditions: unlockConditions, }, }, @@ -1415,7 +1415,7 @@ func TestRevertSendTransactions(t *testing.T) { parentTxn := types.Transaction{ SiacoinInputs: []types.SiacoinInput{ { - ParentID: types.SiacoinOutputID(scOutputID), + ParentID: scOutputID, UnlockConditions: unlockConditions, }, }, @@ -1438,7 +1438,7 @@ func TestRevertSendTransactions(t *testing.T) { } testutil.SignTransaction(cm.TipState(), pk1, &parentTxn) - scOutputID = types.SiacoinOutputID(parentTxn.SiacoinOutputID(2)) + scOutputID = parentTxn.SiacoinOutputID(2) sfOutputID = parentTxn.SiafundOutputID(2) // Mine a block with the above transaction diff --git a/persist/sqlite/init.sql b/persist/sqlite/init.sql index 05b56971..d43a451f 100644 --- a/persist/sqlite/init.sql +++ b/persist/sqlite/init.sql @@ -296,7 +296,7 @@ CREATE TABLE events ( CREATE INDEX events_block_id_height_index ON events(block_id, height); CREATE TABLE event_addresses ( - event_id INTEGER NOT NULL REFERENCES events(id) ON DELETE CASCADE, + event_id INTEGER NOT NULL REFERENCES events(id) ON DELETE CASCADE, address_id INTEGER NOT NULL REFERENCES address_balance(id), PRIMARY KEY (event_id, address_id) );