| 1527 | } |
| 1528 | |
| 1529 | UniValue finalizeblock(const JSONRPCRequest& request) { |
| 1530 | if (request.fHelp || request.params.size() != 1) |
| 1531 | throw std::runtime_error( |
| 1532 | "finalizeblock \"blockhash\"\n" |
| 1533 | "\nTreats a block as final. It cannot be reorged. Any chain\n" |
| 1534 | "that does not contain this block is invalid. Used on a less\n" |
| 1535 | "work chain, it can effectively PUTS YOU OUT OF CONSENSUS.\n" |
| 1536 | "USE WITH CAUTION!\n" |
| 1537 | "\nArguments:\n" |
| 1538 | "1. \"blockhash\" (string, required) the hash of the block to mark as finalized\n" |
| 1539 | "\nResult:\n" |
| 1540 | "\nExamples:\n" |
| 1541 | + HelpExampleCli("finalizeblock", "\"blockhash\"") |
| 1542 | + HelpExampleRpc("finalizeblock", "\"blockhash\"") |
| 1543 | ); |
| 1544 | |
| 1545 | std::string strHash = request.params[0].get_str(); |
| 1546 | uint256 hash(uint256S(strHash)); |
| 1547 | CValidationState state; |
| 1548 | |
| 1549 | { |
| 1550 | LOCK(cs_main); |
| 1551 | CBlockIndex *pblockindex = LookupBlockIndex(hash); |
| 1552 | if (!pblockindex) { |
| 1553 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
| 1554 | } |
| 1555 | |
| 1556 | FinalizeBlockAndInvalidate(state, pblockindex); |
| 1557 | } |
| 1558 | |
| 1559 | if (state.IsValid()) { |
| 1560 | ActivateBestChain(state, Params()); |
| 1561 | } |
| 1562 | |
| 1563 | if (!state.IsValid()) { |
| 1564 | throw JSONRPCError(RPC_DATABASE_ERROR, FormatStateMessage(state)); |
| 1565 | } |
| 1566 | |
| 1567 | return NullUniValue; |
| 1568 | } |
| 1569 | |
| 1570 | static UniValue invalidateblock(const JSONRPCRequest& request) |
| 1571 | { |
nothing calls this directly
no test coverage detected