diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-07-18 14:27:49 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-07-18 14:39:55 -0400 |
commit | 8d4a058ac421da838422da127aac71abf83a49f6 (patch) | |
tree | b54dac317ea8eadec98e8c8c5276998a2aa43346 | |
parent | 4aaa3b52006efa1049c238f638b6d87668125cbb (diff) | |
parent | 817326a828d6148dc63d9ef08f641b9c0c522411 (diff) | |
download | bitcoin-8d4a058ac421da838422da127aac71abf83a49f6.tar.xz |
Merge bitcoin/bitcoin#23997: wallet: avoid rescans under assumed-valid blocks
817326a828d6148dc63d9ef08f641b9c0c522411 wallet: avoid rescans if under the snapshot (James O'Beirne)
Pull request description:
This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11) (parent PR: #15606)
---
Refuse to load a wallet if it requires a rescan lower than the height of assumed-valid blocks.
Of course in live code right now, `BLOCK_ASSUMED_VALID` block index entries don't exist since they're a unique flag introduced by the use of UTXO snapshots, so this is prophylactic code exercised only by unittests.
ACKs for top commit:
achow101:
ACK 817326a828d6148dc63d9ef08f641b9c0c522411
ryanofsky:
Code review ACK 817326a828d6148dc63d9ef08f641b9c0c522411. This seems like the simplest change we can make to avoid wallet problems when an assumeutxo snapshot is loaded.
Tree-SHA512: cfa44b2eb33d1818d30df45210d0dde1e9b78cc9b7c88cb985054dc28427bba9e0905debe4196065d1d3a5ce7bca7e605e629d5ce5f0225b25395746e6d3d596
-rw-r--r-- | src/interfaces/chain.h | 3 | ||||
-rw-r--r-- | src/node/interfaces.cpp | 5 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 17 |
3 files changed, 22 insertions, 3 deletions
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index df9e55874f..ff994b8edc 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -287,6 +287,9 @@ public: //! to be prepared to handle this by ignoring notifications about unknown //! removed transactions and already added new transactions. virtual void requestMempoolTransactions(Notifications& notifications) = 0; + + //! Return true if an assumed-valid chain is in use. + virtual bool hasAssumedValidChain() = 0; }; //! Interface to let node manage chain clients (wallets, or maybe tools for diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 93aa9e526b..46e0efb9b6 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -775,6 +775,11 @@ public: notifications.transactionAddedToMempool(entry.GetSharedTx(), 0 /* mempool_sequence */); } } + bool hasAssumedValidChain() override + { + return Assert(m_node.chainman)->IsSnapshotActive(); + } + NodeContext& m_node; }; } // namespace diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 69c4e4a2b7..890e171913 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3049,20 +3049,31 @@ bool CWallet::AttachChain(const std::shared_ptr<CWallet>& walletInstance, interf if (tip_height && *tip_height != rescan_height) { - if (chain.havePruned()) { + // Technically we could execute the code below in any case, but performing the + // `while` loop below can make startup very slow, so only check blocks on disk + // if necessary. + if (chain.havePruned() || chain.hasAssumedValidChain()) { int block_height = *tip_height; while (block_height > 0 && chain.haveBlockOnDisk(block_height - 1) && rescan_height != block_height) { --block_height; } if (rescan_height != block_height) { - // We can't rescan beyond non-pruned blocks, stop and throw an error. + // We can't rescan beyond blocks we don't have data for, stop and throw an error. // This might happen if a user uses an old wallet within a pruned node // or if they ran -disablewallet for a longer time, then decided to re-enable // Exit early and print an error. + // It also may happen if an assumed-valid chain is in use and therefore not + // all block data is available. // If a block is pruned after this check, we will load the wallet, // but fail the rescan with a generic error. - error = _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"); + + error = chain.hasAssumedValidChain() ? + _( + "Assumed-valid: last wallet synchronisation goes beyond " + "available block data. You need to wait for the background " + "validation chain to download more blocks.") : + _("Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex (download the whole blockchain again in case of pruned node)"); return false; } } |