mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 09:06:15 +01:00
RPC: Extract ReconsiderBlock helper
This commit is contained in:
parent
446ce51c21
commit
fccf4f91d2
1 changed files with 20 additions and 16 deletions
|
@ -1622,6 +1622,25 @@ static RPCHelpMan invalidateblock()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReconsiderBlock(ChainstateManager& chainman, uint256 block_hash) {
|
||||||
|
{
|
||||||
|
LOCK(chainman.GetMutex());
|
||||||
|
CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(block_hash);
|
||||||
|
if (!pblockindex) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
chainman.ActiveChainstate().ResetBlockFailureFlags(pblockindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockValidationState state;
|
||||||
|
chainman.ActiveChainstate().ActivateBestChain(state);
|
||||||
|
|
||||||
|
if (!state.IsValid()) {
|
||||||
|
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan reconsiderblock()
|
static RPCHelpMan reconsiderblock()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"reconsiderblock",
|
return RPCHelpMan{"reconsiderblock",
|
||||||
|
@ -1640,22 +1659,7 @@ static RPCHelpMan reconsiderblock()
|
||||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||||
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
||||||
|
|
||||||
{
|
ReconsiderBlock(chainman, hash);
|
||||||
LOCK(cs_main);
|
|
||||||
CBlockIndex* pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
|
|
||||||
if (!pblockindex) {
|
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
chainman.ActiveChainstate().ResetBlockFailureFlags(pblockindex);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockValidationState state;
|
|
||||||
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