Skip to content

Commit d3f04c0

Browse files
committed
Merge #13030: [bugfix] [wallet] Fix zapwallettxes/multiwallet interaction.
1f83839 [wallet] [tests] Test disallowed multiwallet params (John Newbery) 3476e3c [wallet] Fix zapwallettxes/multiwallet interaction. (John Newbery) Pull request description: `-zapwallettxes` should be disallowed when starting bitcoin in multiwallet mode. There's code in `WalletInit::ParameterInteraction()` to disallow `-zapwallettxes` when running in multiwallet mode. This code functioned as expected when passing the parameter `-zapwallettxes=1`, but not when passing the parameter `-zapwallettxes` (ie without the value specified). Fix that and add a test. The new test in the _[wallet] [tests] Test disallowed multiwallet params_ commit reproduces the bug and should fail against master. Fixes #12505 Tree-SHA512: 6cd921717e9c7d2773ca84c946c310c2adec8430e37cbecdb33a620f510db3058a72bd328411812ba415111bc52a3367b332c9d15a37a92ccfd7ae785d2f32ab
2 parents 84efa9a + 1f83839 commit d3f04c0

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/wallet/init.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ bool WalletInit::ParameterInteraction() const
118118
}
119119
}
120120

121-
int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0);
121+
bool zapwallettxes = gArgs.GetBoolArg("-zapwallettxes", false);
122122
// -zapwallettxes implies dropping the mempool on startup
123-
if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) {
124-
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes);
123+
if (zapwallettxes && gArgs.SoftSetBoolArg("-persistmempool", false)) {
124+
LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -persistmempool=0\n", __func__);
125125
}
126126

127127
// -zapwallettxes implies a rescan
128-
if (zapwallettxes != 0) {
128+
if (zapwallettxes) {
129129
if (is_multiwallet) {
130130
return InitError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
131131
}
132132
if (gArgs.SoftSetBoolArg("-rescan", true)) {
133-
LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes);
133+
LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
134134
}
135135
}
136136

test/functional/wallet_multiwallet.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def run_test(self):
9191
open(not_a_dir, 'a').close()
9292
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
9393

94+
self.log.info("Do not allow -zapwallettxes with multiwallet")
95+
self.nodes[0].assert_start_raises_init_error(['-zapwallettxes', '-wallet=w1', '-wallet=w2'], "Error: -zapwallettxes is only allowed with a single wallet file")
96+
self.nodes[0].assert_start_raises_init_error(['-zapwallettxes=1', '-wallet=w1', '-wallet=w2'], "Error: -zapwallettxes is only allowed with a single wallet file")
97+
self.nodes[0].assert_start_raises_init_error(['-zapwallettxes=2', '-wallet=w1', '-wallet=w2'], "Error: -zapwallettxes is only allowed with a single wallet file")
98+
99+
self.log.info("Do not allow -salvagewallet with multiwallet")
100+
self.nodes[0].assert_start_raises_init_error(['-salvagewallet', '-wallet=w1', '-wallet=w2'], "Error: -salvagewallet is only allowed with a single wallet file")
101+
self.nodes[0].assert_start_raises_init_error(['-salvagewallet=1', '-wallet=w1', '-wallet=w2'], "Error: -salvagewallet is only allowed with a single wallet file")
102+
103+
self.log.info("Do not allow -upgradewallet with multiwallet")
104+
self.nodes[0].assert_start_raises_init_error(['-upgradewallet', '-wallet=w1', '-wallet=w2'], "Error: -upgradewallet is only allowed with a single wallet file")
105+
self.nodes[0].assert_start_raises_init_error(['-upgradewallet=1', '-wallet=w1', '-wallet=w2'], "Error: -upgradewallet is only allowed with a single wallet file")
106+
94107
# if wallets/ doesn't exist, datadir should be the default wallet dir
95108
wallet_dir2 = data_dir('walletdir')
96109
os.rename(wallet_dir(), wallet_dir2)

0 commit comments

Comments
 (0)