mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-24 18:23:26 -03:00
RPC: Extract InvalidateBlock helper
This commit is contained in:
parent
5abb9b1af4
commit
446ce51c21
1 changed files with 23 additions and 19 deletions
|
@ -1577,6 +1577,27 @@ static RPCHelpMan preciousblock()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InvalidateBlock(ChainstateManager& chainman, const uint256 block_hash) {
|
||||||
|
BlockValidationState state;
|
||||||
|
CBlockIndex* pblockindex;
|
||||||
|
{
|
||||||
|
LOCK(chainman.GetMutex());
|
||||||
|
pblockindex = chainman.m_blockman.LookupBlockIndex(block_hash);
|
||||||
|
if (!pblockindex) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chainman.ActiveChainstate().InvalidateBlock(state, pblockindex);
|
||||||
|
|
||||||
|
if (state.IsValid()) {
|
||||||
|
chainman.ActiveChainstate().ActivateBestChain(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!state.IsValid()) {
|
||||||
|
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan invalidateblock()
|
static RPCHelpMan invalidateblock()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"invalidateblock",
|
return RPCHelpMan{"invalidateblock",
|
||||||
|
@ -1591,27 +1612,10 @@ static RPCHelpMan invalidateblock()
|
||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
|
||||||
BlockValidationState state;
|
|
||||||
|
|
||||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||||
CBlockIndex* pblockindex;
|
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
||||||
{
|
|
||||||
LOCK(cs_main);
|
|
||||||
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
|
|
||||||
if (!pblockindex) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chainman.ActiveChainstate().InvalidateBlock(state, pblockindex);
|
|
||||||
|
|
||||||
if (state.IsValid()) {
|
InvalidateBlock(chainman, hash);
|
||||||
chainman.ActiveChainstate().ActivateBestChain(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.IsValid()) {
|
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return UniValue::VNULL;
|
return UniValue::VNULL;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue