Skip to content

Commit 9332c7e

Browse files
committed
wallet: Write bestblock to watchonly and solvable wallets
When migrating, we should also be writing the bestblock record to the watchonly and solvable wallets to avoid rescanning on the reload as that can be slow.
1 parent 5b8c597 commit 9332c7e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/wallet/wallet.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,6 +3927,13 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
39273927
}
39283928
}
39293929

3930+
// Get best block locator so that we can copy it to the watchonly and solvables
3931+
CBlockLocator best_block_locator;
3932+
if (!WalletBatch(GetDatabase()).ReadBestBlock(best_block_locator)) {
3933+
error = _("Error: Unable to read wallet's best block locator record");
3934+
return false;
3935+
}
3936+
39303937
// Check if the transactions in the wallet are still ours. Either they belong here, or they belong in the watchonly wallet.
39313938
// We need to go through these in the tx insertion order so that lookups to spends works.
39323939
std::vector<uint256> txids_to_delete;
@@ -3937,6 +3944,18 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
39373944
LOCK(data.watchonly_wallet->cs_wallet);
39383945
data.watchonly_wallet->nOrderPosNext = nOrderPosNext;
39393946
watchonly_batch->WriteOrderPosNext(data.watchonly_wallet->nOrderPosNext);
3947+
// Write the best block locator to avoid rescanning on reload
3948+
if (!watchonly_batch->WriteBestBlock(best_block_locator)) {
3949+
error = _("Error: Unable to write watchonly wallet best block locator record");
3950+
return false;
3951+
}
3952+
}
3953+
if (data.solvable_wallet) {
3954+
// Write the best block locator to avoid rescanning on reload
3955+
if (!WalletBatch(data.solvable_wallet->GetDatabase()).WriteBestBlock(best_block_locator)) {
3956+
error = _("Error: Unable to write solvable wallet best block locator record");
3957+
return false;
3958+
}
39403959
}
39413960
for (const auto& [_pos, wtx] : wtxOrdered) {
39423961
if (!IsMine(*wtx->tx) && !IsFromMe(*wtx->tx)) {

0 commit comments

Comments
 (0)