Skip to content

Commit

Permalink
Dont allow ticket voting address override.
Browse files Browse the repository at this point in the history
Setting a specific voting address was an important part of purchasing a
legacy stakepool ticket, however it is no longer necessary and providing
these options only serves as a potential footgun which can lead to
accidental address reuse.

Now a new voting address is derived for every ticket, either from the
voting account if one is specified, or from the purchase account if not.

Breaking changes:

1. Config `--votingaddress` removed.
1. Param `ticket_address` removed from `PurchaseTickets` gRPC.
1. Param `voting_address` removed from `RunTicketBuyer` gRPC.
1. Param `ticketaddress` removed from `purchaseticket` json-RPC.
  • Loading branch information
jholdstock committed Sep 10, 2024
1 parent 5cd89f5 commit f597088
Show file tree
Hide file tree
Showing 16 changed files with 1,604 additions and 1,736 deletions.
25 changes: 3 additions & 22 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"decred.org/dcrwallet/v5/wallet/txrules"
"github.com/decred/dcrd/connmgr/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/txscript/v4/stdaddr"
"github.com/decred/go-socks/socks"
"github.com/decred/slog"
flags "github.com/jessevdk/go-flags"
Expand Down Expand Up @@ -187,11 +186,9 @@ type config struct {
}

type ticketBuyerOptions struct {
BalanceToMaintainAbsolute *cfgutil.AmountFlag `long:"balancetomaintainabsolute" description:"Amount of funds to keep in wallet when purchasing tickets"`
VotingAddress *cfgutil.AddressFlag `long:"votingaddress" description:"Purchase tickets with voting rights assigned to this address"`
votingAddress stdaddr.StakeAddress
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"`
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"`
}

type vspOptions struct {
Expand Down Expand Up @@ -386,7 +383,6 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
// Ticket Buyer Options
TBOpts: ticketBuyerOptions{
BalanceToMaintainAbsolute: cfgutil.NewAmountFlag(defaultBalanceToMaintainAbsolute),
VotingAddress: cfgutil.NewAddressFlag(),
Limit: defaultTicketbuyerLimit,
},

Expand Down Expand Up @@ -547,21 +543,6 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
os.Exit(0)
}

// Check that no addresses were created for the wrong network
for _, a := range []struct {
flag *cfgutil.AddressFlag
addr *stdaddr.StakeAddress
}{
{cfg.TBOpts.VotingAddress, &cfg.TBOpts.votingAddress},
} {
addr, err := a.flag.StakeAddress(activeNet.Params)
if err != nil {
log.Error(err)
return loadConfigError(err)
}
*a.addr = addr
}

// Parse, validate, and set debug log level(s).
if err := parseAndSetDebugLevels(cfg.DebugLevel); err != nil {
err := errors.Errorf("%s: %v", "loadConfig", err.Error())
Expand Down
5 changes: 0 additions & 5 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func run(ctx context.Context) error {
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
stakeOptions := &ldr.StakeOptions{
VotingEnabled: cfg.EnableVoting,
VotingAddress: cfg.TBOpts.votingAddress,
}
loader := ldr.NewLoader(activeNet.Params, dbDir, stakeOptions,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
Expand Down Expand Up @@ -310,8 +309,6 @@ func run(ctx context.Context) error {
mixedAccount uint32 // (enableticketbuyer && mixing) || mixchange
changeAccount uint32 // (enableticketbuyer && mixing) || mixchange
ticketSplitAccount uint32 // enableticketbuyer && mixing

votingAddr = cfg.TBOpts.votingAddress
)
if cfg.EnableTicketBuyer {
purchaseAccount = lookup("purchaseaccount", cfg.PurchaseAccount)
Expand All @@ -323,7 +320,6 @@ func run(ctx context.Context) error {
}
if cfg.TBOpts.VotingAccount != "" {
votingAccount = lookup("ticketbuyer.votingaccount", cfg.TBOpts.VotingAccount)
votingAddr = nil
}
}
if (cfg.EnableTicketBuyer && cfg.Mixing) || cfg.MixChange {
Expand All @@ -345,7 +341,6 @@ func run(ctx context.Context) error {
BuyTickets: cfg.EnableTicketBuyer,
Account: purchaseAccount,
Maintain: cfg.TBOpts.BalanceToMaintainAbsolute.Amount,
VotingAddr: votingAddr,
Limit: int(cfg.TBOpts.Limit),
VotingAccount: votingAccount,
Mixing: cfg.Mixing,
Expand Down
5 changes: 0 additions & 5 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
_ "decred.org/dcrwallet/v5/wallet/drivers/bdb" // driver loaded during init
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/txscript/v4/stdaddr"
)

const (
Expand Down Expand Up @@ -55,7 +54,6 @@ type Loader struct {
// StakeOptions contains the various options necessary for stake mining.
type StakeOptions struct {
VotingEnabled bool
VotingAddress stdaddr.StakeAddress
}

// NewLoader constructs a Loader.
Expand Down Expand Up @@ -174,7 +172,6 @@ func (l *Loader) CreateWatchingOnlyWallet(ctx context.Context, extendedPubKey st
DB: db,
PubPassphrase: pubPass,
VotingEnabled: so.VotingEnabled,
VotingAddress: so.VotingAddress,
GapLimit: l.gapLimit,
WatchLast: l.watchLast,
AccountGapLimit: l.accountGapLimit,
Expand Down Expand Up @@ -264,7 +261,6 @@ func (l *Loader) CreateNewWallet(ctx context.Context, pubPassphrase, privPassphr
DB: db,
PubPassphrase: pubPassphrase,
VotingEnabled: so.VotingEnabled,
VotingAddress: so.VotingAddress,
GapLimit: l.gapLimit,
WatchLast: l.watchLast,
AccountGapLimit: l.accountGapLimit,
Expand Down Expand Up @@ -322,7 +318,6 @@ func (l *Loader) OpenExistingWallet(ctx context.Context, pubPassphrase []byte) (
DB: db,
PubPassphrase: pubPassphrase,
VotingEnabled: so.VotingEnabled,
VotingAddress: so.VotingAddress,
GapLimit: l.gapLimit,
WatchLast: l.watchLast,
AccountGapLimit: l.accountGapLimit,
Expand Down
11 changes: 0 additions & 11 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3296,16 +3296,6 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
}
}

// Set ticket address if specified.
var ticketAddr stdaddr.StakeAddress
if cmd.TicketAddress != nil && *cmd.TicketAddress != "" {
addr, err := decodeStakeAddress(*cmd.TicketAddress, w.ChainParams())
if err != nil {
return nil, err
}
ticketAddr = addr
}

numTickets := 1
if cmd.NumTickets != nil {
if *cmd.NumTickets > 1 {
Expand Down Expand Up @@ -3380,7 +3370,6 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
request := &wallet.PurchaseTicketsRequest{
Count: numTickets,
SourceAccount: account,
VotingAddress: ticketAddr,
MinConf: minConf,
Expiry: expiry,
DontSignTx: dontSignTx,
Expand Down
Loading

0 comments on commit f597088

Please sign in to comment.