diff --git a/api/api_test.go b/api/api_test.go index 4a45ed0..e46273d 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -271,7 +271,7 @@ func TestAPI(t *testing.T) { testutil.Equal(t, "previous timestamps", cs.PrevTimestamps, resp.PrevTimestamps) testutil.Equal(t, "depth", cs.Depth, resp.Depth) testutil.Equal(t, "child target", cs.ChildTarget, resp.ChildTarget) - testutil.Equal(t, "siafund pool", cs.SiafundPool, resp.SiafundPool) + testutil.Equal(t, "siafund tax revenue", cs.SiafundTaxRevenue, resp.SiafundTaxRevenue) }}, {"Tip", func(t *testing.T) { resp, err := client.Tip() @@ -292,7 +292,7 @@ func TestAPI(t *testing.T) { cs := cm.TipState() testutil.Equal(t, "index", cs.Index, resp.Index) testutil.Equal(t, "difficulty", cs.Difficulty, resp.Difficulty) - testutil.Equal(t, "siafund pool", cs.SiafundPool, resp.SiafundPool) + testutil.Equal(t, "siafund tax revenue", cs.SiafundTaxRevenue, resp.SiafundTaxRevenue) testutil.Equal(t, "total hosts", 1, resp.TotalHosts) testutil.Equal(t, "active contracts", 1, resp.ActiveContracts) testutil.Equal(t, "failed contracts", 0, resp.FailedContracts) @@ -313,7 +313,7 @@ func TestAPI(t *testing.T) { cs := cm.TipState() testutil.Equal(t, "index", tip, resp.Index) testutil.Equal(t, "difficulty", cs.Difficulty, resp.Difficulty) - testutil.Equal(t, "siafund pool", cs.SiafundPool, resp.SiafundPool) + testutil.Equal(t, "siafund tax revenue", cs.SiafundTaxRevenue, resp.SiafundTaxRevenue) testutil.Equal(t, "total hosts", 0, resp.TotalHosts) testutil.Equal(t, "active contracts", 1, resp.ActiveContracts) testutil.Equal(t, "failed contracts", 0, resp.FailedContracts) diff --git a/api/server.go b/api/server.go index fa4615a..597350f 100644 --- a/api/server.go +++ b/api/server.go @@ -39,7 +39,7 @@ type ( Addr() string Peers() []*syncer.Peer Connect(ctx context.Context, addr string) (*syncer.Peer, error) - BroadcastHeader(bh gateway.BlockHeader) + BroadcastHeader(bh types.BlockHeader) BroadcastTransactionSet(txns []types.Transaction) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction) BroadcastV2BlockOutline(bo gateway.V2BlockOutline) @@ -146,12 +146,7 @@ func (s *server) syncerBroadcastBlockHandler(jc jape.Context) { return } if b.V2 == nil { - s.s.BroadcastHeader(gateway.BlockHeader{ - ParentID: b.ParentID, - Nonce: b.Nonce, - Timestamp: b.Timestamp, - MerkleRoot: b.MerkleRoot(), - }) + s.s.BroadcastHeader(b.Header()) } else { s.s.BroadcastV2BlockOutline(gateway.OutlineBlock(b, s.cm.PoolTransactions(), s.cm.V2PoolTransactions())) } diff --git a/explorer/events.go b/explorer/events.go index 9328961..4c4f0a5 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -268,7 +268,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate) []Event { if ok { addEvent(types.Hash256(outputID), cs.MaturityHeight(), &EventFoundationSubsidy{ SiacoinOutput: sce, - }, []types.Address{cs.FoundationPrimaryAddress}) + }, []types.Address{cs.FoundationSubsidyAddress}) } return events diff --git a/explorer/types.go b/explorer/types.go index a78969f..eec17fa 100644 --- a/explorer/types.go +++ b/explorer/types.go @@ -213,10 +213,11 @@ type V2HostAnnouncement struct { // A V2FileContractRenewal renews a file contract. type V2FileContractRenewal struct { - FinalRevision V2FileContract `json:"finalRevision"` - NewContract V2FileContract `json:"newContract"` - RenterRollover types.Currency `json:"renterRollover"` - HostRollover types.Currency `json:"hostRollover"` + FinalRenterOutput types.SiacoinOutput `json:"finalRenterOutput"` + FinalHostOutput types.SiacoinOutput `json:"finalHostOutput"` + RenterRollover types.Currency `json:"renterRollover"` + HostRollover types.Currency `json:"hostRollover"` + NewContract V2FileContract `json:"newContract"` // signatures cover above fields RenterSignature types.Signature `json:"renterSignature"` @@ -283,7 +284,7 @@ type Metrics struct { // Current difficulty Difficulty consensus.Work `json:"difficulty"` // Siafund pool value - SiafundPool types.Currency `json:"siafundPool"` + SiafundTaxRevenue types.Currency `json:"siafundTaxRevenue"` // Total announced hosts TotalHosts uint64 `json:"totalHosts"` // Number of leaves in the accumulator diff --git a/explorer/update.go b/explorer/update.go index 9ac7493..6c0a9e8 100644 --- a/explorer/update.go +++ b/explorer/update.go @@ -279,7 +279,7 @@ func applyChainUpdate(tx UpdateTx, cau chain.ApplyUpdate) error { } state.Metrics.Index = cau.State.Index state.Metrics.Difficulty = cau.State.Difficulty - state.Metrics.SiafundPool = cau.State.SiafundPool + state.Metrics.SiafundTaxRevenue = cau.State.SiafundTaxRevenue state.Metrics.NumLeaves = cau.State.Elements.NumLeaves return tx.ApplyIndex(state) diff --git a/go.mod b/go.mod index e119951..83c1ef7 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ 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.6.2 - go.sia.tech/coreutils v0.7.0 + go.sia.tech/core v0.7.1-0.20241203043244-c435a355b1da + go.sia.tech/coreutils v0.7.1-0.20241203170156-ac0cf880fa70 go.sia.tech/jape v0.12.1 go.uber.org/zap v1.27.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index aa7fd85..27ce0c7 100644 --- a/go.sum +++ b/go.sum @@ -21,10 +21,14 @@ 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.6.2 h1:8NEjxyD93A+EhZopsBy/LvuHH+zUSjRNKnf9rXgtIwU= -go.sia.tech/core v0.6.2/go.mod h1:4v+aT/33857tMfqa5j5OYlAoLsoIrd4d7qMlgeP+VGk= +go.sia.tech/core v0.6.3 h1:7VdCSF61td1iatjGc5xt8WwCZgyB91mTvKhuL35o234= +go.sia.tech/core v0.6.3/go.mod h1:4v+aT/33857tMfqa5j5OYlAoLsoIrd4d7qMlgeP+VGk= +go.sia.tech/core v0.7.1-0.20241203043244-c435a355b1da h1:taO86czGly5SIb8UswVI2W7rmxhmv9G4C93zoAwtfxk= +go.sia.tech/core v0.7.1-0.20241203043244-c435a355b1da/go.mod h1:4v+aT/33857tMfqa5j5OYlAoLsoIrd4d7qMlgeP+VGk= go.sia.tech/coreutils v0.7.0 h1:YpgOUD4vrpDz0KC7FJz+UCOaKaqV5EkX3gMUUmJoz5s= go.sia.tech/coreutils v0.7.0/go.mod h1:eMoqzqO4opKQ6n9tTTxHQmccfNlj+8RFOYuDSL/Qd4g= +go.sia.tech/coreutils v0.7.1-0.20241203170156-ac0cf880fa70 h1:ksY8McNsjadZvAzEISY+sfsJmOVRhLGr1oN64dpZtFY= +go.sia.tech/coreutils v0.7.1-0.20241203170156-ac0cf880fa70/go.mod h1:d6jrawloc02MCXi/EVc8FIN5h3C6XDiMs4fuFMcU0PU= 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= diff --git a/internal/testutil/chain.go b/internal/testutil/chain.go index de97dc7..e89806e 100644 --- a/internal/testutil/chain.go +++ b/internal/testutil/chain.go @@ -173,14 +173,11 @@ func SignV2TransactionWithContracts(cs consensus.State, pk, renterPK, hostPK typ txn.FileContractRevisions[i].Revision.HostSignature = hostPK.SignHash(cs.ContractSigHash(txn.FileContractRevisions[i].Revision)) } for i := range txn.FileContractResolutions { - switch r := txn.FileContractResolutions[i].Resolution.(type) { - case *types.V2FileContractRenewal: + if r, ok := txn.FileContractResolutions[i].Resolution.(*types.V2FileContractRenewal); ok { r.RenterSignature = renterPK.SignHash(cs.RenewalSigHash(*r)) r.HostSignature = hostPK.SignHash(cs.RenewalSigHash(*r)) - case *types.V2FileContractFinalization: - finalRevision := txn.FileContractResolutions[i].Parent.V2FileContract - finalRevision.RevisionNumber = types.MaxRevisionNumber - *r = types.V2FileContractFinalization(renterPK.SignHash(cs.ContractSigHash(finalRevision))) + r.NewContract.RenterSignature = renterPK.SignHash(cs.ContractSigHash(r.NewContract)) + r.NewContract.HostSignature = hostPK.SignHash(cs.ContractSigHash(r.NewContract)) } } } diff --git a/internal/testutil/check.go b/internal/testutil/check.go index f0b5812..13fa049 100644 --- a/internal/testutil/check.go +++ b/internal/testutil/check.go @@ -143,6 +143,9 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl Equal(t, "maturity height", expected.Parent.MaturityHeight, got.Parent.MaturityHeight) Equal(t, "id", expected.Parent.ID, got.Parent.ID) Equal(t, "leaf index", expected.Parent.StateElement.LeafIndex, got.Parent.StateElement.LeafIndex) + if len(got.SatisfiedPolicy.Preimages) == 0 { + got.SatisfiedPolicy.Preimages = nil + } Equal(t, "satisfied policy", expected.SatisfiedPolicy, got.SatisfiedPolicy) } @@ -165,6 +168,9 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl Equal(t, "claim address", expected.ClaimAddress, got.ClaimAddress) Equal(t, "id", expected.Parent.ID, got.Parent.ID) Equal(t, "leaf index", expected.Parent.StateElement.LeafIndex, got.Parent.StateElement.LeafIndex) + if len(got.SatisfiedPolicy.Preimages) == 0 { + got.SatisfiedPolicy.Preimages = nil + } Equal(t, "satisfied policy", expected.SatisfiedPolicy, got.SatisfiedPolicy) } @@ -209,10 +215,13 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl if gotV, ok := got.Resolution.(*explorer.V2FileContractRenewal); !ok { t.Fatalf("expected V2FileContractRenewal, got %v", reflect.TypeOf(got.Resolution)) } else { - CheckV2FC(t, v.FinalRevision, gotV.FinalRevision) CheckV2FC(t, v.NewContract, gotV.NewContract) Equal(t, "type", "renewal", got.Type) + Equal(t, "final renter output address", v.FinalRenterOutput.Address, gotV.FinalRenterOutput.Address) + Equal(t, "final renter output value", v.FinalRenterOutput.Value, gotV.FinalRenterOutput.Value) + Equal(t, "final host output address", v.FinalHostOutput.Address, gotV.FinalHostOutput.Address) + Equal(t, "final host output value", v.FinalHostOutput.Value, gotV.FinalHostOutput.Value) Equal(t, "renter rollover", v.RenterRollover, gotV.RenterRollover) Equal(t, "host rollover", v.HostRollover, gotV.HostRollover) Equal(t, "renter signature", v.RenterSignature, gotV.RenterSignature) @@ -227,13 +236,6 @@ func CheckV2Transaction(t *testing.T, expectTxn types.V2Transaction, gotTxn expl Equal(t, "leaf", v.Leaf, gotV.Leaf) Equal(t, "proof", v.Proof, gotV.Proof) } - case *types.V2FileContractFinalization: - if gotV, ok := got.Resolution.(*types.V2FileContractFinalization); !ok { - t.Fatalf("expected V2FileContractFinalization, got %v", reflect.TypeOf(got.Resolution)) - } else { - Equal(t, "type", "finalization", got.Type) - Equal(t, "finalization signature", types.Signature(*v), types.Signature(*gotV)) - } case *types.V2FileContractExpiration: Equal(t, "type", "expiration", got.Type) if _, ok := got.Resolution.(*types.V2FileContractExpiration); !ok { diff --git a/persist/sqlite/addresses.go b/persist/sqlite/addresses.go index 772a330..760c908 100644 --- a/persist/sqlite/addresses.go +++ b/persist/sqlite/addresses.go @@ -89,7 +89,7 @@ func (st *Store) Hosts(pks []types.PublicKey) (result []explorer.Host, err error encoded = append(encoded, encode(pk)) } - rows, err := tx.Query(`SELECT public_key,net_address,country_code,known_since,last_scan,last_scan_successful,last_announcement,total_scans,successful_interactions,failed_interactions,settings_accepting_contracts,settings_max_download_batch_size,settings_max_duration,settings_max_revise_batch_size,settings_net_address,settings_remaining_storage,settings_sector_size,settings_total_storage,settings_address,settings_window_size,settings_collateral,settings_max_collateral,settings_base_rpc_price,settings_contract_price,settings_download_bandwidth_price,settings_sector_access_price,settings_storage_price,settings_upload_bandwidth_price,settings_ephemeral_account_expiry,settings_max_ephemeral_account_balance,settings_revision_number,settings_version,settings_release,settings_sia_mux_port,price_table_uid,price_table_validity,price_table_host_block_height,price_table_update_price_table_cost,price_table_account_balance_cost,price_table_fund_account_cost,price_table_latest_revision_cost,price_table_subscription_memory_cost,price_table_subscription_notification_cost,price_table_init_base_cost,price_table_memory_time_cost,price_table_download_bandwidth_cost,price_table_upload_bandwidth_cost,price_table_drop_sectors_base_cost,price_table_drop_sectors_unit_cost,price_table_has_sector_base_cost,price_table_read_base_cost,price_table_read_length_cost,price_table_renew_contract_cost,price_table_revision_base_cost,price_table_swap_sector_base_cost,price_table_write_base_cost,price_table_write_length_cost,price_table_write_store_cost,price_table_txn_fee_min_recommended,price_table_txn_fee_max_recommended,price_table_contract_price,price_table_collateral_cost,price_table_max_collateral,price_table_max_duration,price_table_window_size,price_table_registry_entries_left,price_table_registry_entries_total,rhp4_settings_protocol_version,rhp4_settings_release,rhp4_settings_wallet_address,rhp4_settings_accepting_contracts,rhp4_settings_max_collateral,rhp4_settings_max_collateral_duration,rhp4_settings_max_sector_duration,rhp4_settings_max_sector_batch_size,rhp4_settings_remaining_storage,rhp4_settings_total_storage,rhp4_prices_contract_price,rhp4_prices_collateral_price,rhp4_prices_storage_price,rhp4_prices_ingress_price,rhp4_prices_egress_price,rhp4_prices_free_sector_price,rhp4_prices_tip_height,rhp4_prices_valid_until,rhp4_prices_signature FROM host_info WHERE public_key IN (`+queryPlaceHolders(len(pks))+`)`, encoded...) + rows, err := tx.Query(`SELECT public_key,net_address,country_code,known_since,last_scan,last_scan_successful,last_announcement,total_scans,successful_interactions,failed_interactions,settings_accepting_contracts,settings_max_download_batch_size,settings_max_duration,settings_max_revise_batch_size,settings_net_address,settings_remaining_storage,settings_sector_size,settings_total_storage,settings_address,settings_window_size,settings_collateral,settings_max_collateral,settings_base_rpc_price,settings_contract_price,settings_download_bandwidth_price,settings_sector_access_price,settings_storage_price,settings_upload_bandwidth_price,settings_ephemeral_account_expiry,settings_max_ephemeral_account_balance,settings_revision_number,settings_version,settings_release,settings_sia_mux_port,price_table_uid,price_table_validity,price_table_host_block_height,price_table_update_price_table_cost,price_table_account_balance_cost,price_table_fund_account_cost,price_table_latest_revision_cost,price_table_subscription_memory_cost,price_table_subscription_notification_cost,price_table_init_base_cost,price_table_memory_time_cost,price_table_download_bandwidth_cost,price_table_upload_bandwidth_cost,price_table_drop_sectors_base_cost,price_table_drop_sectors_unit_cost,price_table_has_sector_base_cost,price_table_read_base_cost,price_table_read_length_cost,price_table_renew_contract_cost,price_table_revision_base_cost,price_table_swap_sector_base_cost,price_table_write_base_cost,price_table_write_length_cost,price_table_write_store_cost,price_table_txn_fee_min_recommended,price_table_txn_fee_max_recommended,price_table_contract_price,price_table_collateral_cost,price_table_max_collateral,price_table_max_duration,price_table_window_size,price_table_registry_entries_left,price_table_registry_entries_total,rhp4_settings_protocol_version,rhp4_settings_release,rhp4_settings_wallet_address,rhp4_settings_accepting_contracts,rhp4_settings_max_collateral,rhp4_settings_max_contract_duration,rhp4_settings_remaining_storage,rhp4_settings_total_storage,rhp4_prices_contract_price,rhp4_prices_collateral_price,rhp4_prices_storage_price,rhp4_prices_ingress_price,rhp4_prices_egress_price,rhp4_prices_free_sector_price,rhp4_prices_tip_height,rhp4_prices_valid_until,rhp4_prices_signature FROM host_info WHERE public_key IN (`+queryPlaceHolders(len(pks))+`)`, encoded...) if err != nil { return err } @@ -108,7 +108,7 @@ func (st *Store) Hosts(pks []types.PublicKey) (result []explorer.Host, err error s, p := &host.Settings, &host.PriceTable sV4, pV4 := &host.RHPV4Settings, &host.RHPV4Settings.Prices - if err := rows.Scan(decode(&host.PublicKey), &host.NetAddress, &host.CountryCode, decode(&host.KnownSince), decode(&host.LastScan), &host.LastScanSuccessful, decode(&host.LastAnnouncement), &host.TotalScans, &host.SuccessfulInteractions, &host.FailedInteractions, &s.AcceptingContracts, decode(&s.MaxDownloadBatchSize), decode(&s.MaxDuration), decode(&s.MaxReviseBatchSize), &s.NetAddress, decode(&s.RemainingStorage), decode(&s.SectorSize), decode(&s.TotalStorage), decode(&s.Address), decode(&s.WindowSize), decode(&s.Collateral), decode(&s.MaxCollateral), decode(&s.BaseRPCPrice), decode(&s.ContractPrice), decode(&s.DownloadBandwidthPrice), decode(&s.SectorAccessPrice), decode(&s.StoragePrice), decode(&s.UploadBandwidthPrice), &s.EphemeralAccountExpiry, decode(&s.MaxEphemeralAccountBalance), decode(&s.RevisionNumber), &s.Version, &s.Release, &s.SiaMuxPort, decode(&p.UID), &p.Validity, decode(&p.HostBlockHeight), decode(&p.UpdatePriceTableCost), decode(&p.AccountBalanceCost), decode(&p.FundAccountCost), decode(&p.LatestRevisionCost), decode(&p.SubscriptionMemoryCost), decode(&p.SubscriptionNotificationCost), decode(&p.InitBaseCost), decode(&p.MemoryTimeCost), decode(&p.DownloadBandwidthCost), decode(&p.UploadBandwidthCost), decode(&p.DropSectorsBaseCost), decode(&p.DropSectorsUnitCost), decode(&p.HasSectorBaseCost), decode(&p.ReadBaseCost), decode(&p.ReadLengthCost), decode(&p.RenewContractCost), decode(&p.RevisionBaseCost), decode(&p.SwapSectorBaseCost), decode(&p.WriteBaseCost), decode(&p.WriteLengthCost), decode(&p.WriteStoreCost), decode(&p.TxnFeeMinRecommended), decode(&p.TxnFeeMaxRecommended), decode(&p.ContractPrice), decode(&p.CollateralCost), decode(&p.MaxCollateral), decode(&p.MaxDuration), decode(&p.WindowSize), decode(&p.RegistryEntriesLeft), decode(&p.RegistryEntriesTotal), &protocolVersion, &sV4.Release, decode(&sV4.WalletAddress), &sV4.AcceptingContracts, decode(&sV4.MaxCollateral), decode(&sV4.MaxContractDuration), decode(&sV4.MaxSectorDuration), decode(&sV4.MaxSectorBatchSize), decode(&sV4.RemainingStorage), decode(&sV4.TotalStorage), decode(&pV4.ContractPrice), decode(&pV4.Collateral), decode(&pV4.StoragePrice), decode(&pV4.IngressPrice), decode(&pV4.EgressPrice), decode(&pV4.FreeSectorPrice), decode(&pV4.TipHeight), decode(&pV4.ValidUntil), decode(&pV4.Signature)); err != nil { + if err := rows.Scan(decode(&host.PublicKey), &host.NetAddress, &host.CountryCode, decode(&host.KnownSince), decode(&host.LastScan), &host.LastScanSuccessful, decode(&host.LastAnnouncement), &host.TotalScans, &host.SuccessfulInteractions, &host.FailedInteractions, &s.AcceptingContracts, decode(&s.MaxDownloadBatchSize), decode(&s.MaxDuration), decode(&s.MaxReviseBatchSize), &s.NetAddress, decode(&s.RemainingStorage), decode(&s.SectorSize), decode(&s.TotalStorage), decode(&s.Address), decode(&s.WindowSize), decode(&s.Collateral), decode(&s.MaxCollateral), decode(&s.BaseRPCPrice), decode(&s.ContractPrice), decode(&s.DownloadBandwidthPrice), decode(&s.SectorAccessPrice), decode(&s.StoragePrice), decode(&s.UploadBandwidthPrice), &s.EphemeralAccountExpiry, decode(&s.MaxEphemeralAccountBalance), decode(&s.RevisionNumber), &s.Version, &s.Release, &s.SiaMuxPort, decode(&p.UID), &p.Validity, decode(&p.HostBlockHeight), decode(&p.UpdatePriceTableCost), decode(&p.AccountBalanceCost), decode(&p.FundAccountCost), decode(&p.LatestRevisionCost), decode(&p.SubscriptionMemoryCost), decode(&p.SubscriptionNotificationCost), decode(&p.InitBaseCost), decode(&p.MemoryTimeCost), decode(&p.DownloadBandwidthCost), decode(&p.UploadBandwidthCost), decode(&p.DropSectorsBaseCost), decode(&p.DropSectorsUnitCost), decode(&p.HasSectorBaseCost), decode(&p.ReadBaseCost), decode(&p.ReadLengthCost), decode(&p.RenewContractCost), decode(&p.RevisionBaseCost), decode(&p.SwapSectorBaseCost), decode(&p.WriteBaseCost), decode(&p.WriteLengthCost), decode(&p.WriteStoreCost), decode(&p.TxnFeeMinRecommended), decode(&p.TxnFeeMaxRecommended), decode(&p.ContractPrice), decode(&p.CollateralCost), decode(&p.MaxCollateral), decode(&p.MaxDuration), decode(&p.WindowSize), decode(&p.RegistryEntriesLeft), decode(&p.RegistryEntriesTotal), &protocolVersion, &sV4.Release, decode(&sV4.WalletAddress), &sV4.AcceptingContracts, decode(&sV4.MaxCollateral), decode(&sV4.MaxContractDuration), decode(&sV4.RemainingStorage), decode(&sV4.TotalStorage), decode(&pV4.ContractPrice), decode(&pV4.Collateral), decode(&pV4.StoragePrice), decode(&pV4.IngressPrice), decode(&pV4.EgressPrice), decode(&pV4.FreeSectorPrice), decode(&pV4.TipHeight), decode(&pV4.ValidUntil), decode(&pV4.Signature)); err != nil { return err } sV4.ProtocolVersion = [3]uint8(protocolVersion) diff --git a/persist/sqlite/consensus.go b/persist/sqlite/consensus.go index ab54daf..8330cbd 100644 --- a/persist/sqlite/consensus.go +++ b/persist/sqlite/consensus.go @@ -973,11 +973,11 @@ func updateFileContractIndices(tx *txn, revert bool, index types.ChainIndex, fce } func addMetrics(tx *txn, s explorer.UpdateState) error { - _, err := tx.Exec(`INSERT INTO network_metrics(block_id, height, difficulty, siafund_pool, num_leaves, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + _, err := tx.Exec(`INSERT INTO network_metrics(block_id, height, difficulty, siafund_tax_revenue, num_leaves, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, encode(s.Metrics.Index.ID), s.Metrics.Index.Height, encode(s.Metrics.Difficulty), - encode(s.Metrics.SiafundPool), + encode(s.Metrics.SiafundTaxRevenue), encode(s.Metrics.NumLeaves), s.Metrics.TotalHosts, s.Metrics.ActiveContracts, @@ -1114,7 +1114,7 @@ func addHosts(tx *txn, hosts []explorer.Host) error { return nil } - stmt, err := tx.Prepare(`INSERT INTO host_info(public_key, net_address, country_code, known_since, last_scan, last_scan_successful, last_announcement, total_scans, successful_interactions, failed_interactions, settings_accepting_contracts, settings_max_download_batch_size, settings_max_duration, settings_max_revise_batch_size, settings_net_address, settings_remaining_storage, settings_sector_size, settings_total_storage, settings_address, settings_window_size, settings_collateral, settings_max_collateral, settings_base_rpc_price, settings_contract_price, settings_download_bandwidth_price, settings_sector_access_price, settings_storage_price, settings_upload_bandwidth_price, settings_ephemeral_account_expiry, settings_max_ephemeral_account_balance, settings_revision_number, settings_version, settings_release, settings_sia_mux_port, price_table_uid, price_table_validity, price_table_host_block_height, price_table_update_price_table_cost, price_table_account_balance_cost, price_table_fund_account_cost, price_table_latest_revision_cost, price_table_subscription_memory_cost, price_table_subscription_notification_cost, price_table_init_base_cost, price_table_memory_time_cost, price_table_download_bandwidth_cost, price_table_upload_bandwidth_cost, price_table_drop_sectors_base_cost, price_table_drop_sectors_unit_cost, price_table_has_sector_base_cost, price_table_read_base_cost, price_table_read_length_cost, price_table_renew_contract_cost, price_table_revision_base_cost, price_table_swap_sector_base_cost, price_table_write_base_cost, price_table_write_length_cost, price_table_write_store_cost, price_table_txn_fee_min_recommended, price_table_txn_fee_max_recommended, price_table_contract_price, price_table_collateral_cost, price_table_max_collateral, price_table_max_duration, price_table_window_size, price_table_registry_entries_left, price_table_registry_entries_total, rhp4_settings_protocol_version, rhp4_settings_release, rhp4_settings_wallet_address, rhp4_settings_accepting_contracts, rhp4_settings_max_collateral, rhp4_settings_max_collateral_duration, rhp4_settings_max_sector_duration, rhp4_settings_max_sector_batch_size, rhp4_settings_remaining_storage, rhp4_settings_total_storage, rhp4_prices_contract_price, rhp4_prices_collateral_price, rhp4_prices_storage_price, rhp4_prices_ingress_price, rhp4_prices_egress_price, rhp4_prices_free_sector_price, rhp4_prices_tip_height, rhp4_prices_valid_until, rhp4_prices_signature) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$80,$81,$82,$83,$84,$85,$86) ON CONFLICT (public_key) DO UPDATE SET net_address = EXCLUDED.net_address, last_announcement = EXCLUDED.last_announcement`) + stmt, err := tx.Prepare(`INSERT INTO host_info(public_key, net_address, country_code, known_since, last_scan, last_scan_successful, last_announcement, total_scans, successful_interactions, failed_interactions, settings_accepting_contracts, settings_max_download_batch_size, settings_max_duration, settings_max_revise_batch_size, settings_net_address, settings_remaining_storage, settings_sector_size, settings_total_storage, settings_address, settings_window_size, settings_collateral, settings_max_collateral, settings_base_rpc_price, settings_contract_price, settings_download_bandwidth_price, settings_sector_access_price, settings_storage_price, settings_upload_bandwidth_price, settings_ephemeral_account_expiry, settings_max_ephemeral_account_balance, settings_revision_number, settings_version, settings_release, settings_sia_mux_port, price_table_uid, price_table_validity, price_table_host_block_height, price_table_update_price_table_cost, price_table_account_balance_cost, price_table_fund_account_cost, price_table_latest_revision_cost, price_table_subscription_memory_cost, price_table_subscription_notification_cost, price_table_init_base_cost, price_table_memory_time_cost, price_table_download_bandwidth_cost, price_table_upload_bandwidth_cost, price_table_drop_sectors_base_cost, price_table_drop_sectors_unit_cost, price_table_has_sector_base_cost, price_table_read_base_cost, price_table_read_length_cost, price_table_renew_contract_cost, price_table_revision_base_cost, price_table_swap_sector_base_cost, price_table_write_base_cost, price_table_write_length_cost, price_table_write_store_cost, price_table_txn_fee_min_recommended, price_table_txn_fee_max_recommended, price_table_contract_price, price_table_collateral_cost, price_table_max_collateral, price_table_max_duration, price_table_window_size, price_table_registry_entries_left, price_table_registry_entries_total, rhp4_settings_protocol_version, rhp4_settings_release, rhp4_settings_wallet_address, rhp4_settings_accepting_contracts, rhp4_settings_max_collateral, rhp4_settings_max_contract_duration, rhp4_settings_remaining_storage, rhp4_settings_total_storage, rhp4_prices_contract_price, rhp4_prices_collateral_price, rhp4_prices_storage_price, rhp4_prices_ingress_price, rhp4_prices_egress_price, rhp4_prices_free_sector_price, rhp4_prices_tip_height, rhp4_prices_valid_until, rhp4_prices_signature) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$80,$81,$82,$83,$84) ON CONFLICT (public_key) DO UPDATE SET net_address = EXCLUDED.net_address, last_announcement = EXCLUDED.last_announcement`) if err != nil { return fmt.Errorf("failed to prepare host_info stmt: %w", err) } @@ -1136,7 +1136,7 @@ func addHosts(tx *txn, hosts []explorer.Host) error { s, p := host.Settings, host.PriceTable sV4, pV4 := host.RHPV4Settings, host.RHPV4Settings.Prices - if _, err := stmt.Exec(encode(host.PublicKey), host.NetAddress, host.CountryCode, encode(host.KnownSince), encode(host.LastScan), host.LastScanSuccessful, encode(host.LastAnnouncement), host.TotalScans, host.SuccessfulInteractions, host.FailedInteractions, s.AcceptingContracts, encode(s.MaxDownloadBatchSize), encode(s.MaxDuration), encode(s.MaxReviseBatchSize), s.NetAddress, encode(s.RemainingStorage), encode(s.SectorSize), encode(s.TotalStorage), encode(s.Address), encode(s.WindowSize), encode(s.Collateral), encode(s.MaxCollateral), encode(s.BaseRPCPrice), encode(s.ContractPrice), encode(s.DownloadBandwidthPrice), encode(s.SectorAccessPrice), encode(s.StoragePrice), encode(s.UploadBandwidthPrice), s.EphemeralAccountExpiry, encode(s.MaxEphemeralAccountBalance), encode(s.RevisionNumber), s.Version, s.Release, s.SiaMuxPort, encode(p.UID), p.Validity, encode(p.HostBlockHeight), encode(p.UpdatePriceTableCost), encode(p.AccountBalanceCost), encode(p.FundAccountCost), encode(p.LatestRevisionCost), encode(p.SubscriptionMemoryCost), encode(p.SubscriptionNotificationCost), encode(p.InitBaseCost), encode(p.MemoryTimeCost), encode(p.DownloadBandwidthCost), encode(p.UploadBandwidthCost), encode(p.DropSectorsBaseCost), encode(p.DropSectorsUnitCost), encode(p.HasSectorBaseCost), encode(p.ReadBaseCost), encode(p.ReadLengthCost), encode(p.RenewContractCost), encode(p.RevisionBaseCost), encode(p.SwapSectorBaseCost), encode(p.WriteBaseCost), encode(p.WriteLengthCost), encode(p.WriteStoreCost), encode(p.TxnFeeMinRecommended), encode(p.TxnFeeMaxRecommended), encode(p.ContractPrice), encode(p.CollateralCost), encode(p.MaxCollateral), encode(p.MaxDuration), encode(p.WindowSize), encode(p.RegistryEntriesLeft), encode(p.RegistryEntriesTotal), sV4.ProtocolVersion[:], sV4.Release, encode(sV4.WalletAddress), sV4.AcceptingContracts, encode(sV4.MaxCollateral), encode(sV4.MaxContractDuration), encode(sV4.MaxSectorDuration), encode(sV4.MaxSectorBatchSize), encode(sV4.RemainingStorage), encode(sV4.TotalStorage), encode(pV4.ContractPrice), encode(pV4.Collateral), encode(pV4.StoragePrice), encode(pV4.IngressPrice), encode(pV4.EgressPrice), encode(pV4.FreeSectorPrice), encode(pV4.TipHeight), encode(pV4.ValidUntil), encode(pV4.Signature)); err != nil { + if _, err := stmt.Exec(encode(host.PublicKey), host.NetAddress, host.CountryCode, encode(host.KnownSince), encode(host.LastScan), host.LastScanSuccessful, encode(host.LastAnnouncement), host.TotalScans, host.SuccessfulInteractions, host.FailedInteractions, s.AcceptingContracts, encode(s.MaxDownloadBatchSize), encode(s.MaxDuration), encode(s.MaxReviseBatchSize), s.NetAddress, encode(s.RemainingStorage), encode(s.SectorSize), encode(s.TotalStorage), encode(s.Address), encode(s.WindowSize), encode(s.Collateral), encode(s.MaxCollateral), encode(s.BaseRPCPrice), encode(s.ContractPrice), encode(s.DownloadBandwidthPrice), encode(s.SectorAccessPrice), encode(s.StoragePrice), encode(s.UploadBandwidthPrice), s.EphemeralAccountExpiry, encode(s.MaxEphemeralAccountBalance), encode(s.RevisionNumber), s.Version, s.Release, s.SiaMuxPort, encode(p.UID), p.Validity, encode(p.HostBlockHeight), encode(p.UpdatePriceTableCost), encode(p.AccountBalanceCost), encode(p.FundAccountCost), encode(p.LatestRevisionCost), encode(p.SubscriptionMemoryCost), encode(p.SubscriptionNotificationCost), encode(p.InitBaseCost), encode(p.MemoryTimeCost), encode(p.DownloadBandwidthCost), encode(p.UploadBandwidthCost), encode(p.DropSectorsBaseCost), encode(p.DropSectorsUnitCost), encode(p.HasSectorBaseCost), encode(p.ReadBaseCost), encode(p.ReadLengthCost), encode(p.RenewContractCost), encode(p.RevisionBaseCost), encode(p.SwapSectorBaseCost), encode(p.WriteBaseCost), encode(p.WriteLengthCost), encode(p.WriteStoreCost), encode(p.TxnFeeMinRecommended), encode(p.TxnFeeMaxRecommended), encode(p.ContractPrice), encode(p.CollateralCost), encode(p.MaxCollateral), encode(p.MaxDuration), encode(p.WindowSize), encode(p.RegistryEntriesLeft), encode(p.RegistryEntriesTotal), sV4.ProtocolVersion[:], sV4.Release, encode(sV4.WalletAddress), sV4.AcceptingContracts, encode(sV4.MaxCollateral), encode(sV4.MaxContractDuration), encode(sV4.RemainingStorage), encode(sV4.TotalStorage), encode(pV4.ContractPrice), encode(pV4.Collateral), encode(pV4.StoragePrice), encode(pV4.IngressPrice), encode(pV4.EgressPrice), encode(pV4.FreeSectorPrice), encode(pV4.TipHeight), encode(pV4.ValidUntil), encode(pV4.Signature)); err != nil { return fmt.Errorf("failed to execute host_info stmt: %w", err) } @@ -1161,7 +1161,7 @@ func addHostScans(tx *txn, scans []explorer.HostScan) error { } defer unsuccessfulStmt.Close() - successfulStmt, err := tx.Prepare(`UPDATE host_info SET country_code = ?, last_scan = ?, last_scan_successful = 1, total_scans = total_scans + 1, successful_interactions = successful_interactions + 1, settings_accepting_contracts = ?, settings_max_download_batch_size = ?, settings_max_duration = ?, settings_max_revise_batch_size = ?, settings_net_address = ?, settings_remaining_storage = ?, settings_sector_size = ?, settings_total_storage = ?, settings_address = ?, settings_window_size = ?, settings_collateral = ?, settings_max_collateral = ?, settings_base_rpc_price = ?, settings_contract_price = ?, settings_download_bandwidth_price = ?, settings_sector_access_price = ?, settings_storage_price = ?, settings_upload_bandwidth_price = ?, settings_ephemeral_account_expiry = ?, settings_max_ephemeral_account_balance = ?, settings_revision_number = ?, settings_version = ?, settings_release = ?, settings_sia_mux_port = ?, price_table_uid = ?, price_table_validity = ?, price_table_host_block_height = ?, price_table_update_price_table_cost = ?, price_table_account_balance_cost = ?, price_table_fund_account_cost = ?, price_table_latest_revision_cost = ?, price_table_subscription_memory_cost = ?, price_table_subscription_notification_cost = ?, price_table_init_base_cost = ?, price_table_memory_time_cost = ?, price_table_download_bandwidth_cost = ?, price_table_upload_bandwidth_cost = ?, price_table_drop_sectors_base_cost = ?, price_table_drop_sectors_unit_cost = ?, price_table_has_sector_base_cost = ?, price_table_read_base_cost = ?, price_table_read_length_cost = ?, price_table_renew_contract_cost = ?, price_table_revision_base_cost = ?, price_table_swap_sector_base_cost = ?, price_table_write_base_cost = ?, price_table_write_length_cost = ?, price_table_write_store_cost = ?, price_table_txn_fee_min_recommended = ?, price_table_txn_fee_max_recommended = ?, price_table_contract_price = ?, price_table_collateral_cost = ?, price_table_max_collateral = ?, price_table_max_duration = ?, price_table_window_size = ?, price_table_registry_entries_left = ?, price_table_registry_entries_total = ?, rhp4_settings_protocol_version = ?, rhp4_settings_release = ?, rhp4_settings_wallet_address = ?, rhp4_settings_accepting_contracts = ?, rhp4_settings_max_collateral = ?, rhp4_settings_max_collateral_duration = ?, rhp4_settings_max_sector_duration = ?, rhp4_settings_max_sector_batch_size = ?, rhp4_settings_remaining_storage = ?, rhp4_settings_total_storage = ?, rhp4_prices_contract_price = ?, rhp4_prices_collateral_price = ?, rhp4_prices_storage_price = ?, rhp4_prices_ingress_price = ?, rhp4_prices_egress_price = ?, rhp4_prices_free_sector_price = ?, rhp4_prices_tip_height = ?, rhp4_prices_valid_until = ?, rhp4_prices_signature = ? WHERE public_key = ?`) + successfulStmt, err := tx.Prepare(`UPDATE host_info SET country_code = ?, last_scan = ?, last_scan_successful = 1, total_scans = total_scans + 1, successful_interactions = successful_interactions + 1, settings_accepting_contracts = ?, settings_max_download_batch_size = ?, settings_max_duration = ?, settings_max_revise_batch_size = ?, settings_net_address = ?, settings_remaining_storage = ?, settings_sector_size = ?, settings_total_storage = ?, settings_address = ?, settings_window_size = ?, settings_collateral = ?, settings_max_collateral = ?, settings_base_rpc_price = ?, settings_contract_price = ?, settings_download_bandwidth_price = ?, settings_sector_access_price = ?, settings_storage_price = ?, settings_upload_bandwidth_price = ?, settings_ephemeral_account_expiry = ?, settings_max_ephemeral_account_balance = ?, settings_revision_number = ?, settings_version = ?, settings_release = ?, settings_sia_mux_port = ?, price_table_uid = ?, price_table_validity = ?, price_table_host_block_height = ?, price_table_update_price_table_cost = ?, price_table_account_balance_cost = ?, price_table_fund_account_cost = ?, price_table_latest_revision_cost = ?, price_table_subscription_memory_cost = ?, price_table_subscription_notification_cost = ?, price_table_init_base_cost = ?, price_table_memory_time_cost = ?, price_table_download_bandwidth_cost = ?, price_table_upload_bandwidth_cost = ?, price_table_drop_sectors_base_cost = ?, price_table_drop_sectors_unit_cost = ?, price_table_has_sector_base_cost = ?, price_table_read_base_cost = ?, price_table_read_length_cost = ?, price_table_renew_contract_cost = ?, price_table_revision_base_cost = ?, price_table_swap_sector_base_cost = ?, price_table_write_base_cost = ?, price_table_write_length_cost = ?, price_table_write_store_cost = ?, price_table_txn_fee_min_recommended = ?, price_table_txn_fee_max_recommended = ?, price_table_contract_price = ?, price_table_collateral_cost = ?, price_table_max_collateral = ?, price_table_max_duration = ?, price_table_window_size = ?, price_table_registry_entries_left = ?, price_table_registry_entries_total = ?, rhp4_settings_protocol_version = ?, rhp4_settings_release = ?, rhp4_settings_wallet_address = ?, rhp4_settings_accepting_contracts = ?, rhp4_settings_max_collateral = ?, rhp4_settings_max_contract_duration = ?, rhp4_settings_remaining_storage = ?, rhp4_settings_total_storage = ?, rhp4_prices_contract_price = ?, rhp4_prices_collateral_price = ?, rhp4_prices_storage_price = ?, rhp4_prices_ingress_price = ?, rhp4_prices_egress_price = ?, rhp4_prices_free_sector_price = ?, rhp4_prices_tip_height = ?, rhp4_prices_valid_until = ?, rhp4_prices_signature = ? WHERE public_key = ?`) if err != nil { return fmt.Errorf("addHostScans: failed to prepare successful statement: %w", err) } @@ -1171,7 +1171,7 @@ func addHostScans(tx *txn, scans []explorer.HostScan) error { s, p := scan.Settings, scan.PriceTable sV4, pV4 := scan.RHPV4Settings, scan.RHPV4Settings.Prices if scan.Success { - if _, err := successfulStmt.Exec(scan.CountryCode, encode(scan.Timestamp), s.AcceptingContracts, encode(s.MaxDownloadBatchSize), encode(s.MaxDuration), encode(s.MaxReviseBatchSize), s.NetAddress, encode(s.RemainingStorage), encode(s.SectorSize), encode(s.TotalStorage), encode(s.Address), encode(s.WindowSize), encode(s.Collateral), encode(s.MaxCollateral), encode(s.BaseRPCPrice), encode(s.ContractPrice), encode(s.DownloadBandwidthPrice), encode(s.SectorAccessPrice), encode(s.StoragePrice), encode(s.UploadBandwidthPrice), s.EphemeralAccountExpiry, encode(s.MaxEphemeralAccountBalance), encode(s.RevisionNumber), s.Version, s.Release, s.SiaMuxPort, encode(p.UID), p.Validity, encode(p.HostBlockHeight), encode(p.UpdatePriceTableCost), encode(p.AccountBalanceCost), encode(p.FundAccountCost), encode(p.LatestRevisionCost), encode(p.SubscriptionMemoryCost), encode(p.SubscriptionNotificationCost), encode(p.InitBaseCost), encode(p.MemoryTimeCost), encode(p.DownloadBandwidthCost), encode(p.UploadBandwidthCost), encode(p.DropSectorsBaseCost), encode(p.DropSectorsUnitCost), encode(p.HasSectorBaseCost), encode(p.ReadBaseCost), encode(p.ReadLengthCost), encode(p.RenewContractCost), encode(p.RevisionBaseCost), encode(p.SwapSectorBaseCost), encode(p.WriteBaseCost), encode(p.WriteLengthCost), encode(p.WriteStoreCost), encode(p.TxnFeeMinRecommended), encode(p.TxnFeeMaxRecommended), encode(p.ContractPrice), encode(p.CollateralCost), encode(p.MaxCollateral), encode(p.MaxDuration), encode(p.WindowSize), encode(p.RegistryEntriesLeft), encode(p.RegistryEntriesTotal), sV4.ProtocolVersion[:], sV4.Release, encode(sV4.WalletAddress), sV4.AcceptingContracts, encode(sV4.MaxCollateral), encode(sV4.MaxContractDuration), encode(sV4.MaxSectorDuration), encode(sV4.MaxSectorBatchSize), encode(sV4.RemainingStorage), encode(sV4.TotalStorage), encode(pV4.ContractPrice), encode(pV4.Collateral), encode(pV4.StoragePrice), encode(pV4.IngressPrice), encode(pV4.EgressPrice), encode(pV4.FreeSectorPrice), encode(pV4.TipHeight), encode(pV4.ValidUntil), encode(pV4.Signature), encode(scan.PublicKey)); err != nil { + if _, err := successfulStmt.Exec(scan.CountryCode, encode(scan.Timestamp), s.AcceptingContracts, encode(s.MaxDownloadBatchSize), encode(s.MaxDuration), encode(s.MaxReviseBatchSize), s.NetAddress, encode(s.RemainingStorage), encode(s.SectorSize), encode(s.TotalStorage), encode(s.Address), encode(s.WindowSize), encode(s.Collateral), encode(s.MaxCollateral), encode(s.BaseRPCPrice), encode(s.ContractPrice), encode(s.DownloadBandwidthPrice), encode(s.SectorAccessPrice), encode(s.StoragePrice), encode(s.UploadBandwidthPrice), s.EphemeralAccountExpiry, encode(s.MaxEphemeralAccountBalance), encode(s.RevisionNumber), s.Version, s.Release, s.SiaMuxPort, encode(p.UID), p.Validity, encode(p.HostBlockHeight), encode(p.UpdatePriceTableCost), encode(p.AccountBalanceCost), encode(p.FundAccountCost), encode(p.LatestRevisionCost), encode(p.SubscriptionMemoryCost), encode(p.SubscriptionNotificationCost), encode(p.InitBaseCost), encode(p.MemoryTimeCost), encode(p.DownloadBandwidthCost), encode(p.UploadBandwidthCost), encode(p.DropSectorsBaseCost), encode(p.DropSectorsUnitCost), encode(p.HasSectorBaseCost), encode(p.ReadBaseCost), encode(p.ReadLengthCost), encode(p.RenewContractCost), encode(p.RevisionBaseCost), encode(p.SwapSectorBaseCost), encode(p.WriteBaseCost), encode(p.WriteLengthCost), encode(p.WriteStoreCost), encode(p.TxnFeeMinRecommended), encode(p.TxnFeeMaxRecommended), encode(p.ContractPrice), encode(p.CollateralCost), encode(p.MaxCollateral), encode(p.MaxDuration), encode(p.WindowSize), encode(p.RegistryEntriesLeft), encode(p.RegistryEntriesTotal), sV4.ProtocolVersion[:], sV4.Release, encode(sV4.WalletAddress), sV4.AcceptingContracts, encode(sV4.MaxCollateral), encode(sV4.MaxContractDuration), encode(sV4.RemainingStorage), encode(sV4.TotalStorage), encode(pV4.ContractPrice), encode(pV4.Collateral), encode(pV4.StoragePrice), encode(pV4.IngressPrice), encode(pV4.EgressPrice), encode(pV4.FreeSectorPrice), encode(pV4.TipHeight), encode(pV4.ValidUntil), encode(pV4.Signature), encode(scan.PublicKey)); err != nil { return fmt.Errorf("addHostScans: failed to execute successful statement: %w", err) } } else { diff --git a/persist/sqlite/init.sql b/persist/sqlite/init.sql index f359c23..f9675b6 100644 --- a/persist/sqlite/init.sql +++ b/persist/sqlite/init.sql @@ -21,7 +21,7 @@ CREATE TABLE network_metrics ( height INTEGER NOT NULL, difficulty BLOB NOT NULL, - siafund_pool BLOB NOT NULL, + siafund_tax_revenue BLOB NOT NULL, num_leaves BLOB NOT NULL, total_hosts INTEGER NOT NULL, active_contracts INTEGER NOT NULL, @@ -335,12 +335,15 @@ CREATE TABLE v2_transaction_file_contract_resolutions ( transaction_order INTEGER NOT NULL, parent_contract_id INTEGER REFERENCES v2_file_contract_elements(id) ON DELETE CASCADE NOT NULL, -- add an index to all foreign keys - -- V2FileContractRenewal = 0, V2StorageProof = 1, V2FileContractFinalization = 2, V2FileContractExpiration = 3 + -- V2FileContractRenewal = 0, V2StorageProof = 1, V2FileContractExpiration = 2 resolution_type INTEGER NOT NULL, -- V2FileContractRenewal - renewal_final_revision_contract_id INTEGER REFERENCES v2_file_contract_elements(id) ON DELETE CASCADE, renewal_new_contract_id INTEGER REFERENCES v2_file_contract_elements(id) ON DELETE CASCADE, + renewal_final_renter_output_address BLOB, + renewal_final_renter_output_value BLOB, + renewal_final_host_output_address BLOB, + renewal_final_host_output_value BLOB, renewal_renter_rollover BLOB, renewal_host_rollover BLOB, renewal_renter_signature BLOB, @@ -351,9 +354,6 @@ CREATE TABLE v2_transaction_file_contract_resolutions ( storage_proof_leaf BLOB, storage_proof_proof BLOB, - -- V2FileContractFinalization - finalization_signature BLOB, - -- V2FileContractExpiration -- no fields @@ -546,9 +546,7 @@ CREATE TABLE host_info ( rhp4_settings_wallet_address BLOB NOT NULL, rhp4_settings_accepting_contracts INTEGER NOT NULL, rhp4_settings_max_collateral BLOB NOT NULL, - rhp4_settings_max_collateral_duration BLOB NOT NULL, - rhp4_settings_max_sector_duration BLOB NOT NULL, - rhp4_settings_max_sector_batch_size BLOB NOT NULL, + rhp4_settings_max_contract_duration BLOB NOT NULL, rhp4_settings_remaining_storage BLOB NOT NULL, rhp4_settings_total_storage BLOB NOT NULL, -- rhp4 prices diff --git a/persist/sqlite/metrics.go b/persist/sqlite/metrics.go index 6258e54..48074f6 100644 --- a/persist/sqlite/metrics.go +++ b/persist/sqlite/metrics.go @@ -11,7 +11,7 @@ import ( // Metrics implements explorer.Store func (s *Store) Metrics(id types.BlockID) (result explorer.Metrics, err error) { err = s.transaction(func(tx *txn) error { - err = tx.QueryRow(`SELECT block_id, height, difficulty, siafund_pool, num_leaves, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue FROM network_metrics WHERE block_id = ?`, encode(id)).Scan(decode(&result.Index.ID), &result.Index.Height, decode(&result.Difficulty), decode(&result.SiafundPool), decode(&result.NumLeaves), &result.TotalHosts, &result.ActiveContracts, &result.FailedContracts, &result.SuccessfulContracts, &result.StorageUtilization, decode(&result.CirculatingSupply), decode(&result.ContractRevenue)) + err = tx.QueryRow(`SELECT block_id, height, difficulty, siafund_tax_revenue, num_leaves, total_hosts, active_contracts, failed_contracts, successful_contracts, storage_utilization, circulating_supply, contract_revenue FROM network_metrics WHERE block_id = ?`, encode(id)).Scan(decode(&result.Index.ID), &result.Index.Height, decode(&result.Difficulty), decode(&result.SiafundTaxRevenue), decode(&result.NumLeaves), &result.TotalHosts, &result.ActiveContracts, &result.FailedContracts, &result.SuccessfulContracts, &result.StorageUtilization, decode(&result.CirculatingSupply), decode(&result.ContractRevenue)) if err != nil { return fmt.Errorf("failed to get metrics: %w", err) } diff --git a/persist/sqlite/scan_test.go b/persist/sqlite/scan_test.go index 64c8cab..f7b6971 100644 --- a/persist/sqlite/scan_test.go +++ b/persist/sqlite/scan_test.go @@ -119,8 +119,6 @@ func TestScan(t *testing.T) { WalletAddress: w.Address(), MaxCollateral: types.Siacoins(10000), MaxContractDuration: 1000, - MaxSectorDuration: 3 * 144, - MaxSectorBatchSize: 100, RemainingStorage: 100 * proto4.SectorSize, TotalStorage: 100 * proto4.SectorSize, Prices: proto4.HostPrices{ diff --git a/persist/sqlite/v2consensus.go b/persist/sqlite/v2consensus.go index d6d8413..9121ff2 100644 --- a/persist/sqlite/v2consensus.go +++ b/persist/sqlite/v2consensus.go @@ -107,10 +107,6 @@ func updateV2FileContractElements(tx *txn, revert bool, index types.ChainIndex, } for _, fcr := range txn.FileContractResolutions { if v, ok := fcr.Resolution.(*types.V2FileContractRenewal); ok { - fcTxns[explorer.DBFileContract{ - ID: types.FileContractID(fcr.Parent.ID), - RevisionNumber: v.FinalRevision.RevisionNumber, - }] = id fcTxns[explorer.DBFileContract{ ID: types.FileContractID(fcr.Parent.ID).V2RenewalID(), RevisionNumber: v.NewContract.RevisionNumber, @@ -219,20 +215,9 @@ func updateV2FileContractElements(tx *txn, revert bool, index types.ChainIndex, return nil, fmt.Errorf("updateV2FileContractElements: %w", err) } } - // Add the final revision and new renewal contracts + // Add the new renewal contracts for _, fcr := range txn.FileContractResolutions { if v, ok := fcr.Resolution.(*types.V2FileContractRenewal); ok { - { - fc := v.FinalRevision - fcID := types.FileContractID(fcr.Parent.ID) - - // Add final revision, because the ApplyUpdate doesn't tell - // us about this case. We set lastRevision to true here - // because this is the final revision. - if err := addFC(fcID, fcr.Parent.StateElement.LeafIndex, fc, nil, true); err != nil { - return nil, fmt.Errorf("updateV2FileContractElements: failed to add final revision: %w", err) - } - } { // Add NewContract if we have not seen it already. // Only way this could happen is if the renewal is revised @@ -444,7 +429,7 @@ func addV2FileContractRevisions(tx *txn, txnID int64, txn types.V2Transaction, d } func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, dbIDs map[explorer.DBFileContract]int64) error { - renewalStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type, renewal_final_revision_contract_id, renewal_new_contract_id, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) + renewalStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type, renewal_new_contract_id, renewal_final_renter_output_address, renewal_final_renter_output_value, renewal_final_host_output_address, renewal_final_host_output_value, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) if err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to prepare renewal statement: %w", err) } @@ -456,12 +441,6 @@ func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, } defer storageProofStmt.Close() - finalizationStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type, finalization_signature) VALUES (?, ?, ?, ?, ?)`) - if err != nil { - return fmt.Errorf("addV2FileContractResolutions: failed to prepare finalization statement: %w", err) - } - defer finalizationStmt.Close() - expirationStmt, err := tx.Prepare(`INSERT INTO v2_transaction_file_contract_resolutions(transaction_id, transaction_order, parent_contract_id, resolution_type) VALUES (?, ?, ?, ?)`) if err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to prepare expiration statement: %w", err) @@ -479,14 +458,6 @@ func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, switch v := fcr.Resolution.(type) { case *types.V2FileContractRenewal: - finalDBID, ok := dbIDs[explorer.DBFileContract{ - ID: types.FileContractID(fcr.Parent.ID), - RevisionNumber: v.FinalRevision.RevisionNumber, - }] - if !ok { - return errors.New("addV2FileContractResolutions: final dbID not in map") - } - newDBID, ok := dbIDs[explorer.DBFileContract{ ID: types.FileContractID(fcr.Parent.ID).V2RenewalID(), RevisionNumber: v.NewContract.RevisionNumber, @@ -495,19 +466,15 @@ func addV2FileContractResolutions(tx *txn, txnID int64, txn types.V2Transaction, return errors.New("addV2FileContractResolutions: renewal dbID not in map") } - if _, err := renewalStmt.Exec(txnID, i, parentDBID, 0, finalDBID, newDBID, encode(v.RenterRollover), encode(v.HostRollover), encode(v.RenterSignature), encode(v.HostSignature)); err != nil { + if _, err := renewalStmt.Exec(txnID, i, parentDBID, 0, newDBID, encode(v.FinalRenterOutput.Address), encode(v.FinalRenterOutput.Value), encode(v.FinalHostOutput.Address), encode(v.FinalHostOutput.Value), encode(v.RenterRollover), encode(v.HostRollover), encode(v.RenterSignature), encode(v.HostSignature)); err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to execute renewal statement: %w", err) } case *types.V2StorageProof: if _, err := storageProofStmt.Exec(txnID, i, parentDBID, 1, encode(v.ProofIndex), v.Leaf[:], encode(v.Proof)); err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to execute storage proof statement: %w", err) } - case *types.V2FileContractFinalization: - if _, err := finalizationStmt.Exec(txnID, i, parentDBID, 2, encode(v)); err != nil { - return fmt.Errorf("addV2FileContractResolutions: failed to execute finalization statement: %w", err) - } case *types.V2FileContractExpiration: - if _, err := expirationStmt.Exec(txnID, i, parentDBID, 3); err != nil { + if _, err := expirationStmt.Exec(txnID, i, parentDBID, 2); err != nil { return fmt.Errorf("addV2FileContractResolutions: failed to execute expiration statement: %w", err) } } diff --git a/persist/sqlite/v2consensus_test.go b/persist/sqlite/v2consensus_test.go index c7a973b..24a883e 100644 --- a/persist/sqlite/v2consensus_test.go +++ b/persist/sqlite/v2consensus_test.go @@ -214,6 +214,7 @@ func TestV2FoundationAddress(t *testing.T) { _, genesisBlock, cm, db := newStore(t, true, func(network *consensus.Network, genesisBlock types.Block) { network.HardforkV2.AllowHeight = 1 network.HardforkV2.RequireHeight = 2 + network.HardforkFoundation.FailsafeAddress = addr1 network.HardforkFoundation.PrimaryAddress = addr1 genesisBlock.Transactions[0].SiacoinOutputs[0].Address = addr1 }) @@ -1054,10 +1055,11 @@ func TestV2FileContractResolution(t *testing.T) { v2FCNewContract := v2FC v2FCNewContract.RevisionNumber = 10 renewal := &types.V2FileContractRenewal{ - FinalRevision: v2FCFinalRevision, - NewContract: v2FCNewContract, - RenterRollover: types.ZeroCurrency, - HostRollover: types.ZeroCurrency, + NewContract: v2FCNewContract, + FinalRenterOutput: v2FCFinalRevision.RenterOutput, + FinalHostOutput: v2FCFinalRevision.HostOutput, + RenterRollover: types.ZeroCurrency, + HostRollover: types.ZeroCurrency, } sce1 := getSCE(t, db, txn1.SiacoinOutputID(txn1.ID(), 0)) txn2 := types.V2Transaction{ @@ -1070,10 +1072,6 @@ func TestV2FileContractResolution(t *testing.T) { Value: sce1.SiacoinOutput.Value.Sub(fcOut), }}, FileContractResolutions: []types.V2FileContractResolution{ - { - Parent: getFCE(t, db, v2FC0ID), - Resolution: new(types.V2FileContractFinalization), - }, { Parent: getFCE(t, db, v2FC1ID), Resolution: renewal, @@ -1098,11 +1096,6 @@ func TestV2FileContractResolution(t *testing.T) { testutil.Equal(t, "confirmation transaction ID", txn1.ID(), dbTxns[0].FileContractResolutions[0].Parent.ConfirmationTransactionID) testutil.Equal(t, "resolution index", cm.Tip(), *dbTxns[0].FileContractResolutions[0].Parent.ResolutionIndex) testutil.Equal(t, "resolution transaction ID", txn2.ID(), *dbTxns[0].FileContractResolutions[0].Parent.ResolutionTransactionID) - - testutil.Equal(t, "confirmation index", tip1, dbTxns[0].FileContractResolutions[1].Parent.ConfirmationIndex) - testutil.Equal(t, "confirmation transaction ID", txn1.ID(), dbTxns[0].FileContractResolutions[1].Parent.ConfirmationTransactionID) - testutil.Equal(t, "resolution index", cm.Tip(), *dbTxns[0].FileContractResolutions[1].Parent.ResolutionIndex) - testutil.Equal(t, "resolution transaction ID", txn2.ID(), *dbTxns[0].FileContractResolutions[1].Parent.ResolutionTransactionID) } b2 := testutil.MineV2Block(cm.TipState(), nil, types.VoidAddress) @@ -1205,32 +1198,6 @@ func TestV2FileContractResolution(t *testing.T) { testutil.CheckV2FC(t, txn1.FileContracts[3], fcs[3]) } - sce1 = getSCE(t, db, txn1.SiacoinOutputID(txn1.ID(), 0)) - // renewal is not possible because proof window has opened at this point - txn2.SiacoinInputs = nil - txn2.SiacoinOutputs = nil - txn2.FileContractResolutions = txn2.FileContractResolutions[:1] - txn2.FileContractResolutions[0].Parent = getFCE(t, db, v2FC0ID) - // txn2.FileContractResolutions[1].Parent = getFCE(t, db, v2FC1ID) - testutil.SignV2TransactionWithContracts(cm.TipState(), pk1, renterPrivateKey, hostPrivateKey, &txn2) - - if err := cm.AddBlocks([]types.Block{testutil.MineV2Block(cm.TipState(), []types.V2Transaction{txn2}, types.VoidAddress)}); err != nil { - t.Fatal(err) - } - syncDB(t, db, cm) - - { - dbTxns, err := db.V2Transactions([]types.TransactionID{txn2.ID()}) - if err != nil { - t.Fatal(err) - } - testutil.CheckV2Transaction(t, txn2, dbTxns[0]) - testutil.Equal(t, "confirmation index", tip1, dbTxns[0].FileContractResolutions[0].Parent.ConfirmationIndex) - testutil.Equal(t, "confirmation transaction ID", txn1.ID(), dbTxns[0].FileContractResolutions[0].Parent.ConfirmationTransactionID) - testutil.Equal(t, "resolution index", cm.Tip(), *dbTxns[0].FileContractResolutions[0].Parent.ResolutionIndex) - testutil.Equal(t, "resolution transaction ID", txn2.ID(), *dbTxns[0].FileContractResolutions[0].Parent.ResolutionTransactionID) - } - tip, err := db.BestTip(v2FC3.ProofHeight) if err != nil { t.Fatal(err) diff --git a/persist/sqlite/v2transactions.go b/persist/sqlite/v2transactions.go index 59f18a3..d799fa5 100644 --- a/persist/sqlite/v2transactions.go +++ b/persist/sqlite/v2transactions.go @@ -433,11 +433,12 @@ func fillV2TransactionFileContractResolutions(tx *txn, dbIDs []int64, txns []exp consolidatedStmt, err := tx.Prepare(` SELECT parent_contract_id, resolution_type, - renewal_final_revision_contract_id, renewal_new_contract_id, + renewal_new_contract_id, + renewal_final_renter_output_address, renewal_final_renter_output_value, + renewal_final_host_output_address, renewal_final_host_output_value, renewal_renter_rollover, renewal_host_rollover, renewal_renter_signature, renewal_host_signature, - storage_proof_proof_index, storage_proof_leaf, storage_proof_proof, - finalization_signature + storage_proof_proof_index, storage_proof_leaf, storage_proof_proof FROM v2_transaction_file_contract_resolutions WHERE transaction_id = ? ORDER BY transaction_order @@ -469,25 +470,24 @@ WHERE fc.id = ?`) // all var parentContractID, resolutionType int64 // renewal - var renewalFinalRevisionID, renewalNewContractID sql.NullInt64 + var renewalNewContractID sql.NullInt64 + var finalRenterOutput, finalHostOutput types.SiacoinOutput var renewalRenterRollover, renewalHostRollover types.Currency var renewalRenterSignature, renewalHostSignature types.Signature // storage proof var storageProofProofIndex types.ChainIndexElement var storageProofProof []types.Hash256 var storageProofLeaf []byte - // finalization - var finalizationSignature types.Signature // Scan all fields, some of which may be NULL if err := rows.Scan( &parentContractID, &resolutionType, - &renewalFinalRevisionID, &renewalNewContractID, + &renewalNewContractID, + decodeNull(&finalRenterOutput.Address), decodeNull(&finalRenterOutput.Value), + decodeNull(&finalHostOutput.Address), decodeNull(&finalHostOutput.Value), decodeNull(&renewalRenterRollover), decodeNull(&renewalHostRollover), decodeNull(&renewalRenterSignature), decodeNull(&renewalHostSignature), - decodeNull(&storageProofProofIndex), &storageProofLeaf, decodeNull(&storageProofProof), - decodeNull(&finalizationSignature), - ); err != nil { + decodeNull(&storageProofProofIndex), &storageProofLeaf, decodeNull(&storageProofProof)); err != nil { return fmt.Errorf("failed to scan resolution metadata: %w", err) } @@ -503,16 +503,12 @@ WHERE fc.id = ?`) switch resolutionType { case 0: // V2FileContractRenewal renewal := &explorer.V2FileContractRenewal{ - RenterRollover: renewalRenterRollover, - HostRollover: renewalHostRollover, - RenterSignature: renewalRenterSignature, - HostSignature: renewalHostSignature, - } - if renewalFinalRevisionID.Valid { - renewal.FinalRevision, err = scanV2FileContract(fcStmt.QueryRow(renewalFinalRevisionID.Int64)) - if err != nil { - return fmt.Errorf("failed to scan final revision: %w", err) - } + FinalRenterOutput: finalRenterOutput, + FinalHostOutput: finalHostOutput, + RenterRollover: renewalRenterRollover, + HostRollover: renewalHostRollover, + RenterSignature: renewalRenterSignature, + HostSignature: renewalHostSignature, } if renewalNewContractID.Valid { renewal.NewContract, err = scanV2FileContract(fcStmt.QueryRow(renewalNewContractID.Int64)) @@ -532,10 +528,7 @@ WHERE fc.id = ?`) fcr.Type = "storageProof" fcr.Resolution = proof - case 2: // V2FileContractFinalization - fcr.Type = "finalization" - fcr.Resolution = (*types.V2FileContractFinalization)(&finalizationSignature) - case 3: // V2FileContractExpiration + case 2: // V2FileContractExpiration fcr.Type = "expiration" fcr.Resolution = new(types.V2FileContractExpiration) }