Skip to content

Commit

Permalink
Upgrade Dependencies (#664)
Browse files Browse the repository at this point in the history
* all: upgrade core

* all: run go mod tidy

* all: upgrade hostd

* internal: fix TestSQLHostDB

* internal: add TestInvalidSignature

* internal: upgrade hostd

* worker: get rid of pointers

* testing: fix stubs

* all: update hostd

* autopilot: fix bad merge

* all: cleanup PR

* all: run go mod tidy

* bus: use TransactionWeight
  • Loading branch information
peterjan authored Oct 16, 2023
1 parent 378d4a0 commit 0b64995
Show file tree
Hide file tree
Showing 18 changed files with 403 additions and 310 deletions.
1 change: 0 additions & 1 deletion api/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ type WalletPrepareRenewRequest struct {
Revision types.FileContractRevision `json:"revision"`
EndHeight uint64 `json:"endHeight"`
HostAddress types.Address `json:"hostAddress"`
HostKey types.PublicKey `json:"hostKey"`
PriceTable rhpv3.HostPriceTable `json:"priceTable"`
NewCollateral types.Currency `json:"newCollateral"`
RenterAddress types.Address `json:"renterAddress"`
Expand Down
57 changes: 29 additions & 28 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.sia.tech/renterd/tracing"
"go.sia.tech/renterd/wallet"
"go.sia.tech/renterd/webhooks"
"go.sia.tech/siad/modules"
"go.uber.org/zap"
)

Expand All @@ -49,10 +50,13 @@ func NewClient(addr, password string) *Client {
type (
// A ChainManager manages blockchain state.
ChainManager interface {
AcceptBlock(context.Context, types.Block) error
AcceptBlock(types.Block) error
BlockAtHeight(height uint64) (types.Block, bool)
IndexAtHeight(height uint64) (types.ChainIndex, error)
LastBlockTime() time.Time
Synced(ctx context.Context) bool
TipState(ctx context.Context) consensus.State
Subscribe(s modules.ConsensusSetSubscriber, ccID modules.ConsensusChangeID, cancel <-chan struct{}) error
Synced() bool
TipState() consensus.State
}

// A Syncer can connect to other peers and synchronize the blockchain.
Expand All @@ -65,9 +69,11 @@ type (

// A TransactionPool can validate and relay unconfirmed transactions.
TransactionPool interface {
AcceptTransactionSet(txns []types.Transaction) error
Close() error
RecommendedFee() types.Currency
Subscribe(subscriber modules.TransactionPoolSubscriber)
Transactions() []types.Transaction
AddTransactionSet(txns []types.Transaction) error
UnconfirmedParents(txn types.Transaction) ([]types.Transaction, error)
}

Expand Down Expand Up @@ -216,7 +222,7 @@ func (b *bus) consensusAcceptBlock(jc jape.Context) {
if jc.Decode(&block) != nil {
return
}
if jc.Check("failed to accept block", b.cm.AcceptBlock(jc.Request.Context(), block)) != nil {
if jc.Check("failed to accept block", b.cm.AcceptBlock(block)) != nil {
return
}
}
Expand All @@ -241,12 +247,12 @@ func (b *bus) syncerConnectHandler(jc jape.Context) {
}

func (b *bus) consensusStateHandler(jc jape.Context) {
jc.Encode(b.consensusState(jc.Request.Context()))
jc.Encode(b.consensusState())
}

func (b *bus) consensusNetworkHandler(jc jape.Context) {
jc.Encode(api.ConsensusNetwork{
Name: b.cm.TipState(jc.Request.Context()).Network.Name,
Name: b.cm.TipState().Network.Name,
})
}

Expand All @@ -262,7 +268,7 @@ func (b *bus) txpoolTransactionsHandler(jc jape.Context) {
func (b *bus) txpoolBroadcastHandler(jc jape.Context) {
var txnSet []types.Transaction
if jc.Decode(&txnSet) == nil {
jc.Check("couldn't broadcast transaction set", b.tp.AddTransactionSet(txnSet))
jc.Check("couldn't broadcast transaction set", b.tp.AcceptTransactionSet(txnSet))
}
}

Expand Down Expand Up @@ -374,10 +380,10 @@ func (b *bus) walletFundHandler(jc jape.Context) {
txn := wfr.Transaction
if len(txn.MinerFees) == 0 {
// if no fees are specified, we add some
fee := b.tp.RecommendedFee().Mul64(uint64(types.EncodedLen(txn)))
fee := b.tp.RecommendedFee().Mul64(b.cm.TipState().TransactionWeight(txn))
txn.MinerFees = []types.Currency{fee}
}
toSign, err := b.w.FundTransaction(b.cm.TipState(jc.Request.Context()), &txn, wfr.Amount.Add(txn.MinerFees[0]), b.tp.Transactions())
toSign, err := b.w.FundTransaction(b.cm.TipState(), &txn, wfr.Amount.Add(txn.MinerFees[0]), b.tp.Transactions())
if jc.Check("couldn't fund transaction", err) != nil {
return
}
Expand All @@ -398,7 +404,7 @@ func (b *bus) walletSignHandler(jc jape.Context) {
if jc.Decode(&wsr) != nil {
return
}
err := b.w.SignTransaction(b.cm.TipState(jc.Request.Context()), &wsr.Transaction, wsr.ToSign, wsr.CoveredFields)
err := b.w.SignTransaction(b.cm.TipState(), &wsr.Transaction, wsr.ToSign, wsr.CoveredFields)
if jc.Check("couldn't sign transaction", err) == nil {
jc.Encode(wsr.Transaction)
}
Expand All @@ -414,7 +420,7 @@ func (b *bus) walletRedistributeHandler(jc jape.Context) {
return
}

cs := b.cm.TipState(jc.Request.Context())
cs := b.cm.TipState()
txn, toSign, err := b.w.Redistribute(cs, wfr.Outputs, wfr.Amount, b.tp.RecommendedFee(), b.tp.Transactions())
if jc.Check("couldn't redistribute money in the wallet into the desired outputs", err) != nil {
return
Expand All @@ -425,7 +431,7 @@ func (b *bus) walletRedistributeHandler(jc jape.Context) {
return
}

if jc.Check("couldn't broadcast the transaction", b.tp.AddTransactionSet([]types.Transaction{txn})) != nil {
if jc.Check("couldn't broadcast the transaction", b.tp.AcceptTransactionSet([]types.Transaction{txn})) != nil {
b.w.ReleaseInputs(txn)
return
}
Expand All @@ -441,7 +447,6 @@ func (b *bus) walletDiscardHandler(jc jape.Context) {
}

func (b *bus) walletPrepareFormHandler(jc jape.Context) {
ctx := jc.Request.Context()
var wpfr api.WalletPrepareFormRequest
if jc.Decode(&wpfr) != nil {
return
Expand All @@ -454,14 +459,14 @@ func (b *bus) walletPrepareFormHandler(jc jape.Context) {
jc.Error(errors.New("no renter key provided"), http.StatusBadRequest)
return
}
cs := b.cm.TipState(ctx)
cs := b.cm.TipState()

fc := rhpv2.PrepareContractFormation(wpfr.RenterKey, wpfr.HostKey, wpfr.RenterFunds, wpfr.HostCollateral, wpfr.EndHeight, wpfr.HostSettings, wpfr.RenterAddress)
cost := rhpv2.ContractFormationCost(cs, fc, wpfr.HostSettings.ContractPrice)
txn := types.Transaction{
FileContracts: []types.FileContract{fc},
}
txn.MinerFees = []types.Currency{b.tp.RecommendedFee().Mul64(uint64(types.EncodedLen(txn)))}
txn.MinerFees = []types.Currency{b.tp.RecommendedFee().Mul64(cs.TransactionWeight(txn))}
toSign, err := b.w.FundTransaction(cs, &txn, cost.Add(txn.MinerFees[0]), b.tp.Transactions())
if jc.Check("couldn't fund transaction", err) != nil {
return
Expand All @@ -485,15 +490,11 @@ func (b *bus) walletPrepareRenewHandler(jc jape.Context) {
if jc.Decode(&wprr) != nil {
return
}
if wprr.HostKey == (types.PublicKey{}) {
jc.Error(errors.New("no host key provided"), http.StatusBadRequest)
return
}
if wprr.RenterKey == nil {
jc.Error(errors.New("no renter key provided"), http.StatusBadRequest)
return
}
cs := b.cm.TipState(jc.Request.Context())
cs := b.cm.TipState()

// Create the final revision from the provided revision.
finalRevision := wprr.Revision
Expand All @@ -503,7 +504,7 @@ func (b *bus) walletPrepareRenewHandler(jc jape.Context) {
finalRevision.RevisionNumber = math.MaxUint64

// Prepare the new contract.
fc, basePrice := rhpv3.PrepareContractRenewal(wprr.Revision, wprr.HostAddress, wprr.RenterAddress, wprr.RenterFunds, wprr.NewCollateral, wprr.HostKey, wprr.PriceTable, wprr.EndHeight)
fc, basePrice := rhpv3.PrepareContractRenewal(wprr.Revision, wprr.HostAddress, wprr.RenterAddress, wprr.RenterFunds, wprr.NewCollateral, wprr.PriceTable, wprr.EndHeight)

// Create the transaction containing both the final revision and new
// contract.
Expand Down Expand Up @@ -1442,17 +1443,17 @@ func (b *bus) paramsHandlerUploadGET(jc jape.Context) {

jc.Encode(api.UploadParams{
ContractSet: contractSet,
CurrentHeight: b.cm.TipState(jc.Request.Context()).Index.Height,
CurrentHeight: b.cm.TipState().Index.Height,
GougingParams: gp,
UploadPacking: uploadPacking,
})
}

func (b *bus) consensusState(ctx context.Context) api.ConsensusState {
func (b *bus) consensusState() api.ConsensusState {
return api.ConsensusState{
BlockHeight: b.cm.TipState(ctx).Index.Height,
BlockHeight: b.cm.TipState().Index.Height,
LastBlockTime: b.cm.LastBlockTime(),
Synced: b.cm.Synced(ctx),
Synced: b.cm.Synced(),
}
}

Expand All @@ -1479,7 +1480,7 @@ func (b *bus) gougingParams(ctx context.Context) (api.GougingParams, error) {
b.logger.Panicf("failed to unmarshal redundancy settings '%s': %v", rss, err)
}

cs := b.consensusState(ctx)
cs := b.consensusState()

return api.GougingParams{
ConsensusState: cs,
Expand Down Expand Up @@ -1691,7 +1692,7 @@ func (b *bus) contractTaxHandlerGET(jc jape.Context) {
if jc.DecodeParam("payout", (*api.ParamCurrency)(&payout)) != nil {
return
}
cs := b.cm.TipState(jc.Request.Context())
cs := b.cm.TipState()
jc.Encode(cs.FileContractTax(types.FileContract{Payout: payout}))
}

Expand Down
3 changes: 1 addition & 2 deletions bus/client/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ func (c *Client) WalletPrepareForm(ctx context.Context, renterAddress types.Addr
}

// WalletPrepareRenew funds and signs a contract renewal transaction.
func (c *Client) WalletPrepareRenew(ctx context.Context, revision types.FileContractRevision, hostAddress, renterAddress types.Address, renterKey types.PrivateKey, renterFunds, newCollateral types.Currency, hostKey types.PublicKey, pt rhpv3.HostPriceTable, endHeight, windowSize uint64) (api.WalletPrepareRenewResponse, error) {
func (c *Client) WalletPrepareRenew(ctx context.Context, revision types.FileContractRevision, hostAddress, renterAddress types.Address, renterKey types.PrivateKey, renterFunds, newCollateral types.Currency, pt rhpv3.HostPriceTable, endHeight, windowSize uint64) (api.WalletPrepareRenewResponse, error) {
req := api.WalletPrepareRenewRequest{
Revision: revision,
EndHeight: endHeight,
HostAddress: hostAddress,
HostKey: hostKey,
PriceTable: pt,
NewCollateral: newCollateral,
RenterAddress: renterAddress,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
go.sia.tech/core v0.1.12-0.20230529164041-6347a98003be
go.sia.tech/core v0.1.12-0.20231011172826-6ca0ac7b3b6b
go.sia.tech/gofakes3 v0.0.0-20231003090232-776c144c0a19
go.sia.tech/hostd v0.1.4
go.sia.tech/hostd v0.2.1-0.20231013174940-920057ff41c8
go.sia.tech/jape v0.9.1-0.20230525021720-ecf031ecbffb
go.sia.tech/mux v1.2.0
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZE
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
go.sia.tech/core v0.1.12-0.20230529164041-6347a98003be h1:fKfwYsCF5ua3Z/NNdLU+4sS9MM6M4EetMA0V4Y8zPKg=
go.sia.tech/core v0.1.12-0.20230529164041-6347a98003be/go.mod h1:D17UWSn99SEfQnEaR9G9n6Kz9+BwqMoUgZ6Cl424LsQ=
go.sia.tech/core v0.1.12-0.20231011172826-6ca0ac7b3b6b h1:gHnhRiY1SMWCEFu+1Xo0a967RVzHg+g+0grMbHNuLfE=
go.sia.tech/core v0.1.12-0.20231011172826-6ca0ac7b3b6b/go.mod h1:3EoY+rR78w1/uGoXXVqcYdwSjSJKuEMI5bL7WROA27Q=
go.sia.tech/gofakes3 v0.0.0-20231003090232-776c144c0a19 h1:qCJHxn1RgRdmltGl3jehgbJcpTSTaWhzdDuOiWkjvm0=
go.sia.tech/gofakes3 v0.0.0-20231003090232-776c144c0a19/go.mod h1:PlsiVCn6+wssrR7bsOIlZm0DahsVrDydrlbjY4F14sg=
go.sia.tech/hostd v0.1.4 h1:r6PSo8ed0hmxjf4pvFQfRCfGk/DVRd/R/T9K9B0JhJ4=
go.sia.tech/hostd v0.1.4/go.mod h1:o+Z9ZGJZRY31MvRNXyyAlmBHjjiTE/3TgAB4pCHgr2c=
go.sia.tech/hostd v0.2.1-0.20231013174940-920057ff41c8 h1:0kVIAauXG2+C5EZWlnJDVtf6TrLLgB+EcObuCJyDNfY=
go.sia.tech/hostd v0.2.1-0.20231013174940-920057ff41c8/go.mod h1:B+jY+eJ2jlcowcXwYOb28N/A6/cy2dblX/WUec9pFM8=
go.sia.tech/jape v0.9.1-0.20230525021720-ecf031ecbffb h1:yLDEqkqC19E/HgBoq2Uhw9oH3SMNRyeRjZ7Ep4dPKR8=
go.sia.tech/jape v0.9.1-0.20230525021720-ecf031ecbffb/go.mod h1:4QqmBB+t3W7cNplXPj++ZqpoUb2PeiS66RLpXmEGap4=
go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU=
Expand Down
Loading

0 comments on commit 0b64995

Please sign in to comment.