mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
wallet: fix ancient wallets migration
The best block locator was introduced in #152, previously created wallets do not have these record.
This commit is contained in:
@@ -3950,10 +3950,9 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
|
||||
}
|
||||
|
||||
// Get best block locator so that we can copy it to the watchonly and solvables
|
||||
// Note: The best block locator was introduced in #152 so ancient wallets do not have it
|
||||
CBlockLocator best_block_locator;
|
||||
if (!local_wallet_batch.ReadBestBlock(best_block_locator)) {
|
||||
return util::Error{_("Error: Unable to read wallet's best block locator record")};
|
||||
}
|
||||
(void)local_wallet_batch.ReadBestBlock(best_block_locator);
|
||||
|
||||
// Update m_txos to match the descriptors remaining in this wallet
|
||||
m_txos.clear();
|
||||
@@ -3970,7 +3969,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
|
||||
LOCK(data.watchonly_wallet->cs_wallet);
|
||||
data.watchonly_wallet->nOrderPosNext = nOrderPosNext;
|
||||
watchonly_batch->WriteOrderPosNext(data.watchonly_wallet->nOrderPosNext);
|
||||
// Write the best block locator to avoid rescanning on reload
|
||||
// Write the locator record. An empty locator is valid and triggers rescan on load.
|
||||
if (!watchonly_batch->WriteBestBlock(best_block_locator)) {
|
||||
return util::Error{_("Error: Unable to write watchonly wallet best block locator record")};
|
||||
}
|
||||
@@ -3979,7 +3978,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
|
||||
if (data.solvable_wallet) {
|
||||
solvables_batch = std::make_unique<WalletBatch>(data.solvable_wallet->GetDatabase());
|
||||
if (!solvables_batch->TxnBegin()) return util::Error{strprintf(_("Error: database transaction cannot be executed for wallet %s"), data.solvable_wallet->GetName())};
|
||||
// Write the best block locator to avoid rescanning on reload
|
||||
// Write the locator record. An empty locator is valid and triggers rescan on load.
|
||||
if (!solvables_batch->WriteBestBlock(best_block_locator)) {
|
||||
return util::Error{_("Error: Unable to write solvable wallet best block locator record")};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user