feat(rpc): masternode status and count RPCs adjusted for HPMNs (#5206)

## Issue being fixed or feature implemented

## What was done?
-  `masternode status` now returns the type as well
- `masternode count` now returns in addition total and total enabled MNs
per type.


## How Has This Been Tested?
Added functional tests


## Breaking Changes

## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] 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 2023-02-17 20:29:46 +02:00 committed by GitHub
parent 33703a5f2f
commit a3918451d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Updated RPCs
--------
- `masternode` mode `status` now returns the type of the masternode.
- `masternode` mode `count` now returns a detailed summary of total and enabled masternodes per type.

View File

@ -230,6 +230,11 @@ public:
return ranges::count_if(mnMap, [](const auto& p) { return p.second->nType == MnType::HighPerformance; });
}
[[nodiscard]] size_t GetValidHPMNsCount() const
{
return ranges::count_if(mnMap, [](const auto& p) { return p.second->nType == MnType::HighPerformance && IsMNValid(*p.second); });
}
/**
* Execute a callback on all masternodes in the mnList. This will pass a reference
* of each masternode to the callback function. This should be preferred over ForEachMNShared.

View File

@ -112,6 +112,23 @@ static UniValue masternode_count(const JSONRPCRequest& request)
UniValue obj(UniValue::VOBJ);
obj.pushKV("total", total);
obj.pushKV("enabled", enabled);
int hpmn_total = mnList.GetAllHPMNsCount();
int hpmn_enabled = mnList.GetValidHPMNsCount();
UniValue hpmnObj(UniValue::VOBJ);
hpmnObj.pushKV("total", hpmn_total);
hpmnObj.pushKV("enabled", hpmn_enabled);
UniValue regularObj(UniValue::VOBJ);
regularObj.pushKV("total", total - hpmn_total);
regularObj.pushKV("enabled", enabled - hpmn_enabled);
UniValue detailedObj(UniValue::VOBJ);
detailedObj.pushKV("regular", regularObj);
detailedObj.pushKV("hpmn", hpmnObj);
obj.pushKV("detailed", detailedObj);
return obj;
}
@ -247,6 +264,7 @@ static UniValue masternode_status(const JSONRPCRequest& request)
}
if (dmn) {
mnObj.pushKV("proTxHash", dmn->proTxHash.ToString());
mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description));
mnObj.pushKV("collateralHash", dmn->collateralOutpoint.hash.ToString());
mnObj.pushKV("collateralIndex", (int)dmn->collateralOutpoint.n);
UniValue stateObj;

View File

@ -46,6 +46,8 @@ class LLMQHPMNTest(DashTestFramework):
self.log.info("Test that HPMN registration is rejected before v19")
self.test_hpmn_is_rejected_before_v19()
self.test_masternode_count(expected_mns_count=4, expected_hpmns_count=0)
self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
@ -64,6 +66,7 @@ class LLMQHPMNTest(DashTestFramework):
hpmn_protxhash_list.append(hpmn_info.proTxHash)
self.nodes[0].generate(8)
self.sync_blocks(self.nodes)
self.test_masternode_count(expected_mns_count=4, expected_hpmns_count=i+1)
self.test_hpmn_update_service(hpmn_info)
self.log.info("Test llmq_platform are formed only with HPMNs")
@ -189,6 +192,13 @@ class LLMQHPMNTest(DashTestFramework):
self.log.info("protx_hpmn rejected")
assert_equal(protx_success, False)
def test_masternode_count(self, expected_mns_count, expected_hpmns_count):
mn_count = self.nodes[0].masternode('count')
assert_equal(mn_count['total'], expected_mns_count + expected_hpmns_count)
detailed_count = mn_count['detailed']
assert_equal(detailed_count['regular']['total'], expected_mns_count)
assert_equal(detailed_count['hpmn']['total'], expected_hpmns_count)
def test_hpmn_update_service(self, hpmn_info):
funds_address = self.nodes[0].getnewaddress()
operator_reward_address = self.nodes[0].getnewaddress()