Skip to content

Commit b922f6b

Browse files
committed
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.
1 parent ce50acc commit b922f6b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,7 @@ static RPCHelpMan scanblocks()
23212321
{RPCResult::Type::ARR, "relevant_blocks", "Blocks that may have matched a scanobject.", {
23222322
{RPCResult::Type::STR_HEX, "blockhash", "A relevant blockhash"},
23232323
}},
2324+
{RPCResult::Type::BOOL, "completed", "true if the scan process was not aborted"}
23242325
}},
23252326
RPCResult{"when action=='status' and a scan is currently in progress", RPCResult::Type::OBJ, "", "", {
23262327
{RPCResult::Type::NUM, "progress", "Approximate percent complete"},
@@ -2358,8 +2359,7 @@ static RPCHelpMan scanblocks()
23582359
// set the abort flag
23592360
g_scanfilter_should_abort_scan = true;
23602361
return true;
2361-
}
2362-
else if (request.params[0].get_str() == "start") {
2362+
} else if (request.params[0].get_str() == "start") {
23632363
BlockFiltersScanReserver reserver;
23642364
if (!reserver.reserve()) {
23652365
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
@@ -2424,12 +2424,13 @@ static RPCHelpMan scanblocks()
24242424
g_scanfilter_should_abort_scan = false;
24252425
g_scanfilter_progress = 0;
24262426
g_scanfilter_progress_height = start_block_height;
2427+
bool completed = true;
24272428

24282429
const CBlockIndex* end_range = nullptr;
24292430
do {
24302431
node.rpc_interruption_point(); // allow a clean shutdown
24312432
if (g_scanfilter_should_abort_scan) {
2432-
LogPrintf("scanblocks RPC aborted at height %d.\n", end_range->nHeight);
2433+
completed = false;
24332434
break;
24342435
}
24352436

@@ -2453,7 +2454,6 @@ static RPCHelpMan scanblocks()
24532454
}
24542455

24552456
blocks.push_back(filter.GetBlockHash().GetHex());
2456-
LogPrint(BCLog::RPC, "scanblocks: found match in %s\n", filter.GetBlockHash().GetHex());
24572457
}
24582458
}
24592459
}
@@ -2472,8 +2472,9 @@ static RPCHelpMan scanblocks()
24722472
} while (start_index != stop_block);
24732473

24742474
ret.pushKV("from_height", start_block_height);
2475-
ret.pushKV("to_height", stop_block->nHeight);
2475+
ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here
24762476
ret.pushKV("relevant_blocks", blocks);
2477+
ret.pushKV("completed", completed);
24772478
}
24782479
else {
24792480
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid action '%s'", request.params[0].get_str()));

test/functional/rpc_scanblocks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def run_test(self):
4848
assert blockhash in out['relevant_blocks']
4949
assert_equal(height, out['to_height'])
5050
assert_equal(0, out['from_height'])
51+
assert_equal(True, out['completed'])
5152

5253
# mine another block
5354
blockhash_new = self.generate(node, 1)[0]

0 commit comments

Comments
 (0)