Skip to content

Commit fccf4f9

Browse files
committed
RPC: Extract ReconsiderBlock helper
1 parent 446ce51 commit fccf4f9

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/rpc/blockchain.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,25 @@ static RPCHelpMan invalidateblock()
16221622
};
16231623
}
16241624

1625+
void ReconsiderBlock(ChainstateManager& chainman, uint256 block_hash) {
1626+
{
1627+
LOCK(chainman.GetMutex());
1628+
CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(block_hash);
1629+
if (!pblockindex) {
1630+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1631+
}
1632+
1633+
chainman.ActiveChainstate().ResetBlockFailureFlags(pblockindex);
1634+
}
1635+
1636+
BlockValidationState state;
1637+
chainman.ActiveChainstate().ActivateBestChain(state);
1638+
1639+
if (!state.IsValid()) {
1640+
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
1641+
}
1642+
}
1643+
16251644
static RPCHelpMan reconsiderblock()
16261645
{
16271646
return RPCHelpMan{"reconsiderblock",
@@ -1640,22 +1659,7 @@ static RPCHelpMan reconsiderblock()
16401659
ChainstateManager& chainman = EnsureAnyChainman(request.context);
16411660
uint256 hash(ParseHashV(request.params[0], "blockhash"));
16421661

1643-
{
1644-
LOCK(cs_main);
1645-
CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
1646-
if (!pblockindex) {
1647-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1648-
}
1649-
1650-
chainman.ActiveChainstate().ResetBlockFailureFlags(pblockindex);
1651-
}
1652-
1653-
BlockValidationState state;
1654-
chainman.ActiveChainstate().ActivateBestChain(state);
1655-
1656-
if (!state.IsValid()) {
1657-
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
1658-
}
1662+
ReconsiderBlock(chainman, hash);
16591663

16601664
return UniValue::VNULL;
16611665
},

0 commit comments

Comments
 (0)