Skip to content

Commit f571843

Browse files
committed
feat: clean up a bit dkginfo implementation for further quorums
1 parent 4534eb8 commit f571843

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

src/rpc/quorums.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -998,21 +998,18 @@ static RPCHelpMan quorum_dkginfo()
998998
{
999999
{RPCResult::Type::NUM, "active_dkgs", "Total number of active DKG sessions this node is participating in right now"},
10001000
{RPCResult::Type::NUM, "next_dkg", "The number of blocks until the next potential DKG session"},
1001+
GetRpcResult("proTxHash"),
10011002
{RPCResult::Type::ARR, "upcoming_dkgs", /*optional=*/true, "Upcoming DKG sessions for the given proTxHash whose work block is already mined. For rotated quorums all indices in a cycle share the cycle base work block",
10021003
{
10031004
{RPCResult::Type::OBJ, "", "",
10041005
{
10051006
GetRpcResult("llmqType"),
1006-
{RPCResult::Type::STR, "llmqTypeName", "The name of the quorum type"},
10071007
GetRpcResult("quorumIndex"),
10081008
{RPCResult::Type::NUM, "quorumHeight", "The height at which the quorum session starts"},
10091009
{RPCResult::Type::NUM, "blocksUntilStart", "The number of blocks until the quorum session starts"},
1010-
GetRpcResult("proTxHash"),
10111010
{RPCResult::Type::BOOL, "known", "Whether participation could be determined"},
10121011
{RPCResult::Type::STR, "reason", /*optional=*/true, "Why participation could not be determined"},
10131012
{RPCResult::Type::BOOL, "isMember", /*optional=*/true, "Whether the masternode is a member of the upcoming quorum"},
1014-
GetRpcResult("memberIndex"),
1015-
{RPCResult::Type::NUM, "memberCount", /*optional=*/true, "The number of members in the upcoming quorum"},
10161013
{RPCResult::Type::NUM, "workBlockHeight", /*optional=*/true, "The height of the work block used to compute membership"},
10171014
{RPCResult::Type::STR_HEX, "workBlockHash", /*optional=*/true, "The hash of the work block used to compute membership"},
10181015
}},
@@ -1032,6 +1029,7 @@ static RPCHelpMan quorum_dkginfo()
10321029
ret.pushKV("active_dkgs", dkgdbgman.GetSessionCount());
10331030

10341031
const ChainstateManager& chainman = EnsureChainman(node);
1032+
const auto& consensus = chainman.GetParams().GetConsensus();
10351033
const CBlockIndex* const pindexTip = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());
10361034
CHECK_NONFATAL(pindexTip);
10371035
const int nTipHeight{pindexTip->nHeight};
@@ -1045,7 +1043,7 @@ static RPCHelpMan quorum_dkginfo()
10451043
}
10461044
return minDkgWindow;
10471045
};
1048-
ret.pushKV("next_dkg", minNextDKG(Params().GetConsensus(), nTipHeight));
1046+
ret.pushKV("next_dkg", minNextDKG(consensus, nTipHeight));
10491047

10501048
const auto quorum_type_known_enabled = [&](Consensus::LLMQType llmq_type, int quorum_base_height) {
10511049
const int quorum_base_predecessor_height{quorum_base_height - 1};
@@ -1057,7 +1055,6 @@ static RPCHelpMan quorum_dkginfo()
10571055
// The future predecessor is not mined yet, but both DIP0024 conditions are pure height
10581056
// checks (buried deployment); evaluate them at the future height and let pindexTip stand
10591057
// in for the rest (versionbits TESTDUMMY is monotonic once active).
1060-
const auto& consensus = Params().GetConsensus();
10611058
return chainman.IsQuorumTypeEnabled(llmq_type, pindexTip,
10621059
/*optDIP0024IsActive=*/quorum_base_height >=
10631060
consensus.DeploymentHeight(Consensus::DEPLOYMENT_DIP0024),
@@ -1073,8 +1070,9 @@ static RPCHelpMan quorum_dkginfo()
10731070
}
10741071

10751072
if (!proTxHash.IsNull()) {
1073+
ret.pushKV("proTxHash", proTxHash.ToString());
10761074
UniValue upcoming(UniValue::VARR);
1077-
for (const auto& llmq_params : Params().GetConsensus().llmqs) {
1075+
for (const auto& llmq_params : consensus.llmqs) {
10781076
// Whether a rotated cycle applies at the *upcoming* cycle base is what matters here,
10791077
// not whether the tip's own current cycle is rotated. Iterate every possible index
10801078
// for any llmq type that supports rotation and decide per-entry below.
@@ -1095,7 +1093,6 @@ static RPCHelpMan quorum_dkginfo()
10951093
// height check. A rotation-capable type without rotation active at its cycle
10961094
// base has no canonical member selection, so skip it (this can only happen
10971095
// around DIP0024 activation).
1098-
const Consensus::Params& consensus{Params().GetConsensus()};
10991096
if (llmq_params.useRotation &&
11001097
(cycleBaseHeight < 1 || cycleBaseHeight < consensus.DeploymentHeight(Consensus::DEPLOYMENT_DIP0024))) {
11011098
continue;
@@ -1107,7 +1104,6 @@ static RPCHelpMan quorum_dkginfo()
11071104
obj.pushKV("quorumIndex", quorumIndex);
11081105
obj.pushKV("quorumHeight", quorumHeight);
11091106
obj.pushKV("blocksUntilStart", quorumHeight - nTipHeight);
1110-
obj.pushKV("proTxHash", proTxHash.ToString());
11111107

11121108
// All indices of a rotated cycle share the work block of their cycle base, so
11131109
// gate availability on the work block height rather than each index's start
@@ -1120,7 +1116,7 @@ static RPCHelpMan quorum_dkginfo()
11201116
}
11211117

11221118
const CBlockIndex* const pWorkBlockIndex = pindexTip->GetAncestor(workHeight);
1123-
if (!DeploymentActiveAfter(pWorkBlockIndex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20)) {
1119+
if (!DeploymentActiveAfter(pWorkBlockIndex, consensus, Consensus::DEPLOYMENT_V20)) {
11241120
obj.pushKV("known", false);
11251121
obj.pushKV("reason", "pre-v20 quorum selection needs future quorum base block hash");
11261122
upcoming.push_back(obj);
@@ -1138,19 +1134,17 @@ static RPCHelpMan quorum_dkginfo()
11381134
upcoming.push_back(obj);
11391135
continue;
11401136
}
1141-
const auto& members = *predicted_members;
11421137

11431138
obj.pushKV("known", true);
1144-
int memberIndex{-1};
1145-
for (size_t i = 0; i < members.size(); ++i) {
1146-
if (members[i]->proTxHash == proTxHash) {
1147-
memberIndex = (int)i;
1139+
1140+
bool is_member{false};
1141+
for (const auto& member : *predicted_members) {
1142+
if (member->proTxHash == proTxHash) {
1143+
is_member = true;
11481144
break;
11491145
}
11501146
}
1151-
obj.pushKV("isMember", memberIndex != -1);
1152-
obj.pushKV("memberIndex", memberIndex);
1153-
obj.pushKV("memberCount", (int)members.size());
1147+
obj.pushKV("isMember", is_member);
11541148
obj.pushKV("workBlockHeight", pWorkBlockIndex->nHeight);
11551149
obj.pushKV("workBlockHash", pWorkBlockIndex->GetBlockHash().ToString());
11561150
upcoming.push_back(obj);

test/functional/test_framework/test_framework.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,6 @@ def verify_upcoming_dkg_predictions(self, predictions, quorum_info):
21552155
continue
21562156
assert_equal(entry["workBlockHeight"], work_height)
21572157
assert_equal(entry["workBlockHash"], self.nodes[0].getblockhash(work_height))
2158-
assert_equal(entry["memberCount"], len(members))
2159-
assert_equal(entry["memberIndex"], members.index(proTxHash) if proTxHash in members else -1)
21602158
assert_equal(entry["isMember"], proTxHash in members)
21612159

21622160
def mine_quorum(self, llmq_type_name="llmq_test", llmq_type=100, expected_connections=None, expected_members=None, expected_contributions=None, expected_complaints=0, expected_justifications=0, expected_commitments=None, mninfos_online=None, mninfos_valid=None, skip_maturity=False):

0 commit comments

Comments
 (0)