feat: Enrich quorum listextended rpc reply (#5114)

<!--
*** Please remove the following help text before submitting: ***

Provide a general summary of your changes in the Title above

Pull requests without a rationale and clear improvement may be closed
immediately.

Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:

* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
  should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
  was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
  consider building the system outside of Dash Core, if possible.
-->

## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->


## What was done?
<!--- Describe your changes in detail -->
Added the fields `numValidMembers` and `healthRatio` in `quorum
listextended` RPC reply, as we need a quick way to see the health of all
quorums with a single command.
`healthRatio` range is `[0.0 - 1.0]`
Note: The decision to include both fields was taken because we need
cover the case where a quorum was created with `minSize` members but all
of them were valid.

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->


## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->


## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation

**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
This commit is contained in:
Odysseas Gabrielides 2022-12-23 22:06:31 +02:00 committed by pasta
parent a7c0754f87
commit 8e2d61e634
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 14 additions and 1 deletions

View File

@ -7,3 +7,5 @@ This RPC returns the following data per quorum grouped per llmqTypes:
- `creationHeight`: Block height where its DKG started
- `quorumIndex`: Returned only for rotated llmqTypes
- `minedBlockHash`: Hash of the block containing the mined final commitment
- `numValidMembers`: The total of valid members.
- `healthRatio`: The ratio of healthy members to quorum size. Range [0.0 - 1.0].

View File

@ -23,6 +23,8 @@
#include <llmq/signing_shares.h>
#include <llmq/snapshot.h>
#include <iomanip>
namespace llmq {
extern const std::string CLSIG_REQUESTID_PREFIX;
}
@ -100,7 +102,9 @@ static void quorum_list_extended_help(const JSONRPCRequest& request)
{
{RPCResult::Type::NUM, "creationHeight", "Block height where the DKG started."},
{RPCResult::Type::NUM, "quorumIndex", "Quorum index (applicable only to rotated quorums)."},
{RPCResult::Type::STR_HEX, "minedBlockHash", "Blockhash where the commitment was mined."}
{RPCResult::Type::STR_HEX, "minedBlockHash", "Blockhash where the commitment was mined."},
{RPCResult::Type::NUM, "numValidMembers", "The total of valid members."},
{RPCResult::Type::STR_AMOUNT, "healthRatio", "The ratio of healthy members to quorum size. Range [0.0 - 1.0]."}
}}
}}
}}
@ -136,6 +140,11 @@ static UniValue quorum_list_extended(const JSONRPCRequest& request)
auto quorums = llmq_ctx.qman->ScanQuorums(type, pblockindex, llmq_params.signingActiveQuorumCount);
for (const auto& q : quorums) {
size_t num_members = q->members.size();
size_t num_valid_members = std::count_if(q->qc->validMembers.begin(), q->qc->validMembers.begin() + num_members, [](auto val){return val;});
double health_ratio = num_members > 0 ? double(num_valid_members) / double(num_members) : 0.0;
std::stringstream ss;
ss << std::fixed << std::setprecision(2) << health_ratio;
UniValue obj(UniValue::VOBJ);
{
UniValue j(UniValue::VOBJ);
@ -144,6 +153,8 @@ static UniValue quorum_list_extended(const JSONRPCRequest& request)
}
j.pushKV("creationHeight", q->m_quorum_base_block_index->nHeight);
j.pushKV("minedBlockHash", q->minedBlockHash.ToString());
j.pushKV("numValidMembers", (int32_t)num_valid_members);
j.pushKV("healthRatio", ss.str());
obj.pushKV(q->qc->quorumHash.ToString(),j);
}
v.push_back(obj);