Skip to content

Commit

Permalink
dkginfo rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Jan 31, 2024
1 parent ce67e07 commit cd4bd73
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/rpc/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,50 @@ static UniValue submitchainlock(const JSONRPCRequest& request)
return true;
}

static void dkginfo_help(const JSONRPCRequest& request)
{
RPCHelpMan{"dkginfo",
"Return information regarding DKGs.\n"
"Enabled only for Masternode and works only when SPORK_17_QUORUM_DKG_ENABLED spork is ON.\n",
{
{},
},
RPCResults{},
RPCExamples{""},
}.Check(request);
}

static UniValue dkginfo(const JSONRPCRequest& request)
{
dkginfo_help(request);

if (!fMasternodeMode) {
throw JSONRPCError(RPC_INVALID_REQUEST, "RPC allowed only for Masternodes");
}

const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);

llmq::CDKGDebugStatus status;
llmq_ctx.dkg_debugman->GetLocalDebugStatus(status);
UniValue ret(UniValue::VOBJ);
ret.pushKV("nActiveDKGs", (int)status.sessions.size());

if (status.sessions.empty()) {
int nTipHeight = WITH_LOCK(cs_main, return chainman.ActiveChain().Height());
const Consensus::Params &consensus_params = Params().GetConsensus();
int minDkgWindow = std::numeric_limits<int>::max();
for (const auto &params: consensus_params.llmqs) {
if (!params.useRotation)
minDkgWindow = std::min(minDkgWindow, params.dkgInterval - (nTipHeight % params.dkgInterval));
}
ret.pushKV("nextDKG", minDkgWindow);
}

return ret;
}


void RegisterQuorumsRPCCommands(CRPCTable &tableRPC)
{
Expand All @@ -1047,6 +1091,7 @@ static const CRPCCommand commands[] =
{ "evo", "submitchainlock", &submitchainlock, {"blockHash", "signature", "blockHeight"} },
{ "evo", "verifychainlock", &verifychainlock, {"blockHash", "signature", "blockHeight"} },
{ "evo", "verifyislock", &verifyislock, {"id", "txid", "signature", "maxHeight"} },
{ "evo", "dkginfo", &dkginfo, {} },
};
// clang-format on
for (const auto& command : commands) {
Expand Down
5 changes: 5 additions & 0 deletions test/functional/feature_llmq_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def run_test(self):

b_h_0 = self.nodes[0].getbestblockhash()

tip = self.nodes[0].getblockcount()
assert_equal(self.nodes[1].dkginfo()['nextDKG'], int(24 - (tip % 24)))
assert_equal(self.nodes[2].dkginfo()['nextDKG'], int(24 - (tip % 24)))
assert_equal(self.nodes[3].dkginfo()['nextDKG'], int(24 - (tip % 24)))

#Mine 2 quorums so that Chainlocks can be available: Need them to include CL in CbTx as soon as v20 activates
self.log.info("Mining 2 quorums")
h_0 = self.mine_quorum()
Expand Down

0 comments on commit cd4bd73

Please sign in to comment.