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

Update core #126

Merged
merged 3 commits into from
Dec 3, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
.vscode
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.2

require (
go.etcd.io/bbolt v1.3.11
go.sia.tech/core v0.6.2
go.sia.tech/core v0.7.1-0.20241203043244-c435a355b1da
go.sia.tech/mux v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.29.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ 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.1 h1:eaExM2E2eNr43su2XDkY5J24E3F54YGS7hcC3WtVjVk=
go.sia.tech/core v0.6.1/go.mod h1:P3C1BWa/7J4XgdzWuaYHBvLo2RzZ0UBaJM4TG1GWB2g=
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.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/mux v1.3.0 h1:hgR34IEkqvfBKUJkAzGi31OADeW2y7D6Bmy/Jcbop9c=
go.sia.tech/mux v1.3.0/go.mod h1:I46++RD4beqA3cW9Xm9SwXbezwPqLvHhVs9HLpDtt58=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
15 changes: 1 addition & 14 deletions miner.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package coreutils

import (
"encoding/binary"
"time"

"go.sia.tech/core/consensus"
Expand All @@ -12,22 +11,10 @@ import (
// FindBlockNonce attempts to find a nonce for b that meets the PoW target.
func FindBlockNonce(cs consensus.State, b *types.Block, timeout time.Duration) bool {
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()
startBlock := time.Now()
for types.BlockID(types.HashBytes(buf)).CmpWork(cs.ChildTarget) < 0 {
for b.ID().CmpWork(cs.ChildTarget) < 0 {
b.Nonce += factor
binary.LittleEndian.PutUint64(buf[32:], b.Nonce)
if time.Since(startBlock) > timeout {
return false
}
Expand Down
36 changes: 24 additions & 12 deletions rhp/v4/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,10 @@ func RPCWriteSector(ctx context.Context, t TransportClient, prices rhp4.HostPric
req := rhp4.RPCWriteSectorRequest{
Prices: prices,
Token: token,
Duration: duration,
DataLength: length,
}

if err := req.Validate(t.PeerKey(), req.Duration); err != nil {
if err := req.Validate(t.PeerKey()); err != nil {
return RPCWriteSectorResult{}, fmt.Errorf("invalid request: %w", err)
}

Expand Down Expand Up @@ -287,7 +286,7 @@ func RPCWriteSector(ctx context.Context, t TransportClient, prices rhp4.HostPric

return RPCWriteSectorResult{
Root: resp.Root,
Usage: prices.RPCWriteSectorCost(uint64(length), duration),
Usage: prices.RPCWriteSectorCost(uint64(length)),
}, nil
}

Expand Down Expand Up @@ -419,6 +418,7 @@ func RPCAppendSectors(ctx context.Context, t TransportClient, cs consensus.State
} else if !contract.Revision.HostPublicKey.VerifyHash(sigHash, hostSignature.HostSignature) {
return RPCAppendSectorsResult{}, rhp4.ErrInvalidSignature
}
revision.HostSignature = hostSignature.HostSignature
return RPCAppendSectorsResult{
Revision: revision,
Usage: usage,
Expand Down Expand Up @@ -498,7 +498,7 @@ func RPCSectorRoots(ctx context.Context, t TransportClient, cs consensus.State,
RenterSignature: revision.RenterSignature,
}

if err := req.Validate(contract.Revision.HostPublicKey, revision, length); err != nil {
if err := req.Validate(contract.Revision.HostPublicKey, revision); err != nil {
return RPCSectorRootsResult{}, fmt.Errorf("invalid request: %w", err)
}

Expand Down Expand Up @@ -597,10 +597,10 @@ func RPCFormContract(ctx context.Context, t TransportClient, tp TxPool, signer F
// sign the renter inputs after the host inputs have been added
signer.SignV2Inputs(&formationTxn, toSign)
formationSigHash := cs.ContractSigHash(fc)
formationTxn.FileContracts[0].RenterSignature = signer.SignHash(formationSigHash)
fc.RenterSignature = signer.SignHash(formationSigHash)

renterPolicyResp := rhp4.RPCFormContractSecondResponse{
RenterContractSignature: formationTxn.FileContracts[0].RenterSignature,
RenterContractSignature: fc.RenterSignature,
}
for _, si := range formationTxn.SiacoinInputs[:len(renterSiacoinElements)] {
renterPolicyResp.RenterSatisfiedPolicies = append(renterPolicyResp.RenterSatisfiedPolicies, si.SatisfiedPolicy)
Expand Down Expand Up @@ -727,10 +727,14 @@ func RPCRenewContract(ctx context.Context, t TransportClient, tp TxPool, signer
// sign the renewal
renewalSigHash := cs.RenewalSigHash(renewal)
renewal.RenterSignature = signer.SignHash(renewalSigHash)
// sign the contract
contractSigHash := cs.ContractSigHash(renewal.NewContract)
renewal.NewContract.RenterSignature = signer.SignHash(contractSigHash)

// send the renter signatures
renterPolicyResp := rhp4.RPCRenewContractSecondResponse{
RenterRenewalSignature: renewal.RenterSignature,
RenterRenewalSignature: renewal.RenterSignature,
RenterContractSignature: renewal.NewContract.RenterSignature,
}
for _, si := range renewalTxn.SiacoinInputs[:len(req.RenterInputs)] {
renterPolicyResp.RenterSatisfiedPolicies = append(renterPolicyResp.RenterSatisfiedPolicies, si.SatisfiedPolicy)
Expand Down Expand Up @@ -760,12 +764,14 @@ func RPCRenewContract(ctx context.Context, t TransportClient, tp TxPool, signer

// validate the host signature
if !existing.HostPublicKey.VerifyHash(renewalSigHash, hostRenewal.HostSignature) {
return RPCRenewContractResult{}, errors.New("invalid host signature")
return RPCRenewContractResult{}, errors.New("invalid host renewal signature")
} else if !existing.HostPublicKey.VerifyHash(contractSigHash, hostRenewal.NewContract.HostSignature) {
return RPCRenewContractResult{}, errors.New("invalid host contract signature")
}
return RPCRenewContractResult{
Contract: ContractRevision{
ID: params.ContractID.V2RenewalID(),
Revision: renewal.NewContract,
Revision: hostRenewal.NewContract,
},
RenewalSet: TransactionSet{
Basis: hostTransactionSetResp.Basis,
Expand Down Expand Up @@ -852,10 +858,14 @@ func RPCRefreshContract(ctx context.Context, t TransportClient, tp TxPool, signe
// sign the renewal
renewalSigHash := cs.RenewalSigHash(renewal)
renewal.RenterSignature = signer.SignHash(renewalSigHash)
// sign the new contract
contractSigHash := cs.ContractSigHash(renewal.NewContract)
renewal.NewContract.RenterSignature = signer.SignHash(contractSigHash)

// send the renter signatures
renterPolicyResp := rhp4.RPCRefreshContractSecondResponse{
RenterRenewalSignature: renewal.RenterSignature,
RenterRenewalSignature: renewal.RenterSignature,
RenterContractSignature: renewal.NewContract.RenterSignature,
}
for _, si := range renewalTxn.SiacoinInputs[:len(req.RenterInputs)] {
renterPolicyResp.RenterSatisfiedPolicies = append(renterPolicyResp.RenterSatisfiedPolicies, si.SatisfiedPolicy)
Expand Down Expand Up @@ -885,12 +895,14 @@ func RPCRefreshContract(ctx context.Context, t TransportClient, tp TxPool, signe

// validate the host signature
if !existing.HostPublicKey.VerifyHash(renewalSigHash, hostRenewal.HostSignature) {
return RPCRefreshContractResult{}, errors.New("invalid host signature")
return RPCRefreshContractResult{}, errors.New("invalid host renewal signature")
} else if !existing.HostPublicKey.VerifyHash(contractSigHash, hostRenewal.NewContract.HostSignature) {
return RPCRefreshContractResult{}, errors.New("invalid host contract signature")
}
return RPCRefreshContractResult{
Contract: ContractRevision{
ID: params.ContractID.V2RenewalID(),
Revision: renewal.NewContract,
Revision: hostRenewal.NewContract,
},
RenewalSet: TransactionSet{
Basis: hostTransactionSetResp.Basis,
Expand Down
Loading
Loading