diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index dc5d89b0b9..cd3ca32cda 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -290,6 +290,9 @@ public: //! 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; + // ELEMENTS virtual CBlockIndex* getTip() = 0; virtual MempoolAcceptResult testPeginClaimAcceptance(const CTransactionRef tx) = 0; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index d8bd24e036..4731e81bbc 100755 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -776,6 +776,11 @@ public: notifications.transactionAddedToMempool(entry.GetSharedTx(), 0 /* mempool_sequence */); } } + bool hasAssumedValidChain() override + { + return Assert(m_node.chainman)->IsSnapshotActive(); + } + // ELEMENTS MempoolAcceptResult testPeginClaimAcceptance(const CTransactionRef tx) override { LOCK(::cs_main); @@ -792,6 +797,7 @@ public: return TestBlockValidity(state, chainparams, m_node.chainman->ActiveChainstate(), block, pindexPrev, GetAdjustedTime, fCheckPOW, fCheckMerkleRoot); } // end ELEMENTS + NodeContext& m_node; }; } // namespace diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index cbb6a67c6b..6495d4066c 100755 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3286,20 +3286,31 @@ bool CWallet::AttachChain(const std::shared_ptr& 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; } }