From f15fb124f7dab396c8b0410b5b8bd10e4a22ccce Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 3 Dec 2024 18:03:02 -0800 Subject: [PATCH] chore: update core --- api/mine.go | 15 +---- api/server.go | 16 +---- go.mod | 4 +- go.sum | 8 +-- wallet/wallet.go | 2 +- wallet/wallet_test.go | 133 +++--------------------------------------- 6 files changed, 20 insertions(+), 158 deletions(-) diff --git a/api/mine.go b/api/mine.go index 9666d0c..d2b6bd1 100644 --- a/api/mine.go +++ b/api/mine.go @@ -2,7 +2,6 @@ package api import ( "context" - "encoding/binary" "errors" "go.sia.tech/core/types" @@ -50,19 +49,8 @@ func mineBlock(ctx context.Context, cm ChainManager, addr types.Address) (types. } b.Nonce = 0 - buf := make([]byte, 32+8+8+32) - binary.LittleEndian.PutUint64(buf[32:], b.Nonce) - binary.LittleEndian.PutUint64(buf[40:], uint64(b.Timestamp.Unix())) - if b.V2 != nil { - copy(buf[:32], "sia/id/block|") - copy(buf[48:], b.V2.Commitment[:]) - } else { - root := b.MerkleRoot() - copy(buf[:32], b.ParentID[:]) - copy(buf[48:], root[:]) - } factor := cs.NonceFactor() - for types.BlockID(types.HashBytes(buf)).CmpWork(cs.ChildTarget) < 0 { + for b.ID().CmpWork(cs.ChildTarget) < 0 { select { case <-ctx.Done(): return types.Block{}, ctx.Err() @@ -75,7 +63,6 @@ func mineBlock(ctx context.Context, cm ChainManager, addr types.Address) (types. } b.Nonce += factor - binary.LittleEndian.PutUint64(buf[32:], b.Nonce) } return b, nil } diff --git a/api/server.go b/api/server.go index 7549ce5..4da2206 100644 --- a/api/server.go +++ b/api/server.go @@ -79,7 +79,7 @@ type ( Peers() []*syncer.Peer PeerInfo(addr string) (syncer.PeerInfo, error) Connect(ctx context.Context, addr string) (*syncer.Peer, error) - BroadcastHeader(bh gateway.BlockHeader) + BroadcastHeader(types.BlockHeader) BroadcastTransactionSet(txns []types.Transaction) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction) BroadcastV2BlockOutline(bo gateway.V2BlockOutline) @@ -258,12 +258,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())) } @@ -889,12 +884,7 @@ func (s *server) debugMineHandler(jc jape.Context) { } 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/go.mod b/go.mod index 3d33afb..a64e890 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ toolchain go1.23.2 require ( 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.20241203090808-c6a988d759d6 + go.sia.tech/coreutils v0.7.1-0.20241203172514-7bf95dd18f31 go.sia.tech/jape v0.12.1 go.sia.tech/web/walletd v0.24.0 go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index 6fbf308..a9e0008 100644 --- a/go.sum +++ b/go.sum @@ -10,10 +10,10 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.etcd.io/bbolt v1.3.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/coreutils v0.7.0 h1:YpgOUD4vrpDz0KC7FJz+UCOaKaqV5EkX3gMUUmJoz5s= -go.sia.tech/coreutils v0.7.0/go.mod h1:eMoqzqO4opKQ6n9tTTxHQmccfNlj+8RFOYuDSL/Qd4g= +go.sia.tech/core v0.7.1-0.20241203090808-c6a988d759d6 h1:52hztNcOJ+eql7dHMBl+g9VL4Lxr87cUrR9cXrYOkMs= +go.sia.tech/core v0.7.1-0.20241203090808-c6a988d759d6/go.mod h1:4v+aT/33857tMfqa5j5OYlAoLsoIrd4d7qMlgeP+VGk= +go.sia.tech/coreutils v0.7.1-0.20241203172514-7bf95dd18f31 h1:Qskaf8d6oDKG5emNvGHZsd9iZRqz2GeouVNKY5paXlE= +go.sia.tech/coreutils v0.7.1-0.20241203172514-7bf95dd18f31/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/wallet/wallet.go b/wallet/wallet.go index 93bc107..762d744 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -380,7 +380,7 @@ func AppliedEvents(cs consensus.State, b types.Block, cu ChainUpdate, relevant f } // handle foundation subsidy - if relevant(cs.FoundationPrimaryAddress) { + if relevant(cs.FoundationManagementAddress) { element, ok := sces[cs.Index.ID.FoundationOutputID()] if ok { addEvent(types.Hash256(element.ID), element.MaturityHeight, EventTypeFoundationSubsidy, wallet.EventPayout{ diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index dab8c1f..bdd6406 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "fmt" - "math" "math/bits" "path/filepath" "reflect" @@ -3419,14 +3418,10 @@ func TestEventTypes(t *testing.T) { cau.UpdateElementProof(&fce.StateElement) } - // finalize the contract - finalRevision := fce.V2FileContract - finalRevision.RevisionNumber = math.MaxUint64 - finalRevision.RenterSignature = types.Signature{} - finalRevision.HostSignature = types.Signature{} // create a renewal renewal := types.V2FileContractRenewal{ - FinalRevision: finalRevision, + FinalHostOutput: fc.HostOutput, + FinalRenterOutput: fc.RenterOutput, NewContract: types.V2FileContract{ RenterOutput: fc.RenterOutput, ProofHeight: fc.ProofHeight + 10, @@ -3441,12 +3436,15 @@ func TestEventTypes(t *testing.T) { renewalSig := pk.SignHash(renewalSigHash) renewal.RenterSignature = renewalSig renewal.HostSignature = renewalSig + contractSigHash := cm.TipState().ContractSigHash(renewal.NewContract) + renewal.NewContract.RenterSignature = pk.SignHash(contractSigHash) + renewal.NewContract.HostSignature = pk.SignHash(contractSigHash) sces = spendableSiacoinUTXOs() newContractValue := renterPayout.Add(cm.TipState().V2FileContractTax(renewal.NewContract)) - // renewals can't have change outputs - setupTxn := types.V2Transaction{ + // create the renewal transaction + resolutionTxn := types.V2Transaction{ SiacoinInputs: []types.V2SiacoinInput{ { Parent: sces[0], @@ -3456,23 +3454,8 @@ func TestEventTypes(t *testing.T) { }, }, SiacoinOutputs: []types.SiacoinOutput{ - {Address: addr, Value: newContractValue}, {Address: addr, Value: sces[0].SiacoinOutput.Value.Sub(newContractValue)}, }, - } - setupSigHash := cm.TipState().InputSigHash(setupTxn) - setupTxn.SiacoinInputs[0].SatisfiedPolicy.Signatures = []types.Signature{pk.SignHash(setupSigHash)} - - // create the renewal transaction - resolutionTxn := types.V2Transaction{ - SiacoinInputs: []types.V2SiacoinInput{ - { - Parent: setupTxn.EphemeralSiacoinOutput(0), - SatisfiedPolicy: types.SatisfiedPolicy{ - Policy: policy, - }, - }, - }, FileContractResolutions: []types.V2FileContractResolution{ { Parent: fce, @@ -3484,105 +3467,7 @@ func TestEventTypes(t *testing.T) { resolutionTxn.SiacoinInputs[0].SatisfiedPolicy.Signatures = []types.Signature{pk.SignHash(resolutionTxnSigHash)} // broadcast the renewal - if _, err := cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{setupTxn, resolutionTxn}); err != nil { - t.Fatal(err) - } - mineBlock(1, types.VoidAddress) - assertEvent(t, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+144) - }) - - t.Run("v2 contract resolution - finalization", func(t *testing.T) { - sces := spendableSiacoinUTXOs() - - // using the UnlockConditions policy for brevity - policy := types.SpendPolicy{ - Type: types.PolicyTypeUnlockConditions(types.StandardUnlockConditions(pk.PublicKey())), - } - - // create a storage contract - renterPayout := types.Siacoins(10000) - fc := types.V2FileContract{ - RenterOutput: types.SiacoinOutput{ - Address: addr, - Value: renterPayout, - }, - HostOutput: types.SiacoinOutput{ - Address: types.VoidAddress, - Value: types.ZeroCurrency, - }, - ProofHeight: cm.TipState().Index.Height + 10, - ExpirationHeight: cm.TipState().Index.Height + 20, - - RenterPublicKey: pk.PublicKey(), - HostPublicKey: pk.PublicKey(), - } - contractValue := renterPayout.Add(cm.TipState().V2FileContractTax(fc)) - sigHash := cm.TipState().ContractSigHash(fc) - sig := pk.SignHash(sigHash) - fc.RenterSignature = sig - fc.HostSignature = sig - - // create a transaction with the contract - txn := types.V2Transaction{ - FileContracts: []types.V2FileContract{fc}, - SiacoinInputs: []types.V2SiacoinInput{ - { - Parent: sces[0], - SatisfiedPolicy: types.SatisfiedPolicy{ - Policy: policy, - }, - }, - }, - SiacoinOutputs: []types.SiacoinOutput{ - {Address: addr, Value: sces[0].SiacoinOutput.Value.Sub(contractValue)}, - }, - } - sigHash = cm.TipState().InputSigHash(txn) - txn.SiacoinInputs[0].SatisfiedPolicy.Signatures = []types.Signature{pk.SignHash(sigHash)} - - // broadcast the transaction - if _, err := cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{txn}); err != nil { - t.Fatal(err) - } - // current tip - tip := cm.Tip() - // mine until the contract proof window - mineBlock(1, types.VoidAddress) - - // this is even more annoying because we have to keep the file contract - // proof and the chain index proof up to date. - _, applied, err := cm.UpdatesSince(tip, 1000) - if err != nil { - t.Fatal(err) - } - - // get the confirmed file contract element - var fce types.V2FileContractElement - applied[0].ForEachV2FileContractElement(func(ele types.V2FileContractElement, _ bool, _ *types.V2FileContractElement, _ types.V2FileContractResolutionType) { - fce = ele - }) - for _, cau := range applied { - cau.UpdateElementProof(&fce.StateElement) - } - - // finalize the contract - fc = fce.V2FileContract - fc.RevisionNumber = types.MaxRevisionNumber - finalizationSigHash := cm.TipState().ContractSigHash(fc) - finalization := types.V2FileContractFinalization(pk.SignHash(finalizationSigHash)) - - // create the resolution transaction - finalizationTxn := types.V2Transaction{ - FileContractResolutions: []types.V2FileContractResolution{ - { - Parent: fce, - Resolution: &finalization, - }, - }, - } - - // broadcast the resolution - if _, err := cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{finalizationTxn}); err != nil { + if _, err := cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{resolutionTxn}); err != nil { t.Fatal(err) } mineBlock(1, types.VoidAddress) @@ -3616,7 +3501,7 @@ func TestEventTypes(t *testing.T) { } sigHash := cm.TipState().InputSigHash(txn) txn.SiafundInputs[0].SatisfiedPolicy.Signatures = []types.Signature{pk.SignHash(sigHash)} - claimValue := cm.TipState().SiafundPool + claimValue := cm.TipState().SiafundTaxRevenue // broadcast the transaction if _, err := cm.AddV2PoolTransactions(cm.Tip(), []types.V2Transaction{txn}); err != nil {