mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
Merge 5b2d0216d8
into c5e44a0435
This commit is contained in:
commit
fe8fbcd361
2 changed files with 33 additions and 4 deletions
5
doc/release-notes-30713.md
Normal file
5
doc/release-notes-30713.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Updated RPCs
|
||||||
|
------------
|
||||||
|
|
||||||
|
- The `status` action of the`scanblocks` RPC now returns an additional array `relevant_blocks` containing
|
||||||
|
the matching block hashes found so far during a scan.
|
|
@ -2397,9 +2397,17 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void release() {
|
||||||
|
if (!m_could_reserve) {
|
||||||
|
throw std::runtime_error("Attempt to release unreserved BlockFiltersScanReserver");
|
||||||
|
}
|
||||||
|
g_scanfilter_in_progress = false;
|
||||||
|
m_could_reserve = false;
|
||||||
|
}
|
||||||
|
|
||||||
~BlockFiltersScanReserver() {
|
~BlockFiltersScanReserver() {
|
||||||
if (m_could_reserve) {
|
if (m_could_reserve) {
|
||||||
g_scanfilter_in_progress = false;
|
release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2459,6 +2467,9 @@ static RPCHelpMan scanblocks()
|
||||||
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"},
|
||||||
{RPCResult::Type::NUM, "current_height", "Height of the block currently being scanned"},
|
{RPCResult::Type::NUM, "current_height", "Height of the block currently being scanned"},
|
||||||
|
{RPCResult::Type::ARR, "relevant_blocks", "Blocks that may have matched a scanobject.", {
|
||||||
|
{RPCResult::Type::STR_HEX, "blockhash", "A relevant blockhash"},
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
scan_result_abort,
|
scan_result_abort,
|
||||||
|
@ -2473,15 +2484,20 @@ static RPCHelpMan scanblocks()
|
||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
static GlobalMutex cs_relevant_blocks;
|
||||||
|
static UniValue relevant_blocks GUARDED_BY(cs_relevant_blocks);
|
||||||
|
|
||||||
UniValue ret(UniValue::VOBJ);
|
UniValue ret(UniValue::VOBJ);
|
||||||
if (request.params[0].get_str() == "status") {
|
if (request.params[0].get_str() == "status") {
|
||||||
BlockFiltersScanReserver reserver;
|
BlockFiltersScanReserver reserver;
|
||||||
|
LOCK(cs_relevant_blocks);
|
||||||
if (reserver.reserve()) {
|
if (reserver.reserve()) {
|
||||||
// no scan in progress
|
// no scan in progress
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
ret.pushKV("progress", g_scanfilter_progress.load());
|
ret.pushKV("progress", g_scanfilter_progress.load());
|
||||||
ret.pushKV("current_height", g_scanfilter_progress_height.load());
|
ret.pushKV("current_height", g_scanfilter_progress_height.load());
|
||||||
|
ret.pushKV("relevant_blocks", relevant_blocks);
|
||||||
return ret;
|
return ret;
|
||||||
} else if (request.params[0].get_str() == "abort") {
|
} else if (request.params[0].get_str() == "abort") {
|
||||||
BlockFiltersScanReserver reserver;
|
BlockFiltersScanReserver reserver;
|
||||||
|
@ -2493,6 +2509,11 @@ static RPCHelpMan scanblocks()
|
||||||
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") {
|
||||||
|
{
|
||||||
|
LOCK(cs_relevant_blocks);
|
||||||
|
relevant_blocks = UniValue(UniValue::VARR);
|
||||||
|
}
|
||||||
|
|
||||||
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\"");
|
||||||
|
@ -2548,7 +2569,7 @@ static RPCHelpMan scanblocks()
|
||||||
needle_set.emplace(script.begin(), script.end());
|
needle_set.emplace(script.begin(), script.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UniValue blocks(UniValue::VARR);
|
|
||||||
const int amount_per_chunk = 10000;
|
const int amount_per_chunk = 10000;
|
||||||
std::vector<BlockFilter> filters;
|
std::vector<BlockFilter> filters;
|
||||||
int start_block_height = start_index->nHeight; // for progress reporting
|
int start_block_height = start_index->nHeight; // for progress reporting
|
||||||
|
@ -2586,7 +2607,8 @@ static RPCHelpMan scanblocks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks.push_back(filter.GetBlockHash().GetHex());
|
LOCK(cs_relevant_blocks);
|
||||||
|
relevant_blocks.push_back(filter.GetBlockHash().GetHex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2606,8 +2628,10 @@ static RPCHelpMan scanblocks()
|
||||||
|
|
||||||
ret.pushKV("from_height", start_block_height);
|
ret.pushKV("from_height", start_block_height);
|
||||||
ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here
|
ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here
|
||||||
ret.pushKV("relevant_blocks", std::move(blocks));
|
LOCK(cs_relevant_blocks);
|
||||||
|
ret.pushKV("relevant_blocks", std::move(relevant_blocks));
|
||||||
ret.pushKV("completed", completed);
|
ret.pushKV("completed", completed);
|
||||||
|
reserver.release(); // ensure this is before cs_relevant_blocks is released, so status doesn't try to use moved relevant_blocks
|
||||||
}
|
}
|
||||||
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()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue