Skip to content

Commit

Permalink
Standardize on "mixingEnabled".
Browse files Browse the repository at this point in the history
Loader was using a flag to disable mixing whereas the rest of the code
was using a flag to enable it. Standardizing on one removes the need to
invert back and forth.
  • Loading branch information
jholdstock committed Oct 15, 2024
1 parent 4adf892 commit b402438
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type config struct {
IssueClientCert bool `long:"issueclientcert" description:"Notify a client cert and key over the TX pipe for RPC authentication"`

// CSPP
Mixing bool `long:"mixing" description:"Enable mixing support"`
MixingEnabled bool `long:"mixing" description:"Enable mixing support"`
CSPPSolver *cfgutil.ExplicitString `long:"csppsolver" description:"Path to CSPP solver executable (if not in PATH)"`
MixedAccount string `long:"mixedaccount" description:"Account/branch used to derive CoinShuffle++ mixed outputs and voting rewards"`
mixedAccount string
Expand Down Expand Up @@ -738,7 +738,7 @@ func loadConfig(ctx context.Context) (*config, []string, error) {
}

var solverMustWork bool
if cfg.Mixing {
if cfg.MixingEnabled {
if cfg.CSPPSolver.ExplicitlySet() {
solverrpc.SolverProcess = cfg.CSPPSolver.Value
solverMustWork = true
Expand Down
12 changes: 6 additions & 6 deletions dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func run(ctx context.Context) error {

loader := ldr.NewLoader(activeNet.Params, dbDir, cfg.EnableVoting,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, !cfg.Mixing,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, cfg.MixingEnabled,
cfg.ManualTickets, cfg.MixSplitLimit, cfg.dial)

// Stop any services started by the loader after the shutdown procedure is
Expand Down Expand Up @@ -251,7 +251,7 @@ func run(ctx context.Context) error {

if cfg.VSPOpts.URL != "" {
changeAccountName := cfg.ChangeAccount
if changeAccountName == "" && !cfg.Mixing {
if changeAccountName == "" && !cfg.MixingEnabled {
log.Warnf("Change account not set, using "+
"purchase account %q", cfg.PurchaseAccount)
changeAccountName = cfg.PurchaseAccount
Expand Down Expand Up @@ -307,7 +307,7 @@ func run(ctx context.Context) error {
if cfg.EnableTicketBuyer {
purchaseAccount = lookup("purchaseaccount", cfg.PurchaseAccount)

if cfg.Mixing && cfg.TBOpts.VotingAccount == "" {
if cfg.MixingEnabled && cfg.TBOpts.VotingAccount == "" {
err := errors.New("cannot run mixed ticketbuyer without --votingaccount")
log.Error(err)
return err
Expand All @@ -316,11 +316,11 @@ func run(ctx context.Context) error {
votingAccount = lookup("ticketbuyer.votingaccount", cfg.TBOpts.VotingAccount)
}
}
if (cfg.EnableTicketBuyer && cfg.Mixing) || cfg.MixChange {
if (cfg.EnableTicketBuyer && cfg.MixingEnabled) || cfg.MixChange {
mixedAccount = lookup("mixedaccount", cfg.mixedAccount)
changeAccount = lookup("changeaccount", cfg.ChangeAccount)
}
if cfg.EnableTicketBuyer && cfg.Mixing {
if cfg.EnableTicketBuyer && cfg.MixingEnabled {
ticketSplitAccount = lookup("ticketsplitaccount", cfg.TicketSplitAccount)
}

Expand All @@ -337,7 +337,7 @@ func run(ctx context.Context) error {
Maintain: cfg.TBOpts.BalanceToMaintainAbsolute.Amount,
Limit: int(cfg.TBOpts.Limit),
VotingAccount: votingAccount,
Mixing: cfg.Mixing,
Mixing: cfg.MixingEnabled,
MixChange: cfg.MixChange,
MixedAccount: mixedAccount,
MixedAccountBranch: cfg.mixedBranch,
Expand Down
8 changes: 4 additions & 4 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Loader struct {
watchLast uint32
accountGapLimit int
disableCoinTypeUpgrades bool
disableMixing bool
mixingEnabled bool
allowHighFees bool
manualTickets bool
relayFee dcrutil.Amount
Expand All @@ -55,7 +55,7 @@ type Loader struct {
// NewLoader constructs a Loader.
func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled bool, gapLimit uint32,
watchLast uint32, allowHighFees bool, relayFee dcrutil.Amount, accountGapLimit int,
disableCoinTypeUpgrades bool, disableMixing bool, manualTickets bool, mixSplitLimit int, dialer wallet.DialFunc) *Loader {
disableCoinTypeUpgrades bool, mixingEnabled bool, manualTickets bool, mixSplitLimit int, dialer wallet.DialFunc) *Loader {

return &Loader{
chainParams: chainParams,
Expand All @@ -65,7 +65,7 @@ func NewLoader(chainParams *chaincfg.Params, dbDirPath string, votingEnabled boo
watchLast: watchLast,
accountGapLimit: accountGapLimit,
disableCoinTypeUpgrades: disableCoinTypeUpgrades,
disableMixing: disableMixing,
mixingEnabled: mixingEnabled,
allowHighFees: allowHighFees,
manualTickets: manualTickets,
relayFee: relayFee,
Expand Down Expand Up @@ -172,7 +172,7 @@ func (l *Loader) CreateWatchingOnlyWallet(ctx context.Context, extendedPubKey st
WatchLast: l.watchLast,
AccountGapLimit: l.accountGapLimit,
DisableCoinTypeUpgrades: l.disableCoinTypeUpgrades,
DisableMixing: l.disableMixing,
MixingEnabled: l.mixingEnabled,
ManualTickets: l.manualTickets,
AllowHighFees: l.allowHighFees,
RelayFee: l.relayFee,
Expand Down
4 changes: 2 additions & 2 deletions internal/rpc/jsonrpc/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013-2015 The btcsuite developers
// Copyright (c) 2013-2024 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand All @@ -19,7 +19,7 @@ type Options struct {
MaxPOSTClients int64
MaxWebsocketClients int64

Mixing bool
MixingEnabled bool
MixAccount string
MixBranch uint32
MixChangeAccount string
Expand Down
10 changes: 5 additions & 5 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3319,7 +3319,7 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
// mixing is enabled).
var changeAccount = account

if s.cfg.Mixing {
if s.cfg.MixingEnabled {
mixedAccount, err = w.AccountNumber(ctx, s.cfg.MixAccount)
if err != nil {
return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter,
Expand Down Expand Up @@ -3368,7 +3368,7 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd any) (any, error) {
DontSignTx: dontSignTx,

// CSPP
Mixing: s.cfg.Mixing,
Mixing: s.cfg.MixingEnabled,
MixedAccount: mixedAccount,
MixedAccountBranch: mixedAccountBranch,
MixedSplitAccount: mixedSplitAccount,
Expand Down Expand Up @@ -3495,7 +3495,7 @@ func makeOutputs(pairs map[string]dcrutil.Amount, chainParams *chaincfg.Params)
// All errors are returned in dcrjson.RPCError format
func (s *Server) sendPairs(ctx context.Context, w *wallet.Wallet, amounts map[string]dcrutil.Amount, account uint32, minconf int32) (string, error) {
changeAccount := account
if s.cfg.Mixing && s.cfg.MixAccount != "" && s.cfg.MixChangeAccount != "" {
if s.cfg.MixingEnabled && s.cfg.MixAccount != "" && s.cfg.MixChangeAccount != "" {
mixAccount, err := w.AccountNumber(ctx, s.cfg.MixAccount)
if err != nil {
return "", err
Expand Down Expand Up @@ -3531,7 +3531,7 @@ func (s *Server) sendPairs(ctx context.Context, w *wallet.Wallet, amounts map[st
// returned in dcrjson.RPCError format
func (s *Server) sendAmountToTreasury(ctx context.Context, w *wallet.Wallet, amount dcrutil.Amount, account uint32, minconf int32) (string, error) {
changeAccount := account
if s.cfg.Mixing {
if s.cfg.MixingEnabled {
mixAccount, err := w.AccountNumber(ctx, s.cfg.MixAccount)
if err != nil {
return "", err
Expand Down Expand Up @@ -5505,7 +5505,7 @@ func (s *Server) mixOutput(ctx context.Context, icmd any) (any, error) {
}

func (s *Server) mixAccount(ctx context.Context, icmd any) (any, error) {
if !s.cfg.Mixing {
if !s.cfg.MixingEnabled {
return nil, errors.E("Mixing is not configured")
}
w, ok := s.walletLoader.LoadedWallet()
Expand Down
2 changes: 1 addition & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func startRPCServers(walletLoader *loader.Loader) (*grpc.Server, *jsonrpc.Server
Password: pass,
MaxPOSTClients: cfg.LegacyRPCMaxClients,
MaxWebsocketClients: cfg.LegacyRPCMaxWebsockets,
Mixing: cfg.Mixing,
MixingEnabled: cfg.MixingEnabled,
MixAccount: cfg.mixedAccount,
MixBranch: cfg.mixedBranch,
MixChangeAccount: cfg.ChangeAccount,
Expand Down
4 changes: 2 additions & 2 deletions wallet/mixing.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (w *Wallet) MixOutput(ctx context.Context, output *wire.OutPoint, changeAcc
op := errors.Opf("wallet.MixOutput(%v)", output)

// Mixing requests require wallet mixing support.
if !w.mixing {
if !w.mixingEnabled {
s := "wallet mixing support is disabled"
return errors.E(op, errors.Invalid, s)
}
Expand Down Expand Up @@ -454,7 +454,7 @@ func (w *Wallet) MixAccount(ctx context.Context, changeAccount, mixAccount,
const op errors.Op = "wallet.MixAccount"

// Mixing requests require wallet mixing support.
if !w.mixing {
if !w.mixingEnabled {
s := "wallet mixing support is disabled"
return errors.E(op, errors.Invalid, s)
}
Expand Down
1 change: 1 addition & 0 deletions wallet/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var basicWalletConfig = Config{
GapLimit: 20,
RelayFee: dcrutil.Amount(1e5),
Params: chaincfg.SimNetParams(),
MixingEnabled: true,
}

func testWallet(ctx context.Context, t *testing.T, cfg *Config, seed []byte) (w *Wallet, teardown func()) {
Expand Down
22 changes: 11 additions & 11 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ type Wallet struct {
passphraseTimeoutCancel chan struct{}

// Mixing
mixing bool
mixpool *mixpool.Pool
mixSems mixSemaphores
mixClient *mixclient.Client
mixingEnabled bool
mixpool *mixpool.Pool
mixSems mixSemaphores
mixClient *mixclient.Client

// Cached Blake3 anchor candidate
cachedBlake3WorkDiffCandidateAnchor *wire.BlockHeader
Expand Down Expand Up @@ -190,7 +190,7 @@ type Config struct {
AccountGapLimit int
MixSplitLimit int
DisableCoinTypeUpgrades bool
DisableMixing bool
MixingEnabled bool

ManualTickets bool
AllowHighFees bool
Expand Down Expand Up @@ -1599,7 +1599,7 @@ func (w *Wallet) PurchaseTickets(ctx context.Context, n NetworkBackend,
// Do not attempt to split utxos for a fee payment when spending from
// the mixed account. This error is rather unlikely anyways, as mixed
// accounts probably have very many outputs.
if req.Mixing && !w.mixing {
if req.Mixing && !w.mixingEnabled {
s := "wallet mixing support is disabled"
return nil, errors.E(op, errors.Invalid, s)
}
Expand Down Expand Up @@ -5409,8 +5409,8 @@ func Open(ctx context.Context, cfg *Config) (*Wallet, error) {

addressBuffers: make(map[uint32]*bip0044AccountData),

mixSems: newMixSemaphores(cfg.MixSplitLimit),
mixing: !cfg.DisableMixing,
mixSems: newMixSemaphores(cfg.MixSplitLimit),
mixingEnabled: cfg.MixingEnabled,

vspClients: make(map[string]*VSPClient),

Expand Down Expand Up @@ -5515,7 +5515,7 @@ func Open(ctx context.Context, cfg *Config) (*Wallet, error) {
// Record current tip as initialHeight.
_, w.initialHeight = w.MainChainTip(ctx)

if w.mixing {
if w.mixingEnabled {
w.mixpool = mixpool.NewPool((*mixpoolBlockchain)(w))
w.mixClient = mixclient.NewClient((*mixingWallet)(w))
w.mixClient.SetLogger(loggers.MixcLog)
Expand All @@ -5527,12 +5527,12 @@ func Open(ctx context.Context, cfg *Config) (*Wallet, error) {
// MixingEnabled returns whether the wallet is enabled for mixing and is
// running the mixing client.
func (w *Wallet) MixingEnabled() bool {
return w.mixing
return w.mixingEnabled
}

// Run executes any necessary background goroutines for the wallet.
func (w *Wallet) Run(ctx context.Context) error {
if w.mixing {
if w.mixingEnabled {
return w.mixClient.Run(ctx)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion walletsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func createWallet(ctx context.Context, cfg *config) error {
dbDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
loader := loader.NewLoader(activeNet.Params, dbDir, cfg.EnableVoting,
cfg.GapLimit, cfg.WatchLast, cfg.AllowHighFees, cfg.RelayFee.Amount,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, !cfg.Mixing,
cfg.AccountGapLimit, cfg.DisableCoinTypeUpgrades, cfg.MixingEnabled,
cfg.ManualTickets, cfg.MixSplitLimit, cfg.dial)

var privPass, pubPass, seed []byte
Expand Down

0 comments on commit b402438

Please sign in to comment.