diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2024-03-02 16:37:00 +0100 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2024-09-01 20:56:37 +0200 |
commit | 446ce51c21cd2466cb12fa0166fd069d42b603bf (patch) | |
tree | 48bf48f16514ede12a49d7f2d654420081d79a2f /src/rpc | |
parent | 5abb9b1af49be9024f95fa2f777285c531785d85 (diff) |
RPC: Extract InvalidateBlock helper
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/blockchain.cpp | 42 |
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; }, |