aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorMartin Zumsande <mzumsande@gmail.com>2022-04-25 22:38:59 +0200
committerMartin Zumsande <mzumsande@gmail.com>2022-04-26 10:12:46 +0200
commit2052e3aa9aa666bdc86dac370f1dd8fb978d3497 (patch)
tree6f871593335148c79ba80325a9b6ebd37bf35eba /src/wallet
parent1e7db37e76c510d373c4404eea2b97508b367aca (diff)
wallet: ignore chainStateFlushed notifications while attaching chain
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp9
-rw-r--r--src/wallet/wallet.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 0d7075810d..34247d14e3 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -523,6 +523,11 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
void CWallet::chainStateFlushed(const CBlockLocator& loc)
{
+ // Don't update the best block until the chain is attached so that in case of a shutdown,
+ // the rescan will be restarted at next startup.
+ if (m_attaching_chain) {
+ return;
+ }
WalletBatch batch(GetDatabase());
batch.WriteBestBlock(loc);
}
@@ -2940,6 +2945,8 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
// be pending on the validation-side until lock release. It's likely to have
// block processing duplicata (if rescan block range overlaps with notification one)
// but we guarantee at least than wallet state is correct after notifications delivery.
+ // However, chainStateFlushed notifications are ignored until the rescan is finished
+ // so that in case of a shutdown event, the rescan will be repeated at the next start.
// This is temporary until rescan and notifications delivery are unified under same
// interface.
walletInstance->m_chain_notifications_handler = walletInstance->chain().handleNotifications(walletInstance);
@@ -2968,6 +2975,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
if (tip_height && *tip_height != rescan_height)
{
+ walletInstance->m_attaching_chain = true; //ignores chainStateFlushed notifications
if (chain.havePruned()) {
int block_height = *tip_height;
while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) {
@@ -3007,6 +3015,7 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf
return false;
}
}
+ walletInstance->m_attaching_chain = false;
walletInstance->chainStateFlushed(chain.getTipLocator());
walletInstance->GetDatabase().IncrementUpdateCounter();
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 26b7f97b5f..80b6845ae6 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -237,6 +237,7 @@ private:
std::atomic<bool> fAbortRescan{false};
std::atomic<bool> fScanningWallet{false}; // controlled by WalletRescanReserver
+ std::atomic<bool> m_attaching_chain{false};
std::atomic<int64_t> m_scanning_start{0};
std::atomic<double> m_scanning_progress{0};
friend class WalletRescanReserver;