Skip to content
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
12 changes: 12 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
// ticket buyer options
defaultBalanceToMaintainAbsolute = 0
defaultTicketbuyerLimit = 1
// If max ticket price is set to 0, purchase will still be made even if ticket price is too high
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the other default values have comments, so this one seems a bit out of place.

Perhaps we move it to the description tag in the config struct? Then it will appear in the output of dcrwallet --help which is useful for end-users.

defaultMaxTicketPrice = 0

walletDbName = "wallet.db"
)
Expand Down Expand Up @@ -187,6 +189,7 @@ type ticketBuyerOptions struct {
BalanceToMaintainAbsolute *cfgutil.AmountFlag `long:"balancetomaintainabsolute" description:"Amount of funds to keep in wallet when purchasing tickets"`
Limit uint `long:"limit" description:"Buy no more than specified number of tickets per block"`
VotingAccount string `long:"votingaccount" description:"Account used to derive addresses specifying voting rights"`
MaxTicketPrice *cfgutil.AmountFlag `long:"maxticketprice" description:"Don't buy when the price is too high"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MaxTicketPrice *cfgutil.AmountFlag `long:"maxticketprice" description:"Don't buy when the price is too high"`
MaxTicketPrice *cfgutil.AmountFlag `long:"maxticketprice" description:"Don't buy tickets when the price is above this limit; no limit if unset or zero"`

}

type vspOptions struct {
Expand Down Expand Up @@ -382,6 +385,7 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
TBOpts: ticketBuyerOptions{
BalanceToMaintainAbsolute: cfgutil.NewAmountFlag(defaultBalanceToMaintainAbsolute),
Limit: defaultTicketbuyerLimit,
MaxTicketPrice: cfgutil.NewAmountFlag(defaultMaxTicketPrice),
},

VSPOpts: vspOptions{
Expand Down Expand Up @@ -573,6 +577,14 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
return loadConfigError(err)
}

// Check valid Maxticketprice param
if cfg.TBOpts.MaxTicketPrice.ToCoin() < 0 {
str := "%s: maxticketprice cannot be negative: %v"
err := errors.Errorf(str, funcName, cfg.TBOpts.MaxTicketPrice)
fmt.Fprintln(os.Stderr, err)
return loadConfigError(err)
}

// Exit if you try to use a simulation wallet with a standard
// data directory.
if !cfg.AppDataDir.ExplicitlySet() && cfg.CreateTemp {
Expand Down
1 change: 1 addition & 0 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func run(ctx context.Context) error {
BuyTickets: cfg.EnableTicketBuyer,
Account: purchaseAccount,
Maintain: cfg.TBOpts.BalanceToMaintainAbsolute.Amount,
MaxTicketPrice: cfg.TBOpts.MaxTicketPrice.Amount,
Limit: int(cfg.TBOpts.Limit),
VotingAccount: votingAccount,
Mixing: cfg.Mixing,
Expand Down
1 change: 1 addition & 0 deletions sample-dcrwallet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@

; Amount of funds to keep in wallet when stake mining
; ticketbuyer.balancetomaintainabsolute=0
; ticketbuyer.maxticketprice=0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other item in this file has a comment - the description from config.go.


[VSP Options]

Expand Down
13 changes: 8 additions & 5 deletions ticketbuyer/tb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Config struct {
// Minimum amount to maintain in purchasing account
Maintain dcrutil.Amount

// Maximum ticket price allowed to be purchased
MaxTicketPrice dcrutil.Amount

// Limit maximum number of purchased tickets per block
Limit int

Expand Down Expand Up @@ -282,11 +285,11 @@ func (tb *TB) buy(ctx context.Context, passphrase []byte, tip *wire.BlockHeader,
}

purchaseTicketReq := &wallet.PurchaseTicketsRequest{
Count: buy,
SourceAccount: account,
MinConf: minconf,
Expiry: expiry,

Count: buy,
SourceAccount: account,
MinConf: minconf,
Expiry: expiry,
MaxTicketPrice: cfg.MaxTicketPrice,
// CSPP
Mixing: mixing,
VotingAccount: votingAccount,
Expand Down
5 changes: 5 additions & 0 deletions wallet/createtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ func (w *Wallet) purchaseTickets(ctx context.Context, op errors.Op,
return nil, err
}

// If the ticket price exceeds the max ticket price, skipping purchase
if req.MaxTicketPrice > 0 && ticketPrice > req.MaxTicketPrice {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the new config item is a TicketBuyer config, I don't think this check should be buried deep in the generic purchaseTickets func, it should really live in the ticketbuyer code. If the ticket price is too high, ticketbuyer should not be calling purchaseTickets at all. For reference, see how and where the check for balance to maintain is handled.

return nil, errors.E(op, errors.Invalid, "Skipping purchase: Ticket price exceeds max ticket price.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Error strings should not be capitalized (unless beginning with an exported name, a proper noun or an acronym) and should not end with punctuation."

https://google.github.io/styleguide/go/decisions.html#error-strings

}

const stakeSubmissionPkScriptSize = txsizes.P2PKHPkScriptSize + 1

// Make sure that we have enough funds. Calculate different
Expand Down
1 change: 1 addition & 0 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ type PurchaseTicketsRequest struct {
SourceAccount uint32
MinConf int32
Expiry int32
MaxTicketPrice dcrutil.Amount
VotingAccount uint32 // Used when Mixing == true || UseVotingAccount == true
UseVotingAccount bool // Forces use of supplied voting account.
DontSignTx bool
Expand Down