diff --git a/config.go b/config.go index 936080789..26b86638e 100644 --- a/config.go +++ b/config.go @@ -175,9 +175,10 @@ type ticketBuyerOptions struct { type vspOptions struct { // VSP - TODO: VSPServer to a []string to support multiple VSPs - URL string `long:"url" description:"Base URL of the VSP server"` - PubKey string `long:"pubkey" description:"VSP server pubkey"` - Sync bool `long:"sync" description:"sync tickets to vsp"` + URL string `long:"url" description:"Base URL of the VSP server"` + PubKey string `long:"pubkey" description:"VSP server pubkey"` + Sync bool `long:"sync" description:"sync tickets to vsp"` + MaxFee *cfgutil.AmountFlag `long:"maxfee" description:"Maximum VSP fee"` } // cleanAndExpandPath expands environement variables and leading ~ in the @@ -362,6 +363,10 @@ func loadConfig(ctx context.Context) (*config, []string, error) { BalanceToMaintainAbsolute: cfgutil.NewAmountFlag(defaultBalanceToMaintainAbsolute), VotingAddress: cfgutil.NewAddressFlag(), }, + + VSPOpts: vspOptions{ + MaxFee: cfgutil.NewAmountFlag(0.1e8), + }, } // Pre-parse the command line options to see if an alternative config diff --git a/dcrwallet.go b/dcrwallet.go index 7491c085c..06ed8594e 100644 --- a/dcrwallet.go +++ b/dcrwallet.go @@ -269,6 +269,7 @@ func run(ctx context.Context) error { PubKey: cfg.VSPOpts.PubKey, PurchaseAccount: purchaseAcct, ChangeAccount: changeAcct, + MaxFee: cfg.VSPOpts.MaxFee.Amount, Dialer: cfg.dial, Wallet: w, Params: activeNet.Params, diff --git a/internal/vsp/feeaddress.go b/internal/vsp/feeaddress.go index 83698f299..638b454bd 100644 --- a/internal/vsp/feeaddress.go +++ b/internal/vsp/feeaddress.go @@ -102,17 +102,13 @@ func (v *VSP) GetFeeAddress(ctx context.Context, ticketHash chainhash.Hash) (dcr } feeAmount := dcrutil.Amount(feeResponse.FeeAmount) - // TODO - convert to vsp.maxfee config option - maxFee, err := dcrutil.NewAmount(0.1) - if err != nil { + log.Infof("VSP requires fee %v", feeAmount) + if feeAmount > v.cfg.MaxFee { + err := fmt.Errorf("server fee amount too high: %v > %v", feeAmount, v.cfg.MaxFee) + log.Warn(err) return 0, err } - if feeAmount > maxFee { - log.Warnf("fee amount too high: %v > %v", feeAmount, maxFee) - return 0, fmt.Errorf("server fee amount too high: %v > %v", feeAmount, maxFee) - } - v.ticketToFeeMu.Lock() v.ticketToFeeMap[ticketHash] = PendingFee{ CommitmentAddress: commitmentAddr, diff --git a/internal/vsp/vsp.go b/internal/vsp/vsp.go index bdbda86fa..aec4ca9a9 100644 --- a/internal/vsp/vsp.go +++ b/internal/vsp/vsp.go @@ -47,6 +47,11 @@ type Config struct { // ChangeAccount specifies the change account when creating fee transactions. ChangeAccount uint32 + // MaxFee specifies the maximum allowed fee which the VSP may require. + // Fees exceeding this value will result in the fee transaction not + // being paid to the VSP. + MaxFee dcrutil.Amount + // Dialer specifies an optional dialer when connecting to the VSP. Dialer DialFunc