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

Add "isValidMember" and "memberIndex" to "quorum memberof" and allow to specify quorum scan count #3009

Merged
merged 2 commits into from Jul 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/rpc/rpcquorums.cpp
Expand Up @@ -192,20 +192,29 @@ UniValue quorum_dkgstatus(const JSONRPCRequest& request)
void quorum_memberof_help()
{
throw std::runtime_error(
"quorum memberof \"proTxHash\"\n"
"quorum memberof \"proTxHash\" (quorumCount)\n"
"Checks which quorums the given masternode is a member of.\n"
"\nArguments:\n"
"1. \"proTxHash\" (string, required) ProTxHash of the masternode.\n"
"2. scanQuorumsCount (number, optional) Number of quorums to scan for. If not specified,\n"
" the active quorum count for each specific quorum type is used."
);
}

UniValue quorum_memberof(const JSONRPCRequest& request)
{
if (request.fHelp || (request.params.size() != 2)) {
if (request.fHelp || (request.params.size() < 2 || request.params.size() > 3)) {
quorum_memberof_help();
}

uint256 protxHash = ParseHashV(request.params[1], "proTxHash");
int scanQuorumsCount = -1;
if (request.params.size() >= 3) {
scanQuorumsCount = ParseInt32V(request.params[2], "scanQuorumsCount");
if (scanQuorumsCount <= 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid scanQuorumsCount parameter");
}
}

const CBlockIndex* pindexTip;
{
Expand All @@ -219,26 +228,25 @@ UniValue quorum_memberof(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "masternode not found");
}

std::set<std::pair<Consensus::LLMQType, uint256>> quorumHashes;
UniValue result(UniValue::VARR);

for (const auto& p : Params().GetConsensus().llmqs) {
auto& params = p.second;
auto quorums = llmq::quorumManager->ScanQuorums(params.type, params.signingActiveQuorumCount);
size_t count = params.signingActiveQuorumCount;
if (scanQuorumsCount != -1) {
count = (size_t)scanQuorumsCount;
}
auto quorums = llmq::quorumManager->ScanQuorums(params.type, count);
for (auto& quorum : quorums) {
for (auto& m : quorum->members) {
if (m->proTxHash == dmn->proTxHash) {
quorumHashes.emplace(params.type, quorum->qc.quorumHash);
}
if (quorum->IsMember(dmn->proTxHash)) {
auto json = BuildQuorumInfo(quorum, false, false);
json.push_back(Pair("isValidMember", quorum->IsValidMember(dmn->proTxHash)));
json.push_back(Pair("memberIndex", quorum->GetMemberIndex(dmn->proTxHash)));
result.push_back(json);
}
}
}

UniValue result(UniValue::VARR);
for (auto& p : quorumHashes) {
auto quorum = llmq::quorumManager->GetQuorum(p.first, p.second);
assert(quorum);
result.push_back(BuildQuorumInfo(quorum, false, false));
}

return result;
}

Expand Down