Skip to content

Commit 9d2d9f7

Browse files
committed
rpc: Include assumeutxo as a failure reason of rescanblockchain
1 parent 595edee commit 9d2d9f7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/wallet/rpc/transactions.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <key_io.h>
77
#include <policy/rbf.h>
88
#include <rpc/util.h>
9+
#include <rpc/blockchain.h>
910
#include <util/vector.h>
1011
#include <wallet/receive.h>
1112
#include <wallet/rpc/util.h>
@@ -909,9 +910,15 @@ RPCHelpMan rescanblockchain()
909910
}
910911
}
911912

912-
// We can't rescan beyond non-pruned blocks, stop and throw an error
913+
// We can't rescan unavailable blocks, stop and throw an error
913914
if (!pwallet->chain().hasBlocks(pwallet->GetLastBlockHash(), start_height, stop_height)) {
914-
throw JSONRPCError(RPC_MISC_ERROR, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height.");
915+
if (pwallet->chain().havePruned() && pwallet->chain().getPruneHeight() >= start_height) {
916+
throw JSONRPCError(RPC_MISC_ERROR, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height.");
917+
}
918+
if (pwallet->chain().hasAssumedValidChain()) {
919+
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.");
920+
}
921+
throw JSONRPCError(RPC_MISC_ERROR, "Failed to rescan unavailable blocks, potentially caused by data corruption. If the issue persists you may want to reindex (see -reindex option).");
915922
}
916923

917924
CHECK_NONFATAL(pwallet->chain().findAncestorByHeight(pwallet->GetLastBlockHash(), start_height, FoundBlock().hash(start_block)));

test/functional/wallet_assumeutxo.py

+4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def run_test(self):
176176
assert_equal(result[0]['error']['code'], -1)
177177
assert_equal(result[0]['error']['message'], expected_error_message)
178178

179+
self.log.info("Test that rescanning blocks from before the snapshot fails when blocks are not available from the background sync yet")
180+
w1 = n1.get_wallet_rpc(wallet_name)
181+
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)
182+
179183
PAUSE_HEIGHT = FINAL_HEIGHT - 40
180184

181185
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)

0 commit comments

Comments
 (0)