aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/blockchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r--src/rpc/blockchain.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index b449444aff..4da26e84bd 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1577,28 +1577,12 @@ static RPCHelpMan preciousblock()
};
}
-static RPCHelpMan invalidateblock()
-{
- return RPCHelpMan{"invalidateblock",
- "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n",
- {
- {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"},
- },
- RPCResult{RPCResult::Type::NONE, "", ""},
- RPCExamples{
- HelpExampleCli("invalidateblock", "\"blockhash\"")
- + HelpExampleRpc("invalidateblock", "\"blockhash\"")
- },
- [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
-{
- uint256 hash(ParseHashV(request.params[0], "blockhash"));
+void InvalidateBlock(ChainstateManager& chainman, const uint256 block_hash) {
BlockValidationState state;
-
- ChainstateManager& chainman = EnsureAnyChainman(request.context);
CBlockIndex* pblockindex;
{
- LOCK(cs_main);
- pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
+ LOCK(chainman.GetMutex());
+ pblockindex = chainman.m_blockman.LookupBlockIndex(block_hash);
if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
@@ -1612,6 +1596,26 @@ static RPCHelpMan invalidateblock()
if (!state.IsValid()) {
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
}
+}
+
+static RPCHelpMan invalidateblock()
+{
+ return RPCHelpMan{"invalidateblock",
+ "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n",
+ {
+ {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"},
+ },
+ RPCResult{RPCResult::Type::NONE, "", ""},
+ RPCExamples{
+ HelpExampleCli("invalidateblock", "\"blockhash\"")
+ + HelpExampleRpc("invalidateblock", "\"blockhash\"")
+ },
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
+{
+ ChainstateManager& chainman = EnsureAnyChainman(request.context);
+ uint256 hash(ParseHashV(request.params[0], "blockhash"));
+
+ InvalidateBlock(chainman, hash);
return UniValue::VNULL;
},