diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -442,6 +442,19 @@ return ret; } +static void verifyProofOrThrow(const NodeContext &node, + const avalanche::Proof &proof) { + avalanche::ProofValidationState state; + { + LOCK(cs_main); + if (!proof.verify(state, + node.chainman->ActiveChainstate().CoinsTip())) { + throw JSONRPCError(RPC_INVALID_PARAMETER, + "The proof is invalid: " + state.ToString()); + } + } +} + static UniValue verifyavalancheproof(const Config &config, const JSONRPCRequest &request) { RPCHelpMan{ @@ -465,17 +478,7 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, error.original); } - NodeContext &node = EnsureNodeContext(request.context); - - avalanche::ProofValidationState state; - { - LOCK(cs_main); - if (!proof.verify(state, - node.chainman->ActiveChainstate().CoinsTip())) { - throw JSONRPCError(RPC_INVALID_PARAMETER, - "The proof is invalid: " + state.ToString()); - } - } + verifyProofOrThrow(EnsureNodeContext(request.context), proof); return true; }