Skip to content

Commit

Permalink
jsonrpc: Respect configured VSPMaxFee.
Browse files Browse the repository at this point in the history
Don't override with a hard-coded value of 0.2e8.
  • Loading branch information
jholdstock authored and jrick committed Apr 24, 2023
1 parent c6933a3 commit a19dcb4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config.go
Expand Up @@ -57,6 +57,7 @@ const (
defaultDisableCoinTypeUpgrades = false
defaultCircuitLimit = 32
defaultMixSplitLimit = 10
defaultVSPMaxFee = dcrutil.Amount(0.2e8)

// ticket buyer options
defaultBalanceToMaintainAbsolute = 0
Expand Down Expand Up @@ -378,7 +379,7 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
},

VSPOpts: vspOptions{
MaxFee: cfgutil.NewAmountFlag(0.2e8),
MaxFee: cfgutil.NewAmountFlag(defaultVSPMaxFee),
},
}

Expand Down
3 changes: 3 additions & 0 deletions internal/rpc/jsonrpc/config.go
Expand Up @@ -7,6 +7,8 @@ package jsonrpc
import (
"context"
"net"

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

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

VSPHost string
VSPPubKey string
VSPMaxFee dcrutil.Amount
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
}
13 changes: 8 additions & 5 deletions internal/rpc/jsonrpc/methods.go
Expand Up @@ -3423,12 +3423,11 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd interface{}) (interfac
}
}

var vspHost string
var vspPubKey string
var vspClient *vsp.Client
if s.cfg.VSPHost != "" || s.cfg.VSPPubKey != "" {
vspHost = s.cfg.VSPHost
vspPubKey = s.cfg.VSPPubKey
vspHost := s.cfg.VSPHost
vspPubKey := s.cfg.VSPPubKey
vspMaxFee := s.cfg.VSPMaxFee
if vspPubKey == "" {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"vsp pubkey can not be null")
Expand All @@ -3437,13 +3436,17 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd interface{}) (interfac
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"vsp host can not be null")
}
if vspMaxFee == 0 {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
"vsp max fee must be greater than zero")
}
cfg := vsp.Config{
URL: vspHost,
PubKey: vspPubKey,
Dialer: s.cfg.Dial,
Wallet: w,
Policy: vsp.Policy{
MaxFee: 0.2e8,
MaxFee: vspMaxFee,
FeeAcct: account,
ChangeAcct: changeAccount,
},
Expand Down
1 change: 1 addition & 0 deletions rpcserver.go
Expand Up @@ -373,6 +373,7 @@ 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

0 comments on commit a19dcb4

Please sign in to comment.