@@ -1577,28 +1577,12 @@ static RPCHelpMan preciousblock()
1577
1577
};
1578
1578
}
1579
1579
1580
- static RPCHelpMan invalidateblock ()
1581
- {
1582
- return RPCHelpMan{" invalidateblock" ,
1583
- " \n Permanently marks a block as invalid, as if it violated a consensus rule.\n " ,
1584
- {
1585
- {" blockhash" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " the hash of the block to mark as invalid" },
1586
- },
1587
- RPCResult{RPCResult::Type::NONE, " " , " " },
1588
- RPCExamples{
1589
- HelpExampleCli (" invalidateblock" , " \" blockhash\" " )
1590
- + HelpExampleRpc (" invalidateblock" , " \" blockhash\" " )
1591
- },
1592
- [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1593
- {
1594
- uint256 hash (ParseHashV (request.params [0 ], " blockhash" ));
1580
+ void InvalidateBlock (ChainstateManager& chainman, const uint256 block_hash) {
1595
1581
BlockValidationState state;
1596
-
1597
- ChainstateManager& chainman = EnsureAnyChainman (request.context );
1598
1582
CBlockIndex* pblockindex;
1599
1583
{
1600
- LOCK (cs_main );
1601
- pblockindex = chainman.m_blockman .LookupBlockIndex (hash );
1584
+ LOCK (chainman. GetMutex () );
1585
+ pblockindex = chainman.m_blockman .LookupBlockIndex (block_hash );
1602
1586
if (!pblockindex) {
1603
1587
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
1604
1588
}
@@ -1612,6 +1596,26 @@ static RPCHelpMan invalidateblock()
1612
1596
if (!state.IsValid ()) {
1613
1597
throw JSONRPCError (RPC_DATABASE_ERROR, state.ToString ());
1614
1598
}
1599
+ }
1600
+
1601
+ static RPCHelpMan invalidateblock ()
1602
+ {
1603
+ return RPCHelpMan{" invalidateblock" ,
1604
+ " \n Permanently marks a block as invalid, as if it violated a consensus rule.\n " ,
1605
+ {
1606
+ {" blockhash" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " the hash of the block to mark as invalid" },
1607
+ },
1608
+ RPCResult{RPCResult::Type::NONE, " " , " " },
1609
+ RPCExamples{
1610
+ HelpExampleCli (" invalidateblock" , " \" blockhash\" " )
1611
+ + HelpExampleRpc (" invalidateblock" , " \" blockhash\" " )
1612
+ },
1613
+ [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1614
+ {
1615
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
1616
+ uint256 hash (ParseHashV (request.params [0 ], " blockhash" ));
1617
+
1618
+ InvalidateBlock (chainman, hash);
1615
1619
1616
1620
return UniValue::VNULL;
1617
1621
},
0 commit comments