mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
wallet: ignore chainStateFlushed notifications while attaching chain
This commit is contained in:
parent
1e7db37e76
commit
2052e3aa9a
2 changed files with 10 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue