Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): quorum dkginfo rpc #5853

Merged
merged 8 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release-notes-5853.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Added RPC
--------

- `dkginfo` RPC returns information about DKGs:
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
`nActiveDKGs`: Total number of active DKG sessions.
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
`nextDKG`: If `nActiveDKGs` is 0, then `nextDKG` indicates the number of blocks until the next potential DKG session.
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved

Note: This RPC is enabled only for Masternodes, and it is expected to work only when `SPORK_17_QUORUM_DKG_ENABLED` spork is ON.
45 changes: 45 additions & 0 deletions src/rpc/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,47 @@ static UniValue quorum_rotationinfo(const JSONRPCRequest& request, const LLMQCon
return quorumRotationInfoRet.ToJson();
}

static void quorum_dkginfo_help(const JSONRPCRequest& request)
{
RPCHelpMan{"quorum dkginfo",
"Return information regarding DKGs.\n"
"Enabled only for Masternode and works only when SPORK_17_QUORUM_DKG_ENABLED spork is ON.\n",
UdjinM6 marked this conversation as resolved.
Show resolved Hide resolved
{
{},
},
RPCResults{},
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
RPCExamples{""},
}.Check(request);
}

static UniValue quorum_dkginfo(const JSONRPCRequest& request, const LLMQContext& llmq_ctx, const ChainstateManager& chainman)
{
quorum_dkginfo_help(request);

if (!fMasternodeMode) {
throw JSONRPCError(RPC_INVALID_REQUEST, "RPC allowed only for Masternodes");
UdjinM6 marked this conversation as resolved.
Show resolved Hide resolved
}

llmq::CDKGDebugStatus status;
llmq_ctx.dkg_debugman->GetLocalDebugStatus(status);
UniValue ret(UniValue::VOBJ);
ret.pushKV("nActiveDKGs", int(status.sessions.size()));
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved

const int nTipHeight{WITH_LOCK(cs_main, return chainman.ActiveChain().Height())};
auto minNextDKG = [](const Consensus::Params& consensusParams, int nTipHeight) {
int minDkgWindow{std::numeric_limits<int>::max()};
for (const auto& params: consensusParams.llmqs) {
if (params.useRotation && (nTipHeight % params.dkgInterval <= params.signingActiveQuorumCount)) {
return 1;
}
minDkgWindow = std::min(minDkgWindow, params.dkgInterval - (nTipHeight % params.dkgInterval));
}
return minDkgWindow;
};
ret.pushKV("nextDKG", minNextDKG(Params().GetConsensus(), nTipHeight));

return ret;
}

[[ noreturn ]] static void quorum_help()
{
Expand All @@ -801,6 +842,7 @@ static UniValue quorum_rotationinfo(const JSONRPCRequest& request, const LLMQCon
" list - List of on-chain quorums\n"
" listextended - Extended list of on-chain quorums\n"
" info - Return information about a quorum\n"
" dkginfo - Return information about DKGs\n"
" dkgsimerror - Simulates DKG errors and malicious behavior\n"
" dkgstatus - Return the status of the current DKG process\n"
" memberof - Checks which quorums the given masternode is a member of\n"
Expand Down Expand Up @@ -836,6 +878,8 @@ static UniValue _quorum(const JSONRPCRequest& request)
return quorum_list_extended(new_request, chainman, llmq_ctx);
} else if (command == "quoruminfo") {
return quorum_info(new_request, llmq_ctx);
} else if (command == "quorumdkginfo") {
return quorum_dkginfo(new_request, llmq_ctx, chainman);
} else if (command == "quorumdkgstatus") {
return quorum_dkgstatus(new_request, chainman, llmq_ctx);
} else if (command == "quorummemberof") {
Expand Down Expand Up @@ -1037,6 +1081,7 @@ static UniValue submitchainlock(const JSONRPCRequest& request)
}



ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
void RegisterQuorumsRPCCommands(CRPCTable &tableRPC)
{
// clang-format off
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].quorum("dkginfo")['nextDKG'], int(24 - (tip % 24)))
ogabrielides marked this conversation as resolved.
Show resolved Hide resolved
assert_equal(self.nodes[2].quorum("dkginfo")['nextDKG'], int(24 - (tip % 24)))
assert_equal(self.nodes[3].quorum("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
Loading