Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update core #198

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions api/mine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"encoding/binary"
"errors"

"go.sia.tech/core/types"
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
16 changes: 3 additions & 13 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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()))
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ toolchain go1.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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
133 changes: 9 additions & 124 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"math/bits"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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,
Expand All @@ -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],
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading