Skip to content

Commit

Permalink
[RPC] getmasternodestatus for DMN
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 23, 2021
1 parent 8b10fc2 commit 064f774
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ UniValue getmasternodestatus (const JSONRPCRequest& request)
"getmasternodestatus\n"
"\nPrint masternode status\n"

"\nResult:\n"
"\nResult (if legacy masternode):\n"
"{\n"
" \"txhash\": \"xxxx\", (string) Collateral transaction hash\n"
" \"outputidx\": n, (numeric) Collateral transaction output index number\n"
Expand All @@ -654,15 +654,45 @@ UniValue getmasternodestatus (const JSONRPCRequest& request)
" \"status\": \"xxxx\", (string) Masternode status\n"
" \"message\": \"xxxx\" (string) Masternode status message\n"
"}\n"
"\n"
"\nResult (if deterministic masternode):\n"
"{\n"
"... !TODO ...\n"
"}\n"

"\nExamples:\n" +
HelpExampleCli("getmasternodestatus", "") + HelpExampleRpc("getmasternodestatus", ""));

if (!fMasterNode)
throw JSONRPCError(RPC_MISC_ERROR, _("This is not a masternode."));

if (activeMasternode.vin == nullopt)
bool fLegacyMN = (activeMasternode.vin != nullopt);
bool fDeterministicMN = (activeMasternodeManager != nullptr);

if (!fLegacyMN && !fDeterministicMN) {
throw JSONRPCError(RPC_MISC_ERROR, _("Active Masternode not initialized."));
}

if (fDeterministicMN) {
if (!deterministicMNManager->IsDIP3Enforced()) {
// this should never happen as ProTx transactions are not accepted yet
throw JSONRPCError(RPC_MISC_ERROR, _("Deterministic masternodes are not enforced yet"));
}
const CActiveMasternodeInfo* amninfo = activeMasternodeManager->GetInfo();
UniValue mnObj(UniValue::VOBJ);
auto dmn = deterministicMNManager->GetListAtChainTip().GetMNByOperatorKey(amninfo->keyIDOperator);
if (dmn) {
dmn->ToJson(mnObj);
}
mnObj.pushKV("netaddr", amninfo->service.ToString());
mnObj.pushKV("status", activeMasternodeManager->GetStatus());
return mnObj;
}

// Legacy code !TODO: remove when transition to DMN is complete
if (deterministicMNManager->LegacyMNObsolete()) {
throw JSONRPCError(RPC_MISC_ERROR, _("Legacy Masternode is obsolete."));
}

CMasternode* pmn = mnodeman.Find(activeMasternode.vin->prevout);

Expand Down
19 changes: 19 additions & 0 deletions test/functional/tiertwo_governance_sync_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

class MasternodeGovernanceBasicTest(PivxTier2TestFramework):

def check_mns_status_legacy(self, node, txhash):
status = node.getmasternodestatus()
assert_equal(status["txhash"], txhash)
assert_equal(status["message"], "Masternode successfully started")

def check_mns_status(self, node, txhash):
status = node.getmasternodestatus()
assert_equal(status["proTxHash"], txhash)
assert_equal(status["dmnstate"]["PoSePenalty"], 0)
assert_equal(status["status"], "Ready")

def check_budget_finalization_sync(self, votesCount, status):
for i in range(0, len(self.nodes)):
node = self.nodes[i]
Expand Down Expand Up @@ -98,6 +109,14 @@ def run_test(self):
self.enable_mocktime()
self.setup_3_masternodes_network()

# check status of masternodes
self.check_mns_status_legacy(self.remoteOne, self.mnOneTxHash)
self.log.info("MN1 active")
self.check_mns_status_legacy(self.remoteTwo, self.mnTwoTxHash)
self.log.info("MN2 active")
self.check_mns_status(self.remoteDMN, self.proRegTx)
self.log.info("DMN1 active")

# Prepare the proposal
self.log.info("preparing budget proposal..")
firstProposalName = "super-cool"
Expand Down

0 comments on commit 064f774

Please sign in to comment.