From b6dbbf3a5ce237321ccbbb6b0b836bd70dca913d Mon Sep 17 00:00:00 2001 From: random-zebra Date: Fri, 23 Apr 2021 17:30:58 +0200 Subject: [PATCH] wallet: Forbid -salvagewallet, -zapwallettxes, and -upgradewallet with multiple wallets >>> backports bitcoin@9cbe8c80bad1b55557a91db65a06b66ec4743f18 --- src/init.cpp | 18 ------------------ src/wallet/wallet.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f427a3856a9a5..6c748bd99973c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -936,24 +936,6 @@ void InitParameterInteraction() if (gArgs.SoftSetBoolArg("-discover", false)) LogPrintf("%s : parameter interaction: -externalip set -> setting -discover=0\n", __func__); } - - if (gArgs.GetBoolArg("-salvagewallet", false)) { - // Rewrite just private keys: rescan to find transactions - if (gArgs.SoftSetBoolArg("-rescan", true)) - LogPrintf("%s : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__); - } - - int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0); - // -zapwallettxes implies dropping the mempool on startup - if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) { - LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes); - } - - // -zapwallettxes implies a rescan - if (zapwallettxes != 0) { - if (gArgs.SoftSetBoolArg("-rescan", true)) - LogPrintf("%s : parameter interaction: -zapwallettxes=%s -> setting -rescan=1\n", __func__, zapwallettxes); - } } bool InitNUParams() diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8ddf6f75adce8..2d562c1881a28 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -654,6 +654,37 @@ bool CWallet::ParameterInteraction() return UIError("-sysperms is not allowed in combination with enabled wallet functionality"); } + gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT); + const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1; + + if (gArgs.GetBoolArg("-salvagewallet", false) && gArgs.SoftSetBoolArg("-rescan", true)) { + if (is_multiwallet) { + return UIError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet")); + } + // Rewrite just private keys: rescan to find transactions + LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__); + } + + int zapwallettxes = gArgs.GetArg("-zapwallettxes", 0); + // -zapwallettxes implies dropping the mempool on startup + if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-persistmempool", false)) { + LogPrintf("%s: parameter interaction: -zapwallettxes=%s -> setting -persistmempool=0\n", __func__, zapwallettxes); + } + + // -zapwallettxes implies a rescan + if (zapwallettxes != 0 && gArgs.SoftSetBoolArg("-rescan", true)) { + if (is_multiwallet) { + return UIError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes")); + } + LogPrintf("%s: parameter interaction: -zapwallettxes= -> setting -rescan=1\n", __func__); + } + + if (is_multiwallet) { + if (gArgs.GetBoolArg("-upgradewallet", false)) { + return UIError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet")); + } + } + if (gArgs.IsArgSet("-mintxfee")) { CAmount n = 0; if (ParseMoney(gArgs.GetArg("-mintxfee", ""), n) && n > 0) @@ -2080,7 +2111,6 @@ bool CWallet::Verify() return true; } - gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT); uiInterface.InitMessage(_("Verifying wallet(s)...")); for (const std::string& walletFile : gArgs.GetArgs("-wallet")) {