Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ OperationResult initMasternode(const std::string& _strMasterNodePrivKey, const s

// Global params set
strMasterNodeAddr = _strMasterNodeAddr;
strMasterNodePrivKey = _strMasterNodePrivKey;

// Address parsing.
const CChainParams& params = Params();
Expand All @@ -56,11 +55,12 @@ OperationResult initMasternode(const std::string& _strMasterNodePrivKey, const s

CKey key;
CPubKey pubkey;

if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, key, pubkey)) {
if (!CMessageSigner::GetKeysFromSecret(_strMasterNodePrivKey, key, pubkey)) {
return errorOut(_("Invalid masternodeprivkey. Please see the documentation."));
}

activeMasternode.pubKeyMasternode = pubkey;
activeMasternode.privKeyMasternode = key;
fMasterNode = true;
return OperationResult(true);
}
Expand Down Expand Up @@ -169,19 +169,16 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
return false;
}

CPubKey pubKeyMasternode;
CKey keyMasternode;

if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
errorMessage = "Error upon calling GetKeysFromSecret.\n";
if (!privKeyMasternode.IsValid() || !pubKeyMasternode.IsValid()) {
errorMessage = "Error upon masternode key.\n";
return false;
}
Comment thread
furszy marked this conversation as resolved.

LogPrintf("CActiveMasternode::SendMasternodePing() - Relay Masternode Ping vin = %s\n", vin->ToString());

const uint256& nBlockHash = mnodeman.GetBlockHashToPing();
CMasternodePing mnp(*vin, nBlockHash);
if (!mnp.Sign(keyMasternode, pubKeyMasternode)) {
if (!mnp.Sign(privKeyMasternode, pubKeyMasternode)) {
errorMessage = "Couldn't sign Masternode Ping";
return false;
}
Expand Down Expand Up @@ -234,3 +231,12 @@ bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newServ

return true;
}

void CActiveMasternode::GetKeys(CKey& _privKeyMasternode, CPubKey& _pubKeyMasternode)
{
if (!privKeyMasternode.IsValid() || !pubKeyMasternode.IsValid()) {
throw std::runtime_error("Error trying to get masternode keys");
}
_privKeyMasternode = privKeyMasternode;
_pubKeyMasternode = pubKeyMasternode;
}
3 changes: 3 additions & 0 deletions src/activemasternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CActiveMasternode
// Initialized by init.cpp
// Keys for the main Masternode
CPubKey pubKeyMasternode;
CKey privKeyMasternode;

// Initialized while registering Masternode
Optional<CTxIn> vin;
Expand All @@ -55,6 +56,8 @@ class CActiveMasternode
bool SendMasternodePing(std::string& errorMessage);
/// Enable cold wallet mode (run a Masternode with no funds)
bool EnableHotColdMasterNode(CTxIn& vin, CService& addr);

void GetKeys(CKey& privKeyMasternode, CPubKey& pubKeyMasternode);
};

#endif
6 changes: 2 additions & 4 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,8 @@ void CBudgetManager::VoteOnFinalizedBudgets()
// Get masternode keys
CPubKey pubKeyMasternode;
CKey keyMasternode;
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
LogPrintf("%s: Unable to get masternode keys\n", __func__);
return;
}
activeMasternode.GetKeys(keyMasternode, pubKeyMasternode);

// Sign finalized budgets
for (const uint256& budgetHash: vBudgetHashes) {
CFinalizedBudgetVote vote(*(activeMasternode.vin), budgetHash);
Expand Down
10 changes: 2 additions & 8 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,8 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
}
}

std::string errorMessage;
CPubKey pubKeyMasternode;
CKey keyMasternode;

if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
LogPrint(BCLog::MASTERNODE,"CMasternodePayments::ProcessBlock() - Error upon calling GetKeysFromSecret.\n");
return false;
}
CPubKey pubKeyMasternode; CKey keyMasternode;
activeMasternode.GetKeys(keyMasternode, pubKeyMasternode);

LogPrint(BCLog::MASTERNODE,"CMasternodePayments::ProcessBlock() - Signing Winner\n");
if (newWinner.Sign(keyMasternode, pubKeyMasternode)) {
Expand Down
1 change: 0 additions & 1 deletion src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class CActiveMasternode;

extern CMasternodeMan mnodeman;
extern CActiveMasternode activeMasternode;
extern std::string strMasterNodePrivKey;

void DumpMasternodes();

Expand Down
17 changes: 4 additions & 13 deletions src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,8 @@ UniValue mnbudgetvote(const JSONRPCRequest& request)
UniValue statusObj(UniValue::VOBJ);

while (true) {
if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode)) {
failed++;
statusObj.pushKV("node", "local");
statusObj.pushKV("result", "failed");
statusObj.pushKV("error", "Masternode signing error, GetKeysFromSecret failed.");
resultsObj.push_back(statusObj);
break;
}
// Get MN keys
activeMasternode.GetKeys(keyMasternode, pubKeyMasternode);

CMasternode* pmn = mnodeman.Find(activeMasternode.vin->prevout);
if (pmn == NULL) {
Expand Down Expand Up @@ -816,11 +810,8 @@ UniValue mnfinalbudget(const JSONRPCRequest& request)
std::string strHash = request.params[1].get_str();
uint256 hash(uint256S(strHash));

CPubKey pubKeyMasternode;
CKey keyMasternode;

if (!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, keyMasternode, pubKeyMasternode))
return "Error upon calling GetKeysFromSecret";
CPubKey pubKeyMasternode; CKey keyMasternode;
activeMasternode.GetKeys(keyMasternode, pubKeyMasternode);

CMasternode* pmn = mnodeman.Find(activeMasternode.vin->prevout);
if (pmn == NULL) {
Expand Down
1 change: 0 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const char * const PIVX_MASTERNODE_CONF_FILENAME = "masternode.conf";
// PIVX only features
// Masternode
std::atomic<bool> fMasterNode{false};
std::string strMasterNodePrivKey = "";
std::string strMasterNodeAddr = "";
bool fLiteMode = false;

Expand Down