Skip to content

Commit

Permalink
vsp: Make maximum fee configurable
Browse files Browse the repository at this point in the history
The default maximum fee is set to 0.1 DCR, and matches the previous
hardcoded fee check.
  • Loading branch information
jrick committed Nov 30, 2020
1 parent b7ca847 commit 4aed9f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
11 changes: 8 additions & 3 deletions config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dcrwallet.go
Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions internal/vsp/feeaddress.go
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions internal/vsp/vsp.go
Expand Up @@ -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

Expand Down

0 comments on commit 4aed9f5

Please sign in to comment.