mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
rpc: scanblocks, add "completed" flag to the result obj
To tell the user whether the process was aborted or not. Plus, as the process can be aborted prior to the end range, have also changed the "to_height" result value to return the last scanned block instead of the end range block.
This commit is contained in:
parent
ce50acc54f
commit
b922f6b526
2 changed files with 7 additions and 5 deletions
|
@ -2321,6 +2321,7 @@ static RPCHelpMan scanblocks()
|
||||||
{RPCResult::Type::ARR, "relevant_blocks", "Blocks that may have matched a scanobject.", {
|
{RPCResult::Type::ARR, "relevant_blocks", "Blocks that may have matched a scanobject.", {
|
||||||
{RPCResult::Type::STR_HEX, "blockhash", "A relevant blockhash"},
|
{RPCResult::Type::STR_HEX, "blockhash", "A relevant blockhash"},
|
||||||
}},
|
}},
|
||||||
|
{RPCResult::Type::BOOL, "completed", "true if the scan process was not aborted"}
|
||||||
}},
|
}},
|
||||||
RPCResult{"when action=='status' and a scan is currently in progress", RPCResult::Type::OBJ, "", "", {
|
RPCResult{"when action=='status' and a scan is currently in progress", RPCResult::Type::OBJ, "", "", {
|
||||||
{RPCResult::Type::NUM, "progress", "Approximate percent complete"},
|
{RPCResult::Type::NUM, "progress", "Approximate percent complete"},
|
||||||
|
@ -2358,8 +2359,7 @@ static RPCHelpMan scanblocks()
|
||||||
// set the abort flag
|
// set the abort flag
|
||||||
g_scanfilter_should_abort_scan = true;
|
g_scanfilter_should_abort_scan = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (request.params[0].get_str() == "start") {
|
||||||
else if (request.params[0].get_str() == "start") {
|
|
||||||
BlockFiltersScanReserver reserver;
|
BlockFiltersScanReserver reserver;
|
||||||
if (!reserver.reserve()) {
|
if (!reserver.reserve()) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
||||||
|
@ -2424,12 +2424,13 @@ static RPCHelpMan scanblocks()
|
||||||
g_scanfilter_should_abort_scan = false;
|
g_scanfilter_should_abort_scan = false;
|
||||||
g_scanfilter_progress = 0;
|
g_scanfilter_progress = 0;
|
||||||
g_scanfilter_progress_height = start_block_height;
|
g_scanfilter_progress_height = start_block_height;
|
||||||
|
bool completed = true;
|
||||||
|
|
||||||
const CBlockIndex* end_range = nullptr;
|
const CBlockIndex* end_range = nullptr;
|
||||||
do {
|
do {
|
||||||
node.rpc_interruption_point(); // allow a clean shutdown
|
node.rpc_interruption_point(); // allow a clean shutdown
|
||||||
if (g_scanfilter_should_abort_scan) {
|
if (g_scanfilter_should_abort_scan) {
|
||||||
LogPrintf("scanblocks RPC aborted at height %d.\n", end_range->nHeight);
|
completed = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2453,7 +2454,6 @@ static RPCHelpMan scanblocks()
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks.push_back(filter.GetBlockHash().GetHex());
|
blocks.push_back(filter.GetBlockHash().GetHex());
|
||||||
LogPrint(BCLog::RPC, "scanblocks: found match in %s\n", filter.GetBlockHash().GetHex());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2472,8 +2472,9 @@ static RPCHelpMan scanblocks()
|
||||||
} while (start_index != stop_block);
|
} while (start_index != stop_block);
|
||||||
|
|
||||||
ret.pushKV("from_height", start_block_height);
|
ret.pushKV("from_height", start_block_height);
|
||||||
ret.pushKV("to_height", stop_block->nHeight);
|
ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here
|
||||||
ret.pushKV("relevant_blocks", blocks);
|
ret.pushKV("relevant_blocks", blocks);
|
||||||
|
ret.pushKV("completed", completed);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", request.params[0].get_str()));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", request.params[0].get_str()));
|
||||||
|
|
|
@ -48,6 +48,7 @@ class ScanblocksTest(BitcoinTestFramework):
|
||||||
assert blockhash in out['relevant_blocks']
|
assert blockhash in out['relevant_blocks']
|
||||||
assert_equal(height, out['to_height'])
|
assert_equal(height, out['to_height'])
|
||||||
assert_equal(0, out['from_height'])
|
assert_equal(0, out['from_height'])
|
||||||
|
assert_equal(True, out['completed'])
|
||||||
|
|
||||||
# mine another block
|
# mine another block
|
||||||
blockhash_new = self.generate(node, 1)[0]
|
blockhash_new = self.generate(node, 1)[0]
|
||||||
|
|
Loading…
Add table
Reference in a new issue