aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2024-03-02 16:42:27 +0100
committerFabian Jahr <fjahr@protonmail.com>2024-09-01 20:56:38 +0200
commitfccf4f91d21c351d742943d35476f53d40963b8b (patch)
treef05565869b886b61784d771ee5076fdd2126b898 /src/rpc
parent446ce51c21cd2466cb12fa0166fd069d42b603bf (diff)
RPC: Extract ReconsiderBlock helper
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 4da26e84bd..3f6def27d6 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -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()
{
return RPCHelpMan{"reconsiderblock",
@@ -1640,22 +1659,7 @@ static RPCHelpMan reconsiderblock()
ChainstateManager& chainman = EnsureAnyChainman(request.context);
uint256 hash(ParseHashV(request.params[0], "blockhash"));
- {
- 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());
- }
+ ReconsiderBlock(chainman, hash);
return UniValue::VNULL;
},