From aae961cbdbc9f03e5c96314331b6a83d2165d026 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Wed, 9 Jun 2021 03:55:21 +0200 Subject: [PATCH] RPC: Implement quorumdkgstatus command --- CMakeLists.txt | 1 + src/Makefile.am | 1 + src/rpc/register.h | 3 ++ src/rpc/rpcquorums.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/rpc/rpcquorums.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ee4001a480a9..53b6f575f429f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,7 @@ set(SERVER_SOURCES ./src/rpc/net.cpp ./src/rpc/rawtransaction.cpp ./src/rpc/rpcevo.cpp + ./src/rpc/rpcquorums.cpp ./src/rpc/server.cpp ./src/script/sigcache.cpp ./src/script/ismine.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 28c1defbec3fb..2f25321d24546 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -401,6 +401,7 @@ libbitcoin_server_a_SOURCES = \ rpc/net.cpp \ rpc/rawtransaction.cpp \ rpc/rpcevo.cpp \ + rpc/rpcquorums.cpp \ rpc/server.cpp \ script/sigcache.cpp \ script/ismine.cpp \ diff --git a/src/rpc/register.h b/src/rpc/register.h index 1f864bb07d590..c98eaf66b008b 100644 --- a/src/rpc/register.h +++ b/src/rpc/register.h @@ -25,6 +25,8 @@ void RegisterMasternodeRPCCommands(CRPCTable& tableRPC); void RegisterBudgetRPCCommands(CRPCTable& tableRPC); /** Register Evo RPC commands */ void RegisterEvoRPCCommands(CRPCTable &tableRPC); +/** Register Quorums RPC commands */ +void RegisterQuorumsRPCCommands(CRPCTable &tableRPC); static inline void RegisterAllCoreRPCCommands(CRPCTable& tableRPC) { @@ -36,6 +38,7 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable& tableRPC) RegisterMasternodeRPCCommands(tableRPC); RegisterBudgetRPCCommands(tableRPC); RegisterEvoRPCCommands(tableRPC); + RegisterQuorumsRPCCommands(tableRPC); } #endif diff --git a/src/rpc/rpcquorums.cpp b/src/rpc/rpcquorums.cpp new file mode 100644 index 0000000000000..313f940263180 --- /dev/null +++ b/src/rpc/rpcquorums.cpp @@ -0,0 +1,73 @@ +// Copyright (c) 2018-2021 The Dash Core developers +// Copyright (c) 2022 The PIVX Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "activemasternode.h" +#include "chainparams.h" +#include "llmq/quorums_blockprocessor.h" +#include "llmq/quorums_commitment.h" +#include "llmq/quorums_debug.h" +#include "llmq/quorums_utils.h" +#include "net.h" +#include "rpc/server.h" +#include "validation.h" + + +UniValue quorumdkgstatus(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() > 1) { + throw std::runtime_error( + "quorumdkgstatus ( detail_level )\n" + "Return the status of the current DKG process of the active masternode.\n" + "\nArguments:\n" + "1. detail_level (number, optional, default=0) Detail level of output.\n" + " 0=Only show counts. 1=Show member indexes. 2=Show member's ProTxHashes.\n" + "\nExamples:\n" + + HelpExampleRpc("quorumdkgstatus", "2") + + HelpExampleCli("quorumdkgstatus", "") + ); + } + + int detailLevel = request.params.size() > 0 ? request.params[0].get_int() : 0; + if (detailLevel < 0 || detailLevel > 2) { + throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("invalid detail_level %d", detailLevel)); + } + + if (!fMasterNode || !activeMasternodeManager) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "This is not a (deterministic) masternode"); + } + + llmq::CDKGDebugStatus status; + llmq::quorumDKGDebugManager->GetLocalDebugStatus(status); + + auto ret = status.ToJson(detailLevel); + + const int tipHeight = WITH_LOCK(cs_main, return chainActive.Height(); ); + + UniValue minableCommitments(UniValue::VOBJ); + for (const auto& p : Params().GetConsensus().llmqs) { + auto& params = p.second; + llmq::CFinalCommitment fqc; + if (llmq::quorumBlockProcessor->GetMinableCommitment(params.type, tipHeight, fqc)) { + UniValue obj(UniValue::VOBJ); + fqc.ToJson(obj); + minableCommitments.pushKV(params.name, obj); + } + } + ret.pushKV("minableCommitments", minableCommitments); + + return ret; +} + +static const CRPCCommand commands[] = +{ // category name actor (function) okSafe argNames + // -------------- ------------------------- --------------------- ------ -------- + { "evo", "quorumdkgstatus", &quorumdkgstatus, true, {"detail_level"} }, +}; + +void RegisterQuorumsRPCCommands(CRPCTable& tableRPC) +{ + for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) + tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); +}