Page MenuHomePhabricator

D17948.id53541.diff
No OneTemporary

D17948.id53541.diff

diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -228,6 +228,9 @@
//! Check if any block has been pruned.
virtual bool havePruned() = 0;
+ //! Get the current prune height.
+ virtual std::optional<int> getPruneHeight() = 0;
+
//! Check if the node is ready to broadcast transactions.
virtual bool isReadyToBroadcast() = 0;
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -27,6 +27,7 @@
#include <policy/settings.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
+#include <rpc/blockchain.h>
#include <rpc/protocol.h>
#include <rpc/server.h>
#include <shutdown.h>
@@ -716,6 +717,11 @@
return !chainman().m_blockman.LoadingBlocks() &&
!isInitialBlockDownload();
}
+ std::optional<int> getPruneHeight() override {
+ LOCK(chainman().GetMutex());
+ return GetPruneHeight(chainman().m_blockman,
+ chainman().ActiveChain());
+ }
bool isInitialBlockDownload() override {
return chainman().IsInitialBlockDownload();
}
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -3756,14 +3756,29 @@
}
}
- // We can't rescan beyond non-pruned blocks, stop and throw an
- // error
+ // We can't rescan unavailable blocks, stop and throw an error
if (!pwallet->chain().hasBlocks(pwallet->GetLastBlockHash(),
start_height, stop_height)) {
+ if (pwallet->chain().havePruned() &&
+ pwallet->chain().getPruneHeight() >= start_height) {
+ throw JSONRPCError(RPC_MISC_ERROR,
+ "Can't rescan beyond pruned data. "
+ "Use RPC call getblockchaininfo to "
+ "determine your pruned height.");
+ }
+ if (pwallet->chain().hasAssumedValidChain()) {
+ throw JSONRPCError(
+ RPC_MISC_ERROR,
+ "Failed to rescan unavailable blocks likely due to "
+ "an in-progress assumeutxo background sync. Check "
+ "logs or getchainstates RPC for assumeutxo "
+ "background sync progress and try again later.");
+ }
throw JSONRPCError(
RPC_MISC_ERROR,
- "Can't rescan beyond pruned data. Use RPC call "
- "getblockchaininfo to determine your pruned height.");
+ "Failed to rescan unavailable blocks, potentially "
+ "caused by data corruption. If the issue persists you "
+ "may want to reindex (see -reindex option).");
}
CHECK_NONFATAL(pwallet->chain().findAncestorByHeight(
diff --git a/test/functional/wallet_assumeutxo.py b/test/functional/wallet_assumeutxo.py
--- a/test/functional/wallet_assumeutxo.py
+++ b/test/functional/wallet_assumeutxo.py
@@ -172,10 +172,10 @@
"backup_w2.dat",
)
+ wallet_name = "w1"
+ n1.createwallet(wallet_name, disable_private_keys=True)
if self.options.descriptors:
self.log.info("Test loading descriptors during background sync")
- wallet_name = "w1"
- n1.createwallet(wallet_name, disable_private_keys=True)
key = get_generate_key()
time = n1.getblockchaininfo()["time"]
timestamp = 0
@@ -192,6 +192,17 @@
assert_equal(result[0]["error"]["code"], -1)
assert_equal(result[0]["error"]["message"], expected_error_message)
+ self.log.info(
+ "Test that rescanning blocks from before the snapshot fails when blocks are not available from the background sync yet"
+ )
+ w1 = n1.get_wallet_rpc(wallet_name)
+ assert_raises_rpc_error(
+ -1,
+ "Failed to rescan unavailable blocks likely due to an in-progress assumeutxo background sync. Check logs or getchainstates RPC for assumeutxo background sync progress and try again later.",
+ w1.rescanblockchain,
+ 100,
+ )
+
PAUSE_HEIGHT = FINAL_HEIGHT - 40
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 26, 10:34 (5 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573272
Default Alt Text
D17948.id53541.diff (4 KB)

Event Timeline