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

Don't use hard-coded VSP MaxFee. #2439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ func run(ctx context.Context) error {

loader := ldr.NewLoader(activeNet.Params, dbDir, cfg.EnableVoting,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, !cfg.Mixing,
cfg.ManualTickets, cfg.MixSplitLimit, cfg.dial)
cfg.VSPOpts.MaxFee.Amount, cfg.AccountGapLimit,
cfg.DisableCoinTypeUpgrades, !cfg.Mixing, cfg.ManualTickets,
cfg.MixSplitLimit, cfg.dial)

// Stop any services started by the loader after the shutdown procedure is
// initialized and this function returns.
Expand Down
7 changes: 6 additions & 1 deletion internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Loader struct {
allowHighFees bool
manualTickets bool
relayFee dcrutil.Amount
vspMaxFee dcrutil.Amount
mixSplitLimit int
dialer wallet.DialFunc

Expand All @@ -54,7 +55,7 @@ type Loader struct {

// NewLoader constructs a Loader.
func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled bool, gapLimit uint32,
watchLast uint32, allowHighFees bool, relayFee dcrutil.Amount, accountGapLimit int,
watchLast uint32, allowHighFees bool, relayFee dcrutil.Amount, vspMaxFee dcrutil.Amount, accountGapLimit int,
disableCoinTypeUpgrades bool, disableMixing bool, manualTickets bool, mixSplitLimit int, dialer wallet.DialFunc) *Loader {

return &Loader{
Expand All @@ -69,6 +70,7 @@ func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled boo
allowHighFees: allowHighFees,
manualTickets: manualTickets,
relayFee: relayFee,
vspMaxFee: vspMaxFee,
mixSplitLimit: mixSplitLimit,
dialer: dialer,
}
Expand Down Expand Up @@ -176,6 +178,7 @@ func (l *Loader) CreateWatchingOnlyWallet(ctx context.Context, extendedPubKey st
ManualTickets: l.manualTickets,
AllowHighFees: l.allowHighFees,
RelayFee: l.relayFee,
VSPMaxFee: l.vspMaxFee,
MixSplitLimit: l.mixSplitLimit,
Params: l.chainParams,
Dialer: l.dialer,
Expand Down Expand Up @@ -264,6 +267,7 @@ func (l *Loader) CreateNewWallet(ctx context.Context, pubPassphrase, privPassphr
ManualTickets: l.manualTickets,
AllowHighFees: l.allowHighFees,
RelayFee: l.relayFee,
VSPMaxFee: l.vspMaxFee,
Params: l.chainParams,
Dialer: l.dialer,
}
Expand Down Expand Up @@ -321,6 +325,7 @@ func (l *Loader) OpenExistingWallet(ctx context.Context, pubPassphrase []byte) (
ManualTickets: l.manualTickets,
AllowHighFees: l.allowHighFees,
RelayFee: l.relayFee,
VSPMaxFee: l.vspMaxFee,
MixSplitLimit: l.mixSplitLimit,
Params: l.chainParams,
Dialer: l.dialer,
Expand Down
5 changes: 1 addition & 4 deletions internal/rpc/jsonrpc/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013-2015 The btcsuite developers
// Copyright (c) 2013-2024 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand All @@ -7,8 +7,6 @@ package jsonrpc
import (
"context"
"net"

"github.com/decred/dcrd/dcrutil/v4"
)

// Options contains the required options for running the legacy RPC server.
Expand All @@ -27,6 +25,5 @@ type Options struct {

VSPHost string
VSPPubKey string
VSPMaxFee dcrutil.Amount
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
}
2 changes: 1 addition & 1 deletion internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3348,7 +3348,7 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
URL: s.cfg.VSPHost,
PubKey: s.cfg.VSPPubKey,
Policy: &wallet.VSPPolicy{
MaxFee: s.cfg.VSPMaxFee,
MaxFee: w.VSPMaxFee(),
FeeAcct: account,
ChangeAcct: changeAccount,
},
Expand Down
12 changes: 6 additions & 6 deletions internal/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ func (s *walletServer) PurchaseTickets(ctx context.Context,
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: s.wallet.VSPMaxFee(),
FeeAcct: req.Account,
ChangeAcct: req.ChangeAccount,
},
Expand Down Expand Up @@ -2604,7 +2604,7 @@ func (t *ticketbuyerServer) RunTicketBuyer(req *pb.RunTicketBuyerRequest, svr pb
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: w.VSPMaxFee(),
FeeAcct: req.Account,
ChangeAcct: req.Account,
},
Expand Down Expand Up @@ -4076,7 +4076,7 @@ func (s *walletServer) SyncVSPFailedTickets(ctx context.Context, req *pb.SyncVSP
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: s.wallet.VSPMaxFee(),
FeeAcct: req.Account,
ChangeAcct: req.ChangeAccount,
},
Expand Down Expand Up @@ -4113,7 +4113,7 @@ func (s *walletServer) ProcessManagedTickets(ctx context.Context, req *pb.Proces
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: s.wallet.VSPMaxFee(),
FeeAcct: req.FeeAccount,
ChangeAcct: req.ChangeAccount,
},
Expand Down Expand Up @@ -4143,7 +4143,7 @@ func (s *walletServer) ProcessUnmanagedTickets(ctx context.Context, req *pb.Proc
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: s.wallet.VSPMaxFee(),
FeeAcct: req.FeeAccount,
ChangeAcct: req.ChangeAccount,
},
Expand All @@ -4170,7 +4170,7 @@ func (s *walletServer) SetVspdVoteChoices(ctx context.Context, req *pb.SetVspdVo
URL: req.VspHost,
PubKey: req.VspPubkey,
Policy: &wallet.VSPPolicy{
MaxFee: 0.1e8,
MaxFee: s.wallet.VSPMaxFee(),
FeeAcct: req.FeeAccount,
ChangeAcct: req.ChangeAccount,
},
Expand Down
1 change: 0 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ func startRPCServers(walletLoader *loader.Loader) (*grpc.Server, *jsonrpc.Server
MixChangeAccount: cfg.ChangeAccount,
VSPHost: cfg.VSPOpts.URL,
VSPPubKey: cfg.VSPOpts.PubKey,
VSPMaxFee: cfg.VSPOpts.MaxFee.Amount,
TicketSplitAccount: cfg.TicketSplitAccount,
Dial: cfg.dial,
}
Expand Down
8 changes: 8 additions & 0 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type Wallet struct {
minTestNetTarget *big.Int
minTestNetDiffBits uint32

vspMaxFee dcrutil.Amount
vspClientsMu sync.Mutex
vspClients map[string]*VSPClient

Expand All @@ -195,6 +196,7 @@ type Config struct {
ManualTickets bool
AllowHighFees bool
RelayFee dcrutil.Amount
VSPMaxFee dcrutil.Amount
Params *chaincfg.Params

Dialer DialFunc
Expand Down Expand Up @@ -755,6 +757,11 @@ func (w *Wallet) SetTSpendPolicy(ctx context.Context, tspendHash *chainhash.Hash
return nil
}

// VSPMaxFee is the maximum fee to pay when registering a ticket with a VSP.
func (w *Wallet) VSPMaxFee() dcrutil.Amount {
return w.vspMaxFee
}

// RelayFee returns the current minimum relay fee (per kB of serialized
// transaction) used when constructing transactions.
func (w *Wallet) RelayFee() dcrutil.Amount {
Expand Down Expand Up @@ -5412,6 +5419,7 @@ func Open(ctx context.Context, cfg *Config) (*Wallet, error) {
mixSems: newMixSemaphores(cfg.MixSplitLimit),
mixing: !cfg.DisableMixing,

vspMaxFee: cfg.VSPMaxFee,
vspClients: make(map[string]*VSPClient),

dialer: cfg.Dialer,
Expand Down
5 changes: 3 additions & 2 deletions walletsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ func createWallet(ctx context.Context, cfg *config) error {
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
loader := loader.NewLoader(activeNet.Params, dbDir, cfg.EnableVoting,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, !cfg.Mixing,
cfg.ManualTickets, cfg.MixSplitLimit, cfg.dial)
cfg.VSPOpts.MaxFee.Amount, cfg.AccountGapLimit,
cfg.DisableCoinTypeUpgrades, !cfg.Mixing, cfg.ManualTickets,
cfg.MixSplitLimit, cfg.dial)

var privPass, pubPass, seed []byte
var imported bool
Expand Down
Loading