-
Notifications
You must be signed in to change notification settings - Fork 184
Add param to prevent overpriced ticket purchases #2461
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| defaultMaxTicketPrice = 0 | ||||||
|
|
||||||
| walletDbName = "wallet.db" | ||||||
| ) | ||||||
|
|
@@ -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"` | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| type vspOptions struct { | ||||||
|
|
@@ -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{ | ||||||
|
|
@@ -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 { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,6 +238,7 @@ | |
|
|
||
| ; Amount of funds to keep in wallet when stake mining | ||
| ; ticketbuyer.balancetomaintainabsolute=0 | ||
| ; ticketbuyer.maxticketprice=0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every other item in this file has a comment - the description from |
||
|
|
||
| [VSP Options] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return nil, errors.E(op, errors.Invalid, "Skipping purchase: Ticket price exceeds max ticket price.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://google.github.io/styleguide/go/decisions.html#error-strings |
||
| } | ||
|
|
||
| const stakeSubmissionPkScriptSize = txsizes.P2PKHPkScriptSize + 1 | ||
|
|
||
| // Make sure that we have enough funds. Calculate different | ||
|
|
||
There was a problem hiding this comment.
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
configstruct? Then it will appear in the output ofdcrwallet --helpwhich is useful for end-users.