Skip to content

Commit 571bb94

Browse files
committed
Merge bitcoin/bitcoin#23123: Remove -rescan startup parameter
dc3ec74 Add rescan removal release note (Samuel Dobson) bccd1d9 Remove -rescan startup parameter (Samuel Dobson) f963b0f Corrupt wallet tx shouldn't trigger rescan of all wallets (Samuel Dobson) 6c00649 Remove outdated dummy wallet -salvagewallet arg (Samuel Dobson) Pull request description: Remove the `-rescan` startup parameter. Rescans can be run with the `rescanblockchain` RPC. Rescans are still done on wallet-load if needed due to corruption, for example. ACKs for top commit: achow101: ACK dc3ec74 laanwj: re-ACK dc3ec74 Tree-SHA512: 608360d0e7d73737fd3ef408b01b33d97a75eebccd70c6d1b47a32fecb99b9105b520b111b225beb10611c09aa840a2b6d2b6e6e54be5d0362829e757289de5c
2 parents 9013f23 + dc3ec74 commit 571bb94

17 files changed

+56
-46
lines changed

doc/release-notes-remove-rescan.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Notable changes
2+
===============
3+
4+
Rescan startup parameter removed
5+
--------------------------------
6+
7+
The `-rescan` startup parameter has been removed. Wallets which require
8+
rescanning due to corruption will still be rescanned on startup.
9+
Otherwise, please use the `rescanblockchain` RPC to trigger a rescan.

share/examples/bitcoin.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
#coinstatsindex=1
158158

159159
# Enable pruning to reduce storage requirements by deleting old blocks.
160-
# This mode is incompatible with -txindex, -coinstatsindex and -rescan.
160+
# This mode is incompatible with -txindex and -coinstatsindex.
161161
# 0 = default (no pruning).
162162
# 1 = allows manual pruning via RPC.
163163
# >=550 = target to stay under in MiB.

src/dummywallet.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
3939
"-maxtxfee=<amt>",
4040
"-mintxfee=<amt>",
4141
"-paytxfee=<amt>",
42-
"-rescan",
43-
"-salvagewallet",
4442
"-signer=<cmd>",
4543
"-spendzeroconfchange",
4644
"-txconfirmtarget=<n>",

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void SetupServerArgs(ArgsManager& argsman)
397397
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
398398
argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
399399
argsman.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
400-
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex, -coinstatsindex and -rescan. "
400+
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex and -coinstatsindex. "
401401
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
402402
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
403403
argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);

src/wallet/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
6262
CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6363
argsman.AddArg("-paytxfee=<amt>", strprintf("Fee rate (in %s/kvB) to add to transactions you send (default: %s)",
6464
CURRENCY_UNIT, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
65-
argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6665
#ifdef ENABLE_EXTERNAL_SIGNER
6766
argsman.AddArg("-signer=<cmd>", "External signing tool, see doc/external-signer.md", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
6867
#endif

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ RPCHelpMan importmulti()
14391439
"and coins using this key may not appear in the wallet. This error could be "
14401440
"caused by pruning or data corruption (see bitcoind log for details) and could "
14411441
"be dealt with by downloading and rescanning the relevant blocks (see -reindex "
1442-
"and -rescan options).",
1442+
"option and rescanblockchain RPC).",
14431443
GetImportTimestamp(request, now), scannedTime - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)));
14441444
response.push_back(std::move(result));
14451445
}
@@ -1744,7 +1744,7 @@ RPCHelpMan importdescriptors()
17441744
"and coins using this desc may not appear in the wallet. This error could be "
17451745
"caused by pruning or data corruption (see bitcoind log for details) and could "
17461746
"be dealt with by downloading and rescanning the relevant blocks (see -reindex "
1747-
"and -rescan options).",
1747+
"option and rescanblockchain RPC).",
17481748
GetImportTimestamp(request, now), scanned_time - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)));
17491749
response.push_back(std::move(result));
17501750
}

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ static RPCHelpMan loadwallet()
26322632
return RPCHelpMan{"loadwallet",
26332633
"\nLoads a wallet from a wallet file or directory."
26342634
"\nNote that all wallet command-line options used when starting bitcoind will be"
2635-
"\napplied to the new wallet (eg -rescan, etc).\n",
2635+
"\napplied to the new wallet.\n",
26362636
{
26372637
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet directory or .dat file."},
26382638
{"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED_NAMED_ARG, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."},

src/wallet/salvage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::v
4545
// Call Salvage with fAggressive=true to
4646
// get as much data as possible.
4747
// Rewrite salvaged data to fresh wallet file
48-
// Set -rescan so any missing transactions will be
48+
// Rescan so any missing transactions will be
4949
// found.
5050
int64_t now = GetTime();
5151
std::string newFilename = strprintf("%s.%d.bak", filename, now);

src/wallet/test/wallet_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
232232
"seconds of key creation, and could contain transactions pertaining to the key. As a result, "
233233
"transactions and coins using this key may not appear in the wallet. This error could be caused "
234234
"by pruning or data corruption (see bitcoind log for details) and could be dealt with by "
235-
"downloading and rescanning the relevant blocks (see -reindex and -rescan "
236-
"options).\"}},{\"success\":true}]",
235+
"downloading and rescanning the relevant blocks (see -reindex option and rescanblockchain "
236+
"RPC).\"}},{\"success\":true}]",
237237
0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW));
238238
RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
239239
}

src/wallet/wallet.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
16001600
WalletLogPrintf("Rescan started from block %s...\n", start_block.ToString());
16011601

16021602
fAbortRescan = false;
1603-
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup
1603+
ShowProgress(strprintf("%s " + _("Rescanning…").translated, GetDisplayName()), 0); // show rescan progress in GUI as dialog or on splashscreen, if rescan required on startup (e.g. due to corruption)
16041604
uint256 tip_hash = WITH_LOCK(cs_wallet, return GetLastBlockHash());
16051605
uint256 end_hash = tip_hash;
16061606
if (max_height) chain().findAncestorByHeight(tip_hash, *max_height, FoundBlock().hash(end_hash));
@@ -2007,10 +2007,7 @@ DBErrors CWallet::LoadWallet()
20072007
assert(m_internal_spk_managers.empty());
20082008
}
20092009

2010-
if (nLoadWalletRet != DBErrors::LOAD_OK)
2011-
return nLoadWalletRet;
2012-
2013-
return DBErrors::LOAD_OK;
2010+
return nLoadWalletRet;
20142011
}
20152012

20162013
DBErrors CWallet::ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut)
@@ -2542,6 +2539,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
25422539
// TODO: Can't use std::make_shared because we need a custom deleter but
25432540
// should be possible to use std::allocate_shared.
25442541
std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, std::move(database)), ReleaseWallet);
2542+
bool rescan_required = false;
25452543
DBErrors nLoadWalletRet = walletInstance->LoadWallet();
25462544
if (nLoadWalletRet != DBErrors::LOAD_OK) {
25472545
if (nLoadWalletRet == DBErrors::CORRUPT) {
@@ -2562,6 +2560,10 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
25622560
{
25632561
error = strprintf(_("Wallet needed to be rewritten: restart %s to complete"), PACKAGE_NAME);
25642562
return nullptr;
2563+
} else if (nLoadWalletRet == DBErrors::RESCAN_REQUIRED) {
2564+
warnings.push_back(strprintf(_("Error reading %s! Transaction data may be missing or incorrect."
2565+
" Rescanning wallet."), walletFile));
2566+
rescan_required = true;
25652567
}
25662568
else {
25672569
error = strprintf(_("Error loading %s"), walletFile);
@@ -2753,7 +2755,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
27532755

27542756
LOCK(walletInstance->cs_wallet);
27552757

2756-
if (chain && !AttachChain(walletInstance, *chain, error, warnings)) {
2758+
if (chain && !AttachChain(walletInstance, *chain, rescan_required, error, warnings)) {
27572759
return nullptr;
27582760
}
27592761

@@ -2775,7 +2777,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
27752777
return walletInstance;
27762778
}
27772779

2778-
bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interfaces::Chain& chain, bilingual_str& error, std::vector<bilingual_str>& warnings)
2780+
bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interfaces::Chain& chain, const bool rescan_required, bilingual_str& error, std::vector<bilingual_str>& warnings)
27792781
{
27802782
LOCK(walletInstance->cs_wallet);
27812783
// allow setting the chain if it hasn't been set already but prevent changing it
@@ -2792,8 +2794,9 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
27922794
// interface.
27932795
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
27942796

2797+
// If rescan_required = true, rescan_height remains equal to 0
27952798
int rescan_height = 0;
2796-
if (!gArgs.GetBoolArg("-rescan", false))
2799+
if (!rescan_required)
27972800
{
27982801
WalletBatch batch(walletInstance->GetDatabase());
27992802
CBlockLocator locator;

0 commit comments

Comments
 (0)