Skip to content

Commit d73ae60

Browse files
committed
rpc: Improve importdescriptor RPC error messages
Particularly add more details in the case of pruning or assumeutxo.
1 parent 27f99b6 commit d73ae60

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,20 +1745,27 @@ RPCHelpMan importdescriptors()
17451745
if (scanned_time <= GetImportTimestamp(request, now) || results.at(i).exists("error")) {
17461746
response.push_back(results.at(i));
17471747
} else {
1748+
std::string error_msg{strprintf("Rescan failed for descriptor with timestamp %d. There "
1749+
"was an error reading a block from time %d, which is after or within %d seconds "
1750+
"of key creation, and could contain transactions pertaining to the desc. As a "
1751+
"result, transactions and coins using this desc may not appear in the wallet.",
1752+
GetImportTimestamp(request, now), scanned_time - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)};
1753+
if (pwallet->chain().havePruned()) {
1754+
error_msg += strprintf(" This error could be caused by pruning or data corruption "
1755+
"(see bitcoind log for details) and could be dealt with by downloading and "
1756+
"rescanning the relevant blocks (see -reindex option and rescanblockchain RPC).");
1757+
} else if (pwallet->chain().hasAssumedValidChain()) {
1758+
error_msg += strprintf(" This error is likely caused by an in-progress assumeutxo "
1759+
"background sync. Check logs or getchainstates RPC for assumeutxo background "
1760+
"sync progress and try again later.");
1761+
} else {
1762+
error_msg += strprintf(" This error could potentially caused by data corruption. If "
1763+
"the issue persists you may want to reindex (see -reindex option).");
1764+
}
1765+
17481766
UniValue result = UniValue(UniValue::VOBJ);
17491767
result.pushKV("success", UniValue(false));
1750-
result.pushKV(
1751-
"error",
1752-
JSONRPCError(
1753-
RPC_MISC_ERROR,
1754-
strprintf("Rescan failed for descriptor with timestamp %d. There was an error reading a "
1755-
"block from time %d, which is after or within %d seconds of key creation, and "
1756-
"could contain transactions pertaining to the desc. As a result, transactions "
1757-
"and coins using this desc may not appear in the wallet. This error could be "
1758-
"caused by pruning or data corruption (see bitcoind log for details) and could "
1759-
"be dealt with by downloading and rescanning the relevant blocks (see -reindex "
1760-
"option and rescanblockchain RPC).",
1761-
GetImportTimestamp(request, now), scanned_time - TIMESTAMP_WINDOW - 1, TIMESTAMP_WINDOW)));
1768+
result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, error_msg));
17621769
response.push_back(std::move(result));
17631770
}
17641771
}

0 commit comments

Comments
 (0)