Skip to content

Commit

Permalink
RPC: Implement quorumdkgstatus command
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Feb 15, 2022
1 parent 8341489 commit aae961c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -36,6 +38,7 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable& tableRPC)
RegisterMasternodeRPCCommands(tableRPC);
RegisterBudgetRPCCommands(tableRPC);
RegisterEvoRPCCommands(tableRPC);
RegisterQuorumsRPCCommands(tableRPC);
}

#endif
73 changes: 73 additions & 0 deletions src/rpc/rpcquorums.cpp
Original file line number Diff line number Diff line change
@@ -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]);
}

0 comments on commit aae961c

Please sign in to comment.