MCPcopy Create free account
hub / github.com/ElementsProject/elements / invalidateblock

Function invalidateblock

src/rpc/blockchain.cpp:2091–2130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2089}
2090
2091static RPCHelpMan invalidateblock()
2092{
2093 return RPCHelpMan{"invalidateblock",
2094 "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n",
2095 {
2096 {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as invalid"},
2097 },
2098 RPCResult{RPCResult::Type::NONE, "", ""},
2099 RPCExamples{
2100 HelpExampleCli("invalidateblock", "\"blockhash\"")
2101 + HelpExampleRpc("invalidateblock", "\"blockhash\"")
2102 },
2103 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2104{
2105 uint256 hash(ParseHashV(request.params[0], "blockhash"));
2106 BlockValidationState state;
2107
2108 ChainstateManager& chainman = EnsureAnyChainman(request.context);
2109 CBlockIndex* pblockindex;
2110 {
2111 LOCK(cs_main);
2112 pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
2113 if (!pblockindex) {
2114 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
2115 }
2116 }
2117 chainman.ActiveChainstate().InvalidateBlock(state, pblockindex);
2118
2119 if (state.IsValid()) {
2120 chainman.ActiveChainstate().ActivateBestChain(state);
2121 }
2122
2123 if (!state.IsValid()) {
2124 throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
2125 }
2126
2127 return NullUniValue;
2128},
2129 };
2130}
2131
2132static RPCHelpMan reconsiderblock()
2133{

Callers

nothing calls this directly

Calls 9

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHashVFunction · 0.85
JSONRPCErrorFunction · 0.85
LookupBlockIndexMethod · 0.80
InvalidateBlockMethod · 0.80
ActivateBestChainMethod · 0.80
IsValidMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected