| 2049 | } |
| 2050 | |
| 2051 | static RPCHelpMan preciousblock() |
| 2052 | { |
| 2053 | return RPCHelpMan{"preciousblock", |
| 2054 | "\nTreats a block as if it were received before others with the same work.\n" |
| 2055 | "\nA later preciousblock call can override the effect of an earlier one.\n" |
| 2056 | "\nThe effects of preciousblock are not retained across restarts.\n", |
| 2057 | { |
| 2058 | {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to mark as precious"}, |
| 2059 | }, |
| 2060 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 2061 | RPCExamples{ |
| 2062 | HelpExampleCli("preciousblock", "\"blockhash\"") |
| 2063 | + HelpExampleRpc("preciousblock", "\"blockhash\"") |
| 2064 | }, |
| 2065 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 2066 | { |
| 2067 | uint256 hash(ParseHashV(request.params[0], "blockhash")); |
| 2068 | CBlockIndex* pblockindex; |
| 2069 | |
| 2070 | ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 2071 | { |
| 2072 | LOCK(cs_main); |
| 2073 | pblockindex = chainman.m_blockman.LookupBlockIndex(hash); |
| 2074 | if (!pblockindex) { |
| 2075 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | BlockValidationState state; |
| 2080 | chainman.ActiveChainstate().PreciousBlock(state, pblockindex); |
| 2081 | |
| 2082 | if (!state.IsValid()) { |
| 2083 | throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString()); |
| 2084 | } |
| 2085 | |
| 2086 | return NullUniValue; |
| 2087 | }, |
| 2088 | }; |
| 2089 | } |
| 2090 | |
| 2091 | static RPCHelpMan invalidateblock() |
| 2092 | { |
nothing calls this directly
no test coverage detected