Skip to content

Commit 972d236

Browse files
committed
[RPC] Init Deterministic masternode on-demand
1 parent f93bc0f commit 972d236

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

src/activemasternode.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ OperationResult CActiveDeterministicMasternodeManager::SetOperatorKey(const std:
6969

7070
void CActiveDeterministicMasternodeManager::Init()
7171
{
72-
if (!fMasterNode || !deterministicMNManager->IsDIP3Enforced())
72+
// set masternode arg if called from RPC
73+
if (!fMasterNode) {
74+
gArgs.ForceSetArg("-masternode", "1");
75+
fMasterNode = true;
76+
}
77+
78+
if (!deterministicMNManager->IsDIP3Enforced()) {
79+
state = MASTERNODE_ERROR;
80+
strError = "Evo upgrade is not active yet.";
81+
LogPrintf("%s -- ERROR: %s\n", __func__, strError);
7382
return;
83+
}
7484

7585
LOCK(cs_main);
7686

@@ -260,6 +270,7 @@ void CActiveMasternode::ManageStatus()
260270
return;
261271
}
262272

273+
// !TODO: Legacy masternodes - remove after enforcement
263274
LogPrint(BCLog::MASTERNODE, "CActiveMasternode::ManageStatus() - Begin\n");
264275

265276
// If a DMN has been registered with same collateral, disable me.
@@ -427,3 +438,4 @@ void CActiveMasternode::GetKeys(CKey& _privKeyMasternode, CPubKey& _pubKeyMaster
427438
_privKeyMasternode = privKeyMasternode;
428439
_pubKeyMasternode = pubKeyMasternode;
429440
}
441+

src/budget/budgetmanager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,12 @@ void CBudgetManager::VoteOnFinalizedBudgets()
486486
return;
487487
}
488488

489+
// check that the active masternode is enabled
490+
if (activeMasternode.GetStatus() != ACTIVE_MASTERNODE_STARTED) {
491+
LogPrint(BCLog::MNBUDGET,"%s: MN not enabled (%s)\n", __func__, activeMasternode.GetStatusMessage());
492+
return;
493+
}
494+
489495
std::vector<CBudgetProposal> vBudget = GetBudget();
490496
if (vBudget.empty()) {
491497
LogPrint(BCLog::MNBUDGET,"%s: No proposal can be finalized\n", __func__);

src/messagesigner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool CMessageSigner::GetKeysFromSecret(const std::string& strSecret, CKey& keyRe
1919
return false;
2020

2121
pubkeyRet = keyRet.GetPubKey();
22-
return true;
22+
return pubkeyRet.IsValid();
2323
}
2424

2525
bool CMessageSigner::GetKeysFromSecret(const std::string& strSecret, CKey& keyRet, CKeyID& keyIDRet)

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static const CRPCConvertParam vRPCConvertParams[] = {
120120
{ "importpubkey", 2 },
121121
{ "importmulti", 0 },
122122
{ "importmulti", 1 },
123+
{ "initmasternode", 2},
123124
{ "exportsaplingkey", 1 },
124125
{ "importsaplingkey", 2 },
125126
{ "importsaplingviewingkey", 2 },

src/rpc/masternode.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ UniValue mnping(const JSONRPCRequest& request)
5555

5656
UniValue initmasternode(const JSONRPCRequest& request)
5757
{
58-
if (request.fHelp || (request.params.empty() || request.params.size() > 2)) {
58+
if (request.fHelp || (request.params.size() < 2|| request.params.size() > 3)) {
5959
throw std::runtime_error(
60-
"initmasternode ( \"masternodePrivKey\" \"masternodeAddr\" )\n"
60+
"initmasternode \"masternodePrivKey\" \"masternodeAddr\" ( deterministic )\n"
6161
"\nInitialize masternode on demand if it's not already initialized.\n"
6262
"\nArguments:\n"
6363
"1. masternodePrivKey (string, required) The masternode private key.\n"
6464
"2. masternodeAddr (string, required) The IP:Port of this masternode.\n"
65+
"3. deterministic (boolean, optional, default=false) Init as DMN.\n"
6566

6667
"\nResult:\n"
6768
" success (string) if the masternode initialization succeeded.\n"
@@ -73,6 +74,21 @@ UniValue initmasternode(const JSONRPCRequest& request)
7374

7475
std::string _strMasterNodePrivKey = request.params[0].get_str();
7576
std::string _strMasterNodeAddr = request.params[1].get_str();
77+
bool fDeterministic = request.params.size() > 2 && request.params[2].get_bool();
78+
if (fDeterministic) {
79+
if (!activeMasternodeManager) {
80+
activeMasternodeManager = new CActiveDeterministicMasternodeManager();
81+
RegisterValidationInterface(activeMasternodeManager);
82+
}
83+
auto res = activeMasternodeManager->SetOperatorKey(_strMasterNodePrivKey);
84+
if (!res) throw std::runtime_error(res.getError());
85+
activeMasternodeManager->Init();
86+
if (activeMasternodeManager->GetState() == CActiveDeterministicMasternodeManager::MASTERNODE_ERROR) {
87+
throw std::runtime_error(activeMasternodeManager->GetStatus());
88+
}
89+
return "success";
90+
}
91+
// legacy
7692
auto res = initMasternode(_strMasterNodePrivKey, _strMasterNodeAddr, false);
7793
if (!res) throw std::runtime_error(res.getError());
7894
return "success";
@@ -200,7 +216,7 @@ UniValue listmasternodes(const JSONRPCRequest& request)
200216
obj.pushKV("network", strNetwork);
201217
obj.pushKV("txhash", strTxHash);
202218
obj.pushKV("outidx", (uint64_t)oIdx);
203-
obj.pushKV("pubkey", HexStr(mn.pubKeyMasternode));
219+
obj.pushKV("pubkey", EncodeDestination(mn.pubKeyMasternode.GetID()));
204220
obj.pushKV("status", strStatus);
205221
obj.pushKV("addr", EncodeDestination(mn.pubKeyCollateralAddress.GetID()));
206222
obj.pushKV("version", mn.protocolVersion);

0 commit comments

Comments
 (0)