Masternode related refactorings in preparation of DIP3 (#2212)

* Split CActiveMasternode into CActiveMasternodeInfo and CLegacyActiveMasternodeManager

* Use CKeyID instead of CPubKey whenever possible in masternode code

* Rename activeMasternode to activeMasternodeInfo and make it a struct

* Rename pubKeyIDXXX to keyIDXXX

* Bump SERIALIZATION_VERSION_STRING

* Fix build error after rebase

* Fix compilation warning/error with clang
This commit is contained in:
Alexander Block 2018-08-11 21:55:56 +02:00 committed by UdjinM6
parent 633879cd28
commit d946f21bd9
23 changed files with 277 additions and 256 deletions

View File

@ -11,19 +11,19 @@
#include "netbase.h" #include "netbase.h"
// Keep track of the active Masternode // Keep track of the active Masternode
CActiveMasternode activeMasternode; CActiveMasternodeInfo activeMasternodeInfo;
CActiveLegacyMasternodeManager legacyActiveMasternodeManager;
void CActiveMasternode::ManageState(CConnman& connman) void CActiveLegacyMasternodeManager::ManageState(CConnman& connman)
{ {
LogPrint("masternode", "CActiveMasternode::ManageState -- Start\n"); LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- Start\n");
if(!fMasternodeMode) { if(!fMasternodeMode) {
LogPrint("masternode", "CActiveMasternode::ManageState -- Not a masternode, returning\n"); LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- Not a masternode, returning\n");
return; return;
} }
if(Params().NetworkIDString() != CBaseChainParams::REGTEST && !masternodeSync.IsBlockchainSynced()) { if(Params().NetworkIDString() != CBaseChainParams::REGTEST && !masternodeSync.IsBlockchainSynced()) {
nState = ACTIVE_MASTERNODE_SYNC_IN_PROCESS; nState = ACTIVE_MASTERNODE_SYNC_IN_PROCESS;
LogPrintf("CActiveMasternode::ManageState -- %s: %s\n", GetStateString(), GetStatus()); LogPrintf("CActiveLegacyMasternodeManager::ManageState -- %s: %s\n", GetStateString(), GetStatus());
return; return;
} }
@ -31,7 +31,7 @@ void CActiveMasternode::ManageState(CConnman& connman)
nState = ACTIVE_MASTERNODE_INITIAL; nState = ACTIVE_MASTERNODE_INITIAL;
} }
LogPrint("masternode", "CActiveMasternode::ManageState -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled);
if(eType == MASTERNODE_UNKNOWN) { if(eType == MASTERNODE_UNKNOWN) {
ManageStateInitial(connman); ManageStateInitial(connman);
@ -44,7 +44,7 @@ void CActiveMasternode::ManageState(CConnman& connman)
SendMasternodePing(connman); SendMasternodePing(connman);
} }
std::string CActiveMasternode::GetStateString() const std::string CActiveLegacyMasternodeManager::GetStateString() const
{ {
switch (nState) { switch (nState) {
case ACTIVE_MASTERNODE_INITIAL: return "INITIAL"; case ACTIVE_MASTERNODE_INITIAL: return "INITIAL";
@ -56,7 +56,7 @@ std::string CActiveMasternode::GetStateString() const
} }
} }
std::string CActiveMasternode::GetStatus() const std::string CActiveLegacyMasternodeManager::GetStatus() const
{ {
switch (nState) { switch (nState) {
case ACTIVE_MASTERNODE_INITIAL: return "Node just started, not yet activated"; case ACTIVE_MASTERNODE_INITIAL: return "Node just started, not yet activated";
@ -68,7 +68,7 @@ std::string CActiveMasternode::GetStatus() const
} }
} }
std::string CActiveMasternode::GetTypeString() const std::string CActiveLegacyMasternodeManager::GetTypeString() const
{ {
std::string strType; std::string strType;
switch(eType) { switch(eType) {
@ -82,44 +82,44 @@ std::string CActiveMasternode::GetTypeString() const
return strType; return strType;
} }
bool CActiveMasternode::SendMasternodePing(CConnman& connman) bool CActiveLegacyMasternodeManager::SendMasternodePing(CConnman& connman)
{ {
if(!fPingerEnabled) { if(!fPingerEnabled) {
LogPrint("masternode", "CActiveMasternode::SendMasternodePing -- %s: masternode ping service is disabled, skipping...\n", GetStateString()); LogPrint("masternode", "CActiveLegacyMasternodeManager::SendMasternodePing -- %s: masternode ping service is disabled, skipping...\n", GetStateString());
return false; return false;
} }
if(!mnodeman.Has(outpoint)) { if(!mnodeman.Has(activeMasternodeInfo.outpoint)) {
strNotCapableReason = "Masternode not in masternode list"; strNotCapableReason = "Masternode not in masternode list";
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
LogPrintf("CActiveMasternode::SendMasternodePing -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- %s: %s\n", GetStateString(), strNotCapableReason);
return false; return false;
} }
CMasternodePing mnp(outpoint); CMasternodePing mnp(activeMasternodeInfo.outpoint);
mnp.nSentinelVersion = nSentinelVersion; mnp.nSentinelVersion = nSentinelVersion;
mnp.fSentinelIsCurrent = mnp.fSentinelIsCurrent =
(abs(GetAdjustedTime() - nSentinelPingTime) < MASTERNODE_SENTINEL_PING_MAX_SECONDS); (abs(GetAdjustedTime() - nSentinelPingTime) < MASTERNODE_SENTINEL_PING_MAX_SECONDS);
if(!mnp.Sign(keyMasternode, pubKeyMasternode)) { if(!mnp.Sign(activeMasternodeInfo.keyMasternode, activeMasternodeInfo.keyIDMasternode)) {
LogPrintf("CActiveMasternode::SendMasternodePing -- ERROR: Couldn't sign Masternode Ping\n"); LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- ERROR: Couldn't sign Masternode Ping\n");
return false; return false;
} }
// Update lastPing for our masternode in Masternode list // Update lastPing for our masternode in Masternode list
if(mnodeman.IsMasternodePingedWithin(outpoint, MASTERNODE_MIN_MNP_SECONDS, mnp.sigTime)) { if(mnodeman.IsMasternodePingedWithin(activeMasternodeInfo.outpoint, MASTERNODE_MIN_MNP_SECONDS, mnp.sigTime)) {
LogPrintf("CActiveMasternode::SendMasternodePing -- Too early to send Masternode Ping\n"); LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- Too early to send Masternode Ping\n");
return false; return false;
} }
mnodeman.SetMasternodeLastPing(outpoint, mnp); mnodeman.SetMasternodeLastPing(activeMasternodeInfo.outpoint, mnp);
LogPrintf("CActiveMasternode::SendMasternodePing -- Relaying ping, collateral=%s\n", outpoint.ToStringShort()); LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- Relaying ping, collateral=%s\n", activeMasternodeInfo.outpoint.ToStringShort());
mnp.Relay(connman); mnp.Relay(connman);
return true; return true;
} }
bool CActiveMasternode::UpdateSentinelPing(int version) bool CActiveLegacyMasternodeManager::UpdateSentinelPing(int version)
{ {
nSentinelVersion = version; nSentinelVersion = version;
nSentinelPingTime = GetAdjustedTime(); nSentinelPingTime = GetAdjustedTime();
@ -127,41 +127,41 @@ bool CActiveMasternode::UpdateSentinelPing(int version)
return true; return true;
} }
void CActiveMasternode::ManageStateInitial(CConnman& connman) void CActiveLegacyMasternodeManager::ManageStateInitial(CConnman& connman)
{ {
LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled);
// Check that our local network configuration is correct // Check that our local network configuration is correct
if (!fListen) { if (!fListen) {
// listen option is probably overwritten by smth else, no good // listen option is probably overwritten by smth else, no good
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter."; strNotCapableReason = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter.";
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
// First try to find whatever local address is specified by externalip option // First try to find whatever local address is specified by externalip option
bool fFoundLocal = GetLocal(service) && CMasternode::IsValidNetAddr(service); bool fFoundLocal = GetLocal(activeMasternodeInfo.service) && CMasternode::IsValidNetAddr(activeMasternodeInfo.service);
if(!fFoundLocal) { if(!fFoundLocal) {
bool empty = true; bool empty = true;
// If we have some peers, let's try to find our local address from one of them // If we have some peers, let's try to find our local address from one of them
connman.ForEachNodeContinueIf(CConnman::AllNodes, [&fFoundLocal, &empty, this](CNode* pnode) { connman.ForEachNodeContinueIf(CConnman::AllNodes, [&fFoundLocal, &empty, this](CNode* pnode) {
empty = false; empty = false;
if (pnode->addr.IsIPv4()) if (pnode->addr.IsIPv4())
fFoundLocal = GetLocal(service, &pnode->addr) && CMasternode::IsValidNetAddr(service); fFoundLocal = GetLocal(activeMasternodeInfo.service, &pnode->addr) && CMasternode::IsValidNetAddr(activeMasternodeInfo.service);
return !fFoundLocal; return !fFoundLocal;
}); });
// nothing and no live connections, can't do anything for now // nothing and no live connections, can't do anything for now
if (empty) { if (empty) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Can't detect valid external address. Will retry when there are some connections available."; strNotCapableReason = "Can't detect valid external address. Will retry when there are some connections available.";
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
} }
if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) { if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) {
if (Lookup("127.0.0.1", activeMasternode.service, GetListenPort(), false)) { if (Lookup("127.0.0.1", activeMasternodeInfo.service, GetListenPort(), false)) {
fFoundLocal = true; fFoundLocal = true;
} }
} }
@ -169,75 +169,75 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman)
if(!fFoundLocal) { if(!fFoundLocal) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only."; strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only.";
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort();
if(Params().NetworkIDString() == CBaseChainParams::MAIN) { if(Params().NetworkIDString() == CBaseChainParams::MAIN) {
if(service.GetPort() != mainnetDefaultPort) { if(activeMasternodeInfo.service.GetPort() != mainnetDefaultPort) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = strprintf("Invalid port: %u - only %d is supported on mainnet.", service.GetPort(), mainnetDefaultPort); strNotCapableReason = strprintf("Invalid port: %u - only %d is supported on mainnet.", activeMasternodeInfo.service.GetPort(), mainnetDefaultPort);
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
} else if(service.GetPort() == mainnetDefaultPort) { } else if(activeMasternodeInfo.service.GetPort() == mainnetDefaultPort) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = strprintf("Invalid port: %u - %d is only supported on mainnet.", service.GetPort(), mainnetDefaultPort); strNotCapableReason = strprintf("Invalid port: %u - %d is only supported on mainnet.", activeMasternodeInfo.service.GetPort(), mainnetDefaultPort);
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
if(Params().NetworkIDString() != CBaseChainParams::REGTEST) { if(Params().NetworkIDString() != CBaseChainParams::REGTEST) {
// Check socket connectivity // Check socket connectivity
LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- Checking inbound connection to '%s'\n", activeMasternodeInfo.service.ToString());
SOCKET hSocket; SOCKET hSocket;
bool fConnected = ConnectSocket(service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket); bool fConnected = ConnectSocket(activeMasternodeInfo.service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket);
CloseSocket(hSocket); CloseSocket(hSocket);
if (!fConnected) { if (!fConnected) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Could not connect to " + service.ToString(); strNotCapableReason = "Could not connect to " + activeMasternodeInfo.service.ToString();
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
} }
// Default to REMOTE // Default to REMOTE
eType = MASTERNODE_REMOTE; eType = MASTERNODE_REMOTE;
LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled);
} }
void CActiveMasternode::ManageStateRemote() void CActiveLegacyMasternodeManager::ManageStateRemote()
{ {
LogPrint("masternode", "CActiveMasternode::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, pubKeyMasternode.GetID() = %s\n", LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, keyIDMasternode = %s\n",
GetStatus(), GetTypeString(), fPingerEnabled, pubKeyMasternode.GetID().ToString()); GetStatus(), GetTypeString(), fPingerEnabled, activeMasternodeInfo.keyIDMasternode.ToString());
mnodeman.CheckMasternode(pubKeyMasternode, true); mnodeman.CheckMasternode(activeMasternodeInfo.keyIDMasternode, true);
masternode_info_t infoMn; masternode_info_t infoMn;
if(mnodeman.GetMasternodeInfo(pubKeyMasternode, infoMn)) { if(mnodeman.GetMasternodeInfo(activeMasternodeInfo.keyIDMasternode, infoMn)) {
if(infoMn.nProtocolVersion != PROTOCOL_VERSION) { if(infoMn.nProtocolVersion != PROTOCOL_VERSION) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Invalid protocol version"; strNotCapableReason = "Invalid protocol version";
LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
if(service != infoMn.addr) { if(activeMasternodeInfo.service != infoMn.addr) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Broadcasted IP doesn't match our external address. Make sure you issued a new broadcast if IP of this masternode changed recently."; strNotCapableReason = "Broadcasted IP doesn't match our external address. Make sure you issued a new broadcast if IP of this masternode changed recently.";
LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
if(!CMasternode::IsValidStateForAutoStart(infoMn.nActiveState)) { if(!CMasternode::IsValidStateForAutoStart(infoMn.nActiveState)) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = strprintf("Masternode in %s state", CMasternode::StateToString(infoMn.nActiveState)); strNotCapableReason = strprintf("Masternode in %s state", CMasternode::StateToString(infoMn.nActiveState));
LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
if(nState != ACTIVE_MASTERNODE_STARTED) { if(nState != ACTIVE_MASTERNODE_STARTED) {
LogPrintf("CActiveMasternode::ManageStateRemote -- STARTED!\n"); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- STARTED!\n");
outpoint = infoMn.outpoint; activeMasternodeInfo.outpoint = infoMn.outpoint;
service = infoMn.addr; activeMasternodeInfo.service = infoMn.addr;
fPingerEnabled = true; fPingerEnabled = true;
nState = ACTIVE_MASTERNODE_STARTED; nState = ACTIVE_MASTERNODE_STARTED;
} }
@ -245,6 +245,6 @@ void CActiveMasternode::ManageStateRemote()
else { else {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; nState = ACTIVE_MASTERNODE_NOT_CAPABLE;
strNotCapableReason = "Masternode not in masternode list"; strNotCapableReason = "Masternode not in masternode list";
LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason);
} }
} }

View File

@ -10,7 +10,8 @@
#include "net.h" #include "net.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
class CActiveMasternode; struct CActiveMasternodeInfo;
class CActiveLegacyMasternodeManager;
static const int ACTIVE_MASTERNODE_INITIAL = 0; // initial state static const int ACTIVE_MASTERNODE_INITIAL = 0; // initial state
static const int ACTIVE_MASTERNODE_SYNC_IN_PROCESS = 1; static const int ACTIVE_MASTERNODE_SYNC_IN_PROCESS = 1;
@ -18,10 +19,21 @@ static const int ACTIVE_MASTERNODE_INPUT_TOO_NEW = 2;
static const int ACTIVE_MASTERNODE_NOT_CAPABLE = 3; static const int ACTIVE_MASTERNODE_NOT_CAPABLE = 3;
static const int ACTIVE_MASTERNODE_STARTED = 4; static const int ACTIVE_MASTERNODE_STARTED = 4;
extern CActiveMasternode activeMasternode; extern CActiveMasternodeInfo activeMasternodeInfo;
extern CActiveLegacyMasternodeManager legacyActiveMasternodeManager;
struct CActiveMasternodeInfo {
// Keys for the active Masternode
CKeyID keyIDMasternode;
CKey keyMasternode;
// Initialized while registering Masternode
COutPoint outpoint;
CService service;
};
// Responsible for activating the Masternode and pinging the network // Responsible for activating the Masternode and pinging the network
class CActiveMasternode class CActiveLegacyMasternodeManager
{ {
public: public:
enum masternode_type_enum_t { enum masternode_type_enum_t {
@ -45,25 +57,13 @@ private:
uint32_t nSentinelVersion; uint32_t nSentinelVersion;
public: public:
// Keys for the active Masternode
CPubKey pubKeyMasternode;
CKey keyMasternode;
// Initialized while registering Masternode
COutPoint outpoint;
CService service;
int nState; // should be one of ACTIVE_MASTERNODE_XXXX int nState; // should be one of ACTIVE_MASTERNODE_XXXX
std::string strNotCapableReason; std::string strNotCapableReason;
CActiveMasternode() CActiveLegacyMasternodeManager()
: eType(MASTERNODE_UNKNOWN), : eType(MASTERNODE_UNKNOWN),
fPingerEnabled(false), fPingerEnabled(false),
pubKeyMasternode(),
keyMasternode(),
outpoint(),
service(),
nState(ACTIVE_MASTERNODE_INITIAL) nState(ACTIVE_MASTERNODE_INITIAL)
{} {}

View File

@ -265,7 +265,7 @@ void CGovernanceObject::SetMasternodeOutpoint(const COutPoint& outpoint)
masternodeOutpoint = outpoint; masternodeOutpoint = outpoint;
} }
bool CGovernanceObject::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) bool CGovernanceObject::Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode)
{ {
std::string strError; std::string strError;
@ -277,7 +277,7 @@ bool CGovernanceObject::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMas
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
LogPrintf("CGovernanceObject::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CGovernanceObject::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
@ -288,30 +288,30 @@ bool CGovernanceObject::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMas
return false; return false;
} }
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceObject::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CGovernanceObject::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
} }
LogPrint("gobject", "CGovernanceObject::Sign -- pubkey id = %s, masternode = %s\n", LogPrint("gobject", "CGovernanceObject::Sign -- pubkey id = %s, masternode = %s\n",
pubKeyMasternode.GetID().ToString(), masternodeOutpoint.ToStringShort()); keyIDMasternode.ToString(), masternodeOutpoint.ToStringShort());
return true; return true;
} }
bool CGovernanceObject::CheckSignature(const CPubKey& pubKeyMasternode) const bool CGovernanceObject::CheckSignature(const CKeyID& keyIDMasternode) const
{ {
std::string strError; std::string strError;
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
// could be an old object // could be an old object
std::string strMessage = GetSignatureMessage(); std::string strMessage = GetSignatureMessage();
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
@ -320,7 +320,7 @@ bool CGovernanceObject::CheckSignature(const CPubKey& pubKeyMasternode) const
} else { } else {
std::string strMessage = GetSignatureMessage(); std::string strMessage = GetSignatureMessage();
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CGovernance::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -490,7 +490,7 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
masternode_info_t infoMn; masternode_info_t infoMn;
if (!mnodeman.GetMasternodeInfo(masternodeOutpoint, infoMn)) { if (!mnodeman.GetMasternodeInfo(masternodeOutpoint, infoMn)) {
CMasternode::CollateralStatus err = CMasternode::CheckCollateral(masternodeOutpoint, CPubKey()); CMasternode::CollateralStatus err = CMasternode::CheckCollateral(masternodeOutpoint, CKeyID());
if (err == CMasternode::COLLATERAL_UTXO_NOT_FOUND) { if (err == CMasternode::COLLATERAL_UTXO_NOT_FOUND) {
strError = "Failed to find Masternode UTXO, missing masternode=" + strOutpoint + "\n"; strError = "Failed to find Masternode UTXO, missing masternode=" + strOutpoint + "\n";
} else if (err == CMasternode::COLLATERAL_INVALID_AMOUNT) { } else if (err == CMasternode::COLLATERAL_INVALID_AMOUNT) {
@ -507,8 +507,8 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
} }
// Check that we have a valid MN signature // Check that we have a valid MN signature
if (!CheckSignature(infoMn.pubKeyMasternode)) { if (!CheckSignature(infoMn.keyIDMasternode)) {
strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey id = " + infoMn.pubKeyMasternode.GetID().ToString(); strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey id = " + infoMn.keyIDMasternode.ToString();
return false; return false;
} }

View File

@ -251,8 +251,8 @@ public:
// Signature related functions // Signature related functions
void SetMasternodeOutpoint(const COutPoint& outpoint); void SetMasternodeOutpoint(const COutPoint& outpoint);
bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); bool Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode);
bool CheckSignature(const CPubKey& pubKeyMasternode) const; bool CheckSignature(const CKeyID& keyIDMasternode) const;
std::string GetSignatureMessage() const; std::string GetSignatureMessage() const;
uint256 GetSignatureHash() const; uint256 GetSignatureHash() const;

View File

@ -152,7 +152,7 @@ uint256 CGovernanceVote::GetSignatureHash() const
return SerializeHash(*this); return SerializeHash(*this);
} }
bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) bool CGovernanceVote::Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode)
{ {
std::string strError; std::string strError;
@ -164,7 +164,7 @@ bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
LogPrintf("CGovernanceVote::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CGovernanceVote::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
@ -178,7 +178,7 @@ bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return false; return false;
} }
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CGovernanceVote::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CGovernanceVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -187,21 +187,21 @@ bool CGovernanceVote::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return true; return true;
} }
bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const bool CGovernanceVote::CheckSignature(const CKeyID& keyIDMasternode) const
{ {
std::string strError; std::string strError;
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
// could be a signature in old format // could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" + std::string strMessage = masternodeOutpoint.ToStringShort() + "|" + nParentHash.ToString() + "|" +
std::to_string(nVoteSignal) + "|" + std::to_string(nVoteSignal) + "|" +
std::to_string(nVoteOutcome) + "|" + std::to_string(nVoteOutcome) + "|" +
std::to_string(nTime); std::to_string(nTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError); LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
@ -213,7 +213,7 @@ bool CGovernanceVote::CheckSignature(const CPubKey& pubKeyMasternode) const
std::to_string(nVoteOutcome) + "|" + std::to_string(nVoteOutcome) + "|" +
std::to_string(nTime); std::to_string(nTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError); LogPrint("gobject", "CGovernanceVote::IsValid -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -251,7 +251,7 @@ bool CGovernanceVote::IsValid(bool fSignatureCheck) const
if(!fSignatureCheck) return true; if(!fSignatureCheck) return true;
return CheckSignature(infoMn.pubKeyMasternode); return CheckSignature(infoMn.keyIDMasternode);
} }
bool operator==(const CGovernanceVote& vote1, const CGovernanceVote& vote2) bool operator==(const CGovernanceVote& vote1, const CGovernanceVote& vote2)

View File

@ -90,8 +90,8 @@ public:
void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; } void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; }
bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); bool Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode);
bool CheckSignature(const CPubKey& pubKeyMasternode) const; bool CheckSignature(const CKeyID& keyIDMasternode) const;
bool IsValid(bool fSignatureCheck) const; bool IsValid(bool fSignatureCheck) const;
void Relay(CConnman& connman) const; void Relay(CConnman& connman) const;

View File

@ -1851,10 +1851,13 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string strMasterNodePrivKey = GetArg("-masternodeprivkey", ""); std::string strMasterNodePrivKey = GetArg("-masternodeprivkey", "");
if(!strMasterNodePrivKey.empty()) { if(!strMasterNodePrivKey.empty()) {
if(!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, activeMasternode.keyMasternode, activeMasternode.pubKeyMasternode)) CPubKey pubKeyMasternode;
if(!CMessageSigner::GetKeysFromSecret(strMasterNodePrivKey, activeMasternodeInfo.keyMasternode, pubKeyMasternode))
return InitError(_("Invalid masternodeprivkey. Please see documenation.")); return InitError(_("Invalid masternodeprivkey. Please see documenation."));
LogPrintf(" pubKeyMasternode: %s\n", CBitcoinAddress(activeMasternode.pubKeyMasternode.GetID()).ToString()); activeMasternodeInfo.keyIDMasternode = pubKeyMasternode.GetID();
LogPrintf(" keyIDMasternode: %s\n", CBitcoinAddress(activeMasternodeInfo.keyIDMasternode).ToString());
} else { } else {
return InitError(_("You must specify a masternodeprivkey in the configuration. Please see documentation for help.")); return InitError(_("You must specify a masternodeprivkey in the configuration. Please see documentation for help."));
} }
@ -1973,7 +1976,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
scheduler.scheduleEvery(boost::bind(&CNetFulfilledRequestManager::DoMaintenance, boost::ref(netfulfilledman)), 60); scheduler.scheduleEvery(boost::bind(&CNetFulfilledRequestManager::DoMaintenance, boost::ref(netfulfilledman)), 60);
scheduler.scheduleEvery(boost::bind(&CMasternodeSync::DoMaintenance, boost::ref(masternodeSync), boost::ref(*g_connman)), MASTERNODE_SYNC_TICK_SECONDS); scheduler.scheduleEvery(boost::bind(&CMasternodeSync::DoMaintenance, boost::ref(masternodeSync), boost::ref(*g_connman)), MASTERNODE_SYNC_TICK_SECONDS);
scheduler.scheduleEvery(boost::bind(&CMasternodeMan::DoMaintenance, boost::ref(mnodeman), boost::ref(*g_connman)), 1); scheduler.scheduleEvery(boost::bind(&CMasternodeMan::DoMaintenance, boost::ref(mnodeman), boost::ref(*g_connman)), 1);
scheduler.scheduleEvery(boost::bind(&CActiveMasternode::DoMaintenance, boost::ref(activeMasternode), boost::ref(*g_connman)), MASTERNODE_MIN_MNP_SECONDS); scheduler.scheduleEvery(boost::bind(&CActiveLegacyMasternodeManager::DoMaintenance, boost::ref(legacyActiveMasternodeManager), boost::ref(*g_connman)), MASTERNODE_MIN_MNP_SECONDS);
scheduler.scheduleEvery(boost::bind(&CMasternodePayments::DoMaintenance, boost::ref(mnpayments)), 60); scheduler.scheduleEvery(boost::bind(&CMasternodePayments::DoMaintenance, boost::ref(mnpayments)), 60);
scheduler.scheduleEvery(boost::bind(&CGovernanceManager::DoMaintenance, boost::ref(governance), boost::ref(*g_connman)), 60 * 5); scheduler.scheduleEvery(boost::bind(&CGovernanceManager::DoMaintenance, boost::ref(governance), boost::ref(*g_connman)), 60 * 5);

View File

@ -233,8 +233,8 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
int nRank; int nRank;
int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto()); int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto());
if(!mnodeman.GetMasternodeRank(activeMasternode.outpoint, nRank, nLockInputHeight, nMinRequiredProtocol)) { if(!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, nLockInputHeight, nMinRequiredProtocol)) {
LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternode.outpoint.ToStringShort()); LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternodeInfo.outpoint.ToStringShort());
continue; continue;
} }
@ -254,7 +254,7 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
if(itVoted != mapVotedOutpoints.end()) { if(itVoted != mapVotedOutpoints.end()) {
for (const auto& hash : itVoted->second) { for (const auto& hash : itVoted->second) {
std::map<uint256, CTxLockCandidate>::iterator it2 = mapTxLockCandidates.find(hash); std::map<uint256, CTxLockCandidate>::iterator it2 = mapTxLockCandidates.find(hash);
if(it2->second.HasMasternodeVoted(outpointLockPair.first, activeMasternode.outpoint)) { if(it2->second.HasMasternodeVoted(outpointLockPair.first, activeMasternodeInfo.outpoint)) {
// we already voted for this outpoint to be included either in the same tx or in a competing one, // we already voted for this outpoint to be included either in the same tx or in a competing one,
// skip it anyway // skip it anyway
fAlreadyVoted = true; fAlreadyVoted = true;
@ -269,7 +269,7 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
} }
// we haven't voted for this outpoint yet, let's try to do this now // we haven't voted for this outpoint yet, let's try to do this now
CTxLockVote vote(txHash, outpointLockPair.first, activeMasternode.outpoint); CTxLockVote vote(txHash, outpointLockPair.first, activeMasternodeInfo.outpoint);
if(!vote.Sign()) { if(!vote.Sign()) {
LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n"); LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n");
@ -1059,10 +1059,10 @@ bool CTxLockVote::CheckSignature() const
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, infoMn.pubKeyMasternode, vchMasternodeSignature, strError)) { if (!CHashSigner::VerifyHash(hash, infoMn.keyIDMasternode, vchMasternodeSignature, strError)) {
// could be a signature in old format // could be a signature in old format
std::string strMessage = txHash.ToString() + outpoint.ToStringShort(); std::string strMessage = txHash.ToString() + outpoint.ToStringShort();
if(!CMessageSigner::VerifyMessage(infoMn.pubKeyMasternode, vchMasternodeSignature, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(infoMn.keyIDMasternode, vchMasternodeSignature, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
LogPrintf("CTxLockVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CTxLockVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
@ -1070,7 +1070,7 @@ bool CTxLockVote::CheckSignature() const
} }
} else { } else {
std::string strMessage = txHash.ToString() + outpoint.ToStringShort(); std::string strMessage = txHash.ToString() + outpoint.ToStringShort();
if(!CMessageSigner::VerifyMessage(infoMn.pubKeyMasternode, vchMasternodeSignature, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(infoMn.keyIDMasternode, vchMasternodeSignature, strMessage, strError)) {
LogPrintf("CTxLockVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CTxLockVote::CheckSignature -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -1086,24 +1086,24 @@ bool CTxLockVote::Sign()
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if(!CHashSigner::SignHash(hash, activeMasternode.keyMasternode, vchMasternodeSignature)) { if(!CHashSigner::SignHash(hash, activeMasternodeInfo.keyMasternode, vchMasternodeSignature)) {
LogPrintf("CTxLockVote::Sign -- SignHash() failed\n"); LogPrintf("CTxLockVote::Sign -- SignHash() failed\n");
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, activeMasternode.pubKeyMasternode, vchMasternodeSignature, strError)) { if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.keyIDMasternode, vchMasternodeSignature, strError)) {
LogPrintf("CTxLockVote::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CTxLockVote::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
} else { } else {
std::string strMessage = txHash.ToString() + outpoint.ToStringShort(); std::string strMessage = txHash.ToString() + outpoint.ToStringShort();
if(!CMessageSigner::SignMessage(strMessage, vchMasternodeSignature, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchMasternodeSignature, activeMasternodeInfo.keyMasternode)) {
LogPrintf("CTxLockVote::Sign -- SignMessage() failed\n"); LogPrintf("CTxLockVote::Sign -- SignMessage() failed\n");
return false; return false;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, vchMasternodeSignature, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, vchMasternodeSignature, strMessage, strError)) {
LogPrintf("CTxLockVote::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CTxLockVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }

View File

@ -264,7 +264,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int nBlockH
return; return;
} }
// fill payee with locally calculated winner and hope for the best // fill payee with locally calculated winner and hope for the best
payee = GetScriptForDestination(mnInfo.pubKeyCollateralAddress.GetID()); payee = GetScriptForDestination(mnInfo.keyIDCollateralAddress);
} }
// GET MASTERNODE PAYMENT VARIABLES SETUP // GET MASTERNODE PAYMENT VARIABLES SETUP
@ -384,7 +384,7 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, const std::string& strCom
} }
int nDos = 0; int nDos = 0;
if(!vote.CheckSignature(mnInfo.pubKeyMasternode, nCachedBlockHeight, nDos)) { if(!vote.CheckSignature(mnInfo.keyIDMasternode, nCachedBlockHeight, nDos)) {
if(nDos) { if(nDos) {
LOCK(cs_main); LOCK(cs_main);
LogPrintf("MASTERNODEPAYMENTVOTE -- ERROR: invalid signature\n"); LogPrintf("MASTERNODEPAYMENTVOTE -- ERROR: invalid signature\n");
@ -444,12 +444,12 @@ bool CMasternodePaymentVote::Sign()
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if(!CHashSigner::SignHash(hash, activeMasternode.keyMasternode, vchSig)) { if(!CHashSigner::SignHash(hash, activeMasternodeInfo.keyMasternode, vchSig)) {
LogPrintf("CMasternodePaymentVote::Sign -- SignHash() failed\n"); LogPrintf("CMasternodePaymentVote::Sign -- SignHash() failed\n");
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, activeMasternode.pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.keyIDMasternode, vchSig, strError)) {
LogPrintf("CMasternodePaymentVote::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CMasternodePaymentVote::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
@ -458,12 +458,12 @@ bool CMasternodePaymentVote::Sign()
std::to_string(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternodeInfo.keyMasternode)) {
LogPrintf("CMasternodePaymentVote::Sign -- SignMessage() failed\n"); LogPrintf("CMasternodePaymentVote::Sign -- SignMessage() failed\n");
return false; return false;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePaymentVote::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CMasternodePaymentVote::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -489,7 +489,7 @@ bool CMasternodePayments::IsScheduled(const masternode_info_t& mnInfo, int nNotB
if(!masternodeSync.IsMasternodeListSynced()) return false; if(!masternodeSync.IsMasternodeListSynced()) return false;
CScript mnpayee; CScript mnpayee;
mnpayee = GetScriptForDestination(mnInfo.pubKeyCollateralAddress.GetID()); mnpayee = GetScriptForDestination(mnInfo.keyIDCollateralAddress);
CScript payee; CScript payee;
for(int64_t h = nCachedBlockHeight; h <= nCachedBlockHeight + 8; h++){ for(int64_t h = nCachedBlockHeight; h <= nCachedBlockHeight + 8; h++){
@ -759,7 +759,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman)
int nRank; int nRank;
if (!mnodeman.GetMasternodeRank(activeMasternode.outpoint, nRank, nBlockHeight - 101, GetMinMasternodePaymentsProto())) { if (!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, nBlockHeight - 101, GetMinMasternodePaymentsProto())) {
LogPrint("mnpayments", "CMasternodePayments::ProcessBlock -- Unknown Masternode\n"); LogPrint("mnpayments", "CMasternodePayments::ProcessBlock -- Unknown Masternode\n");
return false; return false;
} }
@ -772,7 +772,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman)
// LOCATE THE NEXT MASTERNODE WHICH SHOULD BE PAID // LOCATE THE NEXT MASTERNODE WHICH SHOULD BE PAID
LogPrintf("CMasternodePayments::ProcessBlock -- Start: nBlockHeight=%d, masternode=%s\n", nBlockHeight, activeMasternode.outpoint.ToStringShort()); LogPrintf("CMasternodePayments::ProcessBlock -- Start: nBlockHeight=%d, masternode=%s\n", nBlockHeight, activeMasternodeInfo.outpoint.ToStringShort());
// pay to the oldest MN that still had no payment but its input is old enough and it was active long enough // pay to the oldest MN that still had no payment but its input is old enough and it was active long enough
int nCount = 0; int nCount = 0;
@ -786,9 +786,9 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman)
LogPrintf("CMasternodePayments::ProcessBlock -- Masternode found by GetNextMasternodeInQueueForPayment(): %s\n", mnInfo.outpoint.ToStringShort()); LogPrintf("CMasternodePayments::ProcessBlock -- Masternode found by GetNextMasternodeInQueueForPayment(): %s\n", mnInfo.outpoint.ToStringShort());
CScript payee = GetScriptForDestination(mnInfo.pubKeyCollateralAddress.GetID()); CScript payee = GetScriptForDestination(mnInfo.keyIDCollateralAddress);
CMasternodePaymentVote voteNew(activeMasternode.outpoint, nBlockHeight, payee); CMasternodePaymentVote voteNew(activeMasternodeInfo.outpoint, nBlockHeight, payee);
CTxDestination address1; CTxDestination address1;
ExtractDestination(payee, address1); ExtractDestination(payee, address1);
@ -893,7 +893,7 @@ void CMasternodePaymentVote::Relay(CConnman& connman) const
connman.RelayInv(inv); connman.RelayInv(inv);
} }
bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int nValidationHeight, int &nDos) const bool CMasternodePaymentVote::CheckSignature(const CKeyID& keyIDMasternode, int nValidationHeight, int &nDos) const
{ {
// do not ban by default // do not ban by default
nDos = 0; nDos = 0;
@ -902,12 +902,12 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
// could be a signature in old format // could be a signature in old format
std::string strMessage = masternodeOutpoint.ToStringShort() + std::string strMessage = masternodeOutpoint.ToStringShort() +
std::to_string(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
// nope, not in old format either // nope, not in old format either
// Only ban for future block vote when we are already synced. // Only ban for future block vote when we are already synced.
// Otherwise it could be the case when MN which signed this vote is using another key now // Otherwise it could be the case when MN which signed this vote is using another key now
@ -924,7 +924,7 @@ bool CMasternodePaymentVote::CheckSignature(const CPubKey& pubKeyMasternode, int
std::to_string(nBlockHeight) + std::to_string(nBlockHeight) +
ScriptToAsmStr(payee); ScriptToAsmStr(payee);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
// Only ban for future block vote when we are already synced. // Only ban for future block vote when we are already synced.
// Otherwise it could be the case when MN which signed this vote is using another key now // Otherwise it could be the case when MN which signed this vote is using another key now
// and we have no idea about the old one. // and we have no idea about the old one.

View File

@ -159,7 +159,7 @@ public:
uint256 GetSignatureHash() const; uint256 GetSignatureHash() const;
bool Sign(); bool Sign();
bool CheckSignature(const CPubKey& pubKeyMasternode, int nValidationHeight, int &nDos) const; bool CheckSignature(const CKeyID& keyIDMasternode, int nValidationHeight, int &nDos) const;
bool IsValid(CNode* pnode, int nValidationHeight, std::string& strError, CConnman& connman) const; bool IsValid(CNode* pnode, int nValidationHeight, std::string& strError, CConnman& connman) const;
void Relay(CConnman& connman) const; void Relay(CConnman& connman) const;

View File

@ -87,7 +87,7 @@ void CMasternodeSync::SwitchToNextAsset(CConnman& connman)
nRequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; nRequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
uiInterface.NotifyAdditionalDataSyncProgressChanged(1); uiInterface.NotifyAdditionalDataSyncProgressChanged(1);
//try to activate our masternode if possible //try to activate our masternode if possible
activeMasternode.ManageState(connman); legacyActiveMasternodeManager.ManageState(connman);
connman.ForEachNode(CConnman::AllNodes, [](CNode* pnode) { connman.ForEachNode(CConnman::AllNodes, [](CNode* pnode) {
netfulfilledman.AddFulfilledRequest(pnode->addr, "full-sync"); netfulfilledman.AddFulfilledRequest(pnode->addr, "full-sync");

View File

@ -26,9 +26,9 @@ CMasternode::CMasternode() :
fAllowMixingTx(true) fAllowMixingTx(true)
{} {}
CMasternode::CMasternode(CService addr, COutPoint outpoint, CPubKey pubKeyCollateralAddress, CPubKey pubKeyMasternode, int nProtocolVersionIn) : CMasternode::CMasternode(CService addr, COutPoint outpoint, CPubKey pubKeyCollateralAddressNew, CPubKey pubKeyMasternodeNew, int nProtocolVersionIn) :
masternode_info_t{ MASTERNODE_ENABLED, nProtocolVersionIn, GetAdjustedTime(), masternode_info_t{ MASTERNODE_ENABLED, nProtocolVersionIn, GetAdjustedTime(),
outpoint, addr, pubKeyCollateralAddress, pubKeyMasternode}, outpoint, addr, pubKeyCollateralAddressNew, pubKeyMasternodeNew},
fAllowMixingTx(true) fAllowMixingTx(true)
{} {}
@ -60,6 +60,7 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& co
if(mnb.sigTime <= sigTime && !mnb.fRecovery) return false; if(mnb.sigTime <= sigTime && !mnb.fRecovery) return false;
pubKeyMasternode = mnb.pubKeyMasternode; pubKeyMasternode = mnb.pubKeyMasternode;
keyIDMasternode = mnb.pubKeyMasternode.GetID();
sigTime = mnb.sigTime; sigTime = mnb.sigTime;
vchSig = mnb.vchSig; vchSig = mnb.vchSig;
nProtocolVersion = mnb.nProtocolVersion; nProtocolVersion = mnb.nProtocolVersion;
@ -73,11 +74,11 @@ bool CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& co
mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing)); mnodeman.mapSeenMasternodePing.insert(std::make_pair(lastPing.GetHash(), lastPing));
} }
// if it matches our Masternode privkey... // if it matches our Masternode privkey...
if(fMasternodeMode && pubKeyMasternode == activeMasternode.pubKeyMasternode) { if(fMasternodeMode && keyIDMasternode == activeMasternodeInfo.keyIDMasternode) {
nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE;
if(nProtocolVersion == PROTOCOL_VERSION) { if(nProtocolVersion == PROTOCOL_VERSION) {
// ... and PROTOCOL_VERSION, then we've been remotely activated ... // ... and PROTOCOL_VERSION, then we've been remotely activated ...
activeMasternode.ManageState(connman); legacyActiveMasternodeManager.ManageState(connman);
} else { } else {
// ... otherwise we need to reactivate our node, do not add it to the list and do not relay // ... otherwise we need to reactivate our node, do not add it to the list and do not relay
// but also do not ban the node we get this message from // but also do not ban the node we get this message from
@ -101,13 +102,13 @@ arith_uint256 CMasternode::CalculateScore(const uint256& blockHash) const
return UintToArith256(ss.GetHash()); return UintToArith256(ss.GetHash());
} }
CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, const CPubKey& pubkey) CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, const CKeyID& keyID)
{ {
int nHeight; int nHeight;
return CheckCollateral(outpoint, pubkey, nHeight); return CheckCollateral(outpoint, keyID, nHeight);
} }
CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, const CPubKey& pubkey, int& nHeightRet) CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outpoint, const CKeyID& keyID, int& nHeightRet)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
@ -120,7 +121,7 @@ CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outp
return COLLATERAL_INVALID_AMOUNT; return COLLATERAL_INVALID_AMOUNT;
} }
if(pubkey == CPubKey() || coin.out.scriptPubKey != GetScriptForDestination(pubkey.GetID())) { if(keyID.IsNull() || coin.out.scriptPubKey != GetScriptForDestination(keyID)) {
return COLLATERAL_INVALID_PUBKEY; return COLLATERAL_INVALID_PUBKEY;
} }
@ -171,7 +172,7 @@ void CMasternode::Check(bool fForce)
} }
int nActiveStatePrev = nActiveState; int nActiveStatePrev = nActiveState;
bool fOurMasternode = fMasternodeMode && activeMasternode.pubKeyMasternode == pubKeyMasternode; bool fOurMasternode = fMasternodeMode && activeMasternodeInfo.keyIDMasternode == keyIDMasternode;
// masternode doesn't meet payment protocol requirements ... // masternode doesn't meet payment protocol requirements ...
bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() || bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() ||
@ -319,7 +320,7 @@ void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScan
const CBlockIndex *BlockReading = pindex; const CBlockIndex *BlockReading = pindex;
CScript mnpayee = GetScriptForDestination(pubKeyCollateralAddress.GetID()); CScript mnpayee = GetScriptForDestination(keyIDCollateralAddress);
// LogPrint("mnpayments", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s\n", outpoint.ToStringShort()); // LogPrint("mnpayments", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s\n", outpoint.ToStringShort());
LOCK(cs_mapMasternodeBlocks); LOCK(cs_mapMasternodeBlocks);
@ -396,7 +397,7 @@ bool CMasternodeBroadcast::Create(const COutPoint& outpoint, const CService& ser
// wait for reindex and/or import to finish // wait for reindex and/or import to finish
if (fImporting || fReindex) return false; if (fImporting || fReindex) return false;
LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, keyIDMasternode = %s\n",
CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(),
pubKeyMasternodeNew.GetID().ToString()); pubKeyMasternodeNew.GetID().ToString());
@ -409,7 +410,7 @@ bool CMasternodeBroadcast::Create(const COutPoint& outpoint, const CService& ser
}; };
CMasternodePing mnp(outpoint); CMasternodePing mnp(outpoint);
if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew.GetID()))
return Log(strprintf("Failed to sign ping, masternode=%s", outpoint.ToStringShort())); return Log(strprintf("Failed to sign ping, masternode=%s", outpoint.ToStringShort()));
mnbRet = CMasternodeBroadcast(service, outpoint, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); mnbRet = CMasternodeBroadcast(service, outpoint, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION);
@ -457,19 +458,19 @@ bool CMasternodeBroadcast::SimpleCheck(int& nDos)
} }
CScript pubkeyScript; CScript pubkeyScript;
pubkeyScript = GetScriptForDestination(pubKeyCollateralAddress.GetID()); pubkeyScript = GetScriptForDestination(keyIDCollateralAddress);
if(pubkeyScript.size() != 25) { if(pubkeyScript.size() != 25) {
LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyCollateralAddress has the wrong size\n"); LogPrintf("CMasternodeBroadcast::SimpleCheck -- keyIDCollateralAddress has the wrong size\n");
nDos = 100; nDos = 100;
return false; return false;
} }
CScript pubkeyScript2; CScript pubkeyScript2;
pubkeyScript2 = GetScriptForDestination(pubKeyMasternode.GetID()); pubkeyScript2 = GetScriptForDestination(keyIDMasternode);
if(pubkeyScript2.size() != 25) { if(pubkeyScript2.size() != 25) {
LogPrintf("CMasternodeBroadcast::SimpleCheck -- pubKeyMasternode has the wrong size\n"); LogPrintf("CMasternodeBroadcast::SimpleCheck -- keyIDMasternode has the wrong size\n");
nDos = 100; nDos = 100;
return false; return false;
} }
@ -511,8 +512,8 @@ bool CMasternodeBroadcast::Update(CMasternode* pmn, int& nDos, CConnman& connman
} }
// IsVnAssociatedWithPubkey is validated once in CheckOutpoint, after that they just need to match // IsVnAssociatedWithPubkey is validated once in CheckOutpoint, after that they just need to match
if(pmn->pubKeyCollateralAddress != pubKeyCollateralAddress) { if(pmn->keyIDCollateralAddress != keyIDCollateralAddress) {
LogPrintf("CMasternodeBroadcast::Update -- Got mismatched pubKeyCollateralAddress and outpoint\n"); LogPrintf("CMasternodeBroadcast::Update -- Got mismatched keyIDCollateralAddress and outpoint\n");
nDos = 33; nDos = 33;
return false; return false;
} }
@ -523,7 +524,7 @@ bool CMasternodeBroadcast::Update(CMasternode* pmn, int& nDos, CConnman& connman
} }
// if ther was no masternode broadcast recently or if it matches our Masternode privkey... // if ther was no masternode broadcast recently or if it matches our Masternode privkey...
if(!pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS) || (fMasternodeMode && pubKeyMasternode == activeMasternode.pubKeyMasternode)) { if(!pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS) || (fMasternodeMode && keyIDMasternode == activeMasternodeInfo.keyIDMasternode)) {
// take the newest entry // take the newest entry
LogPrintf("CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n", addr.ToString()); LogPrintf("CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n", addr.ToString());
if(pmn->UpdateFromNewBroadcast(*this, connman)) { if(pmn->UpdateFromNewBroadcast(*this, connman)) {
@ -540,14 +541,14 @@ bool CMasternodeBroadcast::CheckOutpoint(int& nDos)
{ {
// we are a masternode with the same outpoint (i.e. already activated) and this mnb is ours (matches our Masternode privkey) // we are a masternode with the same outpoint (i.e. already activated) and this mnb is ours (matches our Masternode privkey)
// so nothing to do here for us // so nothing to do here for us
if(fMasternodeMode && outpoint == activeMasternode.outpoint && pubKeyMasternode == activeMasternode.pubKeyMasternode) { if(fMasternodeMode && outpoint == activeMasternodeInfo.outpoint && keyIDMasternode == activeMasternodeInfo.keyIDMasternode) {
return false; return false;
} }
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
int nHeight; int nHeight;
CollateralStatus err = CheckCollateral(outpoint, pubKeyCollateralAddress, nHeight); CollateralStatus err = CheckCollateral(outpoint, keyIDCollateralAddress, nHeight);
if (err == COLLATERAL_UTXO_NOT_FOUND) { if (err == COLLATERAL_UTXO_NOT_FOUND) {
LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to find Masternode UTXO, masternode=%s\n", outpoint.ToStringShort()); LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Failed to find Masternode UTXO, masternode=%s\n", outpoint.ToStringShort());
return false; return false;
@ -560,7 +561,7 @@ bool CMasternodeBroadcast::CheckOutpoint(int& nDos)
} }
if(err == COLLATERAL_INVALID_PUBKEY) { if(err == COLLATERAL_INVALID_PUBKEY) {
LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should match pubKeyCollateralAddress, masternode=%s\n", outpoint.ToStringShort()); LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should match keyIDCollateralAddress, masternode=%s\n", outpoint.ToStringShort());
nDos = 33; nDos = 33;
return false; return false;
} }
@ -635,13 +636,13 @@ bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress)
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, pubKeyCollateralAddress, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDCollateralAddress, vchSig, strError)) {
LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
} else { } else {
std::string strMessage = addr.ToString(false) + std::to_string(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + keyIDCollateralAddress.ToString() + keyIDMasternode.ToString() +
std::to_string(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) { if (!CMessageSigner::SignMessage(strMessage, vchSig, keyCollateralAddress)) {
@ -649,7 +650,7 @@ bool CMasternodeBroadcast::Sign(const CKey& keyCollateralAddress)
return false; return false;
} }
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDCollateralAddress, vchSig, strMessage, strError)) {
LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CMasternodeBroadcast::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -666,13 +667,13 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyCollateralAddress, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDCollateralAddress, vchSig, strError)) {
// maybe it's in old format // maybe it's in old format
std::string strMessage = addr.ToString(false) + std::to_string(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + keyIDCollateralAddress.ToString() + keyIDMasternode.ToString() +
std::to_string(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ if (!CMessageSigner::VerifyMessage(keyIDCollateralAddress, vchSig, strMessage, strError)){
// nope, not in old format either // nope, not in old format either
LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError); LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError);
nDos = 100; nDos = 100;
@ -681,10 +682,10 @@ bool CMasternodeBroadcast::CheckSignature(int& nDos) const
} }
} else { } else {
std::string strMessage = addr.ToString(false) + std::to_string(sigTime) + std::string strMessage = addr.ToString(false) + std::to_string(sigTime) +
pubKeyCollateralAddress.GetID().ToString() + pubKeyMasternode.GetID().ToString() + keyIDCollateralAddress.ToString() + keyIDMasternode.ToString() +
std::to_string(nProtocolVersion); std::to_string(nProtocolVersion);
if (!CMessageSigner::VerifyMessage(pubKeyCollateralAddress, vchSig, strMessage, strError)){ if(!CMessageSigner::VerifyMessage(keyIDCollateralAddress, vchSig, strMessage, strError)){
LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError); LogPrintf("CMasternodeBroadcast::CheckSignature -- Got bad Masternode announce signature, error: %s\n", strError);
nDos = 100; nDos = 100;
return false; return false;
@ -742,7 +743,7 @@ CMasternodePing::CMasternodePing(const COutPoint& outpoint)
nDaemonVersion = CLIENT_VERSION; nDaemonVersion = CLIENT_VERSION;
} }
bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode) bool CMasternodePing::Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode)
{ {
std::string strError; std::string strError;
@ -756,7 +757,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
LogPrintf("CMasternodePing::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CMasternodePing::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
@ -769,7 +770,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return false; return false;
} }
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CMasternodePing::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -778,7 +779,7 @@ bool CMasternodePing::Sign(const CKey& keyMasternode, const CPubKey& pubKeyMaste
return true; return true;
} }
bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos) const bool CMasternodePing::CheckSignature(CKeyID& keyIDMasternode, int &nDos) const
{ {
std::string strError = ""; std::string strError = "";
nDos = 0; nDos = 0;
@ -786,11 +787,11 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
std::to_string(sigTime); std::to_string(sigTime);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError); LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);
nDos = 33; nDos = 33;
return false; return false;
@ -800,7 +801,7 @@ bool CMasternodePing::CheckSignature(const CPubKey& pubKeyMasternode, int &nDos)
std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() + std::string strMessage = CTxIn(masternodeOutpoint).ToString() + blockHash.ToString() +
std::to_string(sigTime); std::to_string(sigTime);
if (!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if (!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError); LogPrintf("CMasternodePing::CheckSignature -- Got bad Masternode ping signature, masternode=%s, error: %s\n", masternodeOutpoint.ToStringShort(), strError);
nDos = 33; nDos = 33;
return false; return false;
@ -884,7 +885,7 @@ bool CMasternodePing::CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, i
return false; return false;
} }
if (!CheckSignature(pmn->pubKeyMasternode, nDos)) return false; if (!CheckSignature(pmn->keyIDMasternode, nDos)) return false;
// so, ping seems to be ok // so, ping seems to be ok

View File

@ -95,8 +95,8 @@ public:
bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; } bool IsExpired() const { return GetAdjustedTime() - sigTime > MASTERNODE_NEW_START_REQUIRED_SECONDS; }
bool Sign(const CKey& keyMasternode, const CPubKey& pubKeyMasternode); bool Sign(const CKey& keyMasternode, const CKeyID& keyIDMasternode);
bool CheckSignature(const CPubKey& pubKeyMasternode, int &nDos) const; bool CheckSignature(CKeyID& keyIDMasternode, int &nDos) const;
bool SimpleCheck(int& nDos); bool SimpleCheck(int& nDos);
bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman); bool CheckAndUpdate(CMasternode* pmn, bool fFromNewBroadcast, int& nDos, CConnman& connman);
void Relay(CConnman& connman); void Relay(CConnman& connman);
@ -130,12 +130,21 @@ struct masternode_info_t
masternode_info_t(int activeState, int protoVer, int64_t sTime) : masternode_info_t(int activeState, int protoVer, int64_t sTime) :
nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime} {} nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime} {}
// only called when the network is in legacy MN list mode
masternode_info_t(int activeState, int protoVer, int64_t sTime, masternode_info_t(int activeState, int protoVer, int64_t sTime,
COutPoint const& outpnt, CService const& addr, COutPoint const& outpnt, CService const& addr,
CPubKey const& pkCollAddr, CPubKey const& pkMN) : CPubKey const& pkCollAddr, CPubKey const& pkMN) :
nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime}, nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime},
outpoint{outpnt}, addr{addr}, outpoint{outpnt}, addr{addr},
pubKeyCollateralAddress{pkCollAddr}, pubKeyMasternode{pkMN} {} pubKeyCollateralAddress{pkCollAddr}, pubKeyMasternode{pkMN}, keyIDCollateralAddress{pkCollAddr.GetID()}, keyIDMasternode{pkMN.GetID()} {}
// only called when the network is in deterministic MN list mode
masternode_info_t(int activeState, int protoVer, int64_t sTime,
COutPoint const& outpnt, CService const& addr,
CKeyID const& pkCollAddr, CKeyID const& pkMN) :
nActiveState{activeState}, nProtocolVersion{protoVer}, sigTime{sTime},
outpoint{outpnt}, addr{addr},
pubKeyCollateralAddress{}, pubKeyMasternode{}, keyIDCollateralAddress{pkCollAddr}, keyIDMasternode{pkMN} {}
int nActiveState = 0; int nActiveState = 0;
int nProtocolVersion = 0; int nProtocolVersion = 0;
@ -143,8 +152,10 @@ struct masternode_info_t
COutPoint outpoint{}; COutPoint outpoint{};
CService addr{}; CService addr{};
CPubKey pubKeyCollateralAddress{}; CPubKey pubKeyCollateralAddress{}; // this will be invalid/unset when the network switches to deterministic MNs (luckely it's only important for the broadcast hash)
CPubKey pubKeyMasternode{}; CPubKey pubKeyMasternode{}; // this will be invalid/unset when the network switches to deterministic MNs (luckely it's only important for the broadcast hash)
CKeyID keyIDCollateralAddress{};
CKeyID keyIDMasternode{};
int64_t nLastDsq = 0; //the dsq count from the last dsq broadcast of this node int64_t nLastDsq = 0; //the dsq count from the last dsq broadcast of this node
int64_t nTimeLastChecked = 0; int64_t nTimeLastChecked = 0;
@ -224,6 +235,8 @@ public:
READWRITE(addr); READWRITE(addr);
READWRITE(pubKeyCollateralAddress); READWRITE(pubKeyCollateralAddress);
READWRITE(pubKeyMasternode); READWRITE(pubKeyMasternode);
READWRITE(keyIDCollateralAddress);
READWRITE(keyIDMasternode);
READWRITE(lastPing); READWRITE(lastPing);
READWRITE(vchSig); READWRITE(vchSig);
READWRITE(sigTime); READWRITE(sigTime);
@ -246,8 +259,8 @@ public:
bool UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman); bool UpdateFromNewBroadcast(CMasternodeBroadcast& mnb, CConnman& connman);
static CollateralStatus CheckCollateral(const COutPoint& outpoint, const CPubKey& pubkey); static CollateralStatus CheckCollateral(const COutPoint& outpoint, const CKeyID& keyID);
static CollateralStatus CheckCollateral(const COutPoint& outpoint, const CPubKey& pubkey, int& nHeightRet); static CollateralStatus CheckCollateral(const COutPoint& outpoint, const CKeyID& keyID, int& nHeightRet);
void Check(bool fForce = false); void Check(bool fForce = false);
bool IsBroadcastedWithin(int nSeconds) { return GetAdjustedTime() - sigTime < nSeconds; } bool IsBroadcastedWithin(int nSeconds) { return GetAdjustedTime() - sigTime < nSeconds; }
@ -389,6 +402,11 @@ public:
if (!(s.GetType() & SER_GETHASH)) { if (!(s.GetType() & SER_GETHASH)) {
READWRITE(lastPing); READWRITE(lastPing);
} }
if (ser_action.ForRead()) {
keyIDCollateralAddress = pubKeyCollateralAddress.GetID();
keyIDMasternode = pubKeyMasternode.GetID();
}
} }
uint256 GetHash() const; uint256 GetHash() const;

View File

@ -25,7 +25,7 @@
/** Masternode manager */ /** Masternode manager */
CMasternodeMan mnodeman; CMasternodeMan mnodeman;
const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-8"; const std::string CMasternodeMan::SERIALIZATION_VERSION_STRING = "CMasternodeMan-Version-9";
const int CMasternodeMan::LAST_PAID_SCAN_BLOCKS = 100; const int CMasternodeMan::LAST_PAID_SCAN_BLOCKS = 100;
struct CompareLastPaidBlock struct CompareLastPaidBlock
@ -471,11 +471,10 @@ bool CMasternodeMan::GetMasternodeInfo(const COutPoint& outpoint, masternode_inf
return true; return true;
} }
bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet) bool CMasternodeMan::GetMasternodeInfo(const CKeyID& keyIDMasternode, masternode_info_t& mnInfoRet) {
{
LOCK(cs); LOCK(cs);
for (const auto& mnpair : mapMasternodes) { for (const auto& mnpair : mapMasternodes) {
if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { if (mnpair.second.keyIDMasternode == keyIDMasternode) {
mnInfoRet = mnpair.second.GetInfo(); mnInfoRet = mnpair.second.GetInfo();
return true; return true;
} }
@ -483,17 +482,18 @@ bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masterno
return false; return false;
} }
bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet)
{
return GetMasternodeInfo(pubKeyMasternode.GetID(), mnInfoRet);
}
bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet) bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet)
{ {
LOCK(cs); CTxDestination dest;
for (const auto& mnpair : mapMasternodes) { if (!ExtractDestination(payee, dest) || !boost::get<CKeyID>(&dest))
CScript scriptCollateralAddress = GetScriptForDestination(mnpair.second.pubKeyCollateralAddress.GetID()); return false;
if (scriptCollateralAddress == payee) { CKeyID keyId = *boost::get<CKeyID>(&dest);
mnInfoRet = mnpair.second.GetInfo(); return GetMasternodeInfo(keyId, mnInfoRet);
return true;
}
}
return false;
} }
bool CMasternodeMan::Has(const COutPoint& outpoint) bool CMasternodeMan::Has(const COutPoint& outpoint)
@ -994,7 +994,7 @@ void CMasternodeMan::PushDsegInvs(CNode* pnode, const CMasternode& mn)
void CMasternodeMan::DoFullVerificationStep(CConnman& connman) void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
{ {
if(activeMasternode.outpoint.IsNull()) return; if(activeMasternodeInfo.outpoint.IsNull()) return;
if(!masternodeSync.IsSynced()) return; if(!masternodeSync.IsSynced()) return;
rank_pair_vec_t vecMasternodeRanks; rank_pair_vec_t vecMasternodeRanks;
@ -1014,7 +1014,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
(int)MAX_POSE_RANK); (int)MAX_POSE_RANK);
return; return;
} }
if(rankPair.second.outpoint == activeMasternode.outpoint) { if(rankPair.second.outpoint == activeMasternodeInfo.outpoint) {
nMyRank = rankPair.first; nMyRank = rankPair.first;
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n", LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n",
nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS); nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS);
@ -1199,24 +1199,24 @@ void CMasternodeMan::SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv,
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = mnv.GetSignatureHash1(blockHash); uint256 hash = mnv.GetSignatureHash1(blockHash);
if(!CHashSigner::SignHash(hash, activeMasternode.keyMasternode, mnv.vchSig1)) { if(!CHashSigner::SignHash(hash, activeMasternodeInfo.keyMasternode, mnv.vchSig1)) {
LogPrintf("CMasternodeMan::SendVerifyReply -- SignHash() failed\n"); LogPrintf("CMasternodeMan::SendVerifyReply -- SignHash() failed\n");
return; return;
} }
if (!CHashSigner::VerifyHash(hash, activeMasternode.pubKeyMasternode, mnv.vchSig1, strError)) { if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.keyIDMasternode, mnv.vchSig1, strError)) {
LogPrintf("CMasternodeMan::SendVerifyReply -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CMasternodeMan::SendVerifyReply -- VerifyHash() failed, error: %s\n", strError);
return; return;
} }
} else { } else {
std::string strMessage = strprintf("%s%d%s", activeMasternode.service.ToString(false), mnv.nonce, blockHash.ToString()); std::string strMessage = strprintf("%s%d%s", activeMasternodeInfo.service.ToString(false), mnv.nonce, blockHash.ToString());
if(!CMessageSigner::SignMessage(strMessage, mnv.vchSig1, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, mnv.vchSig1, activeMasternodeInfo.keyMasternode)) {
LogPrintf("MasternodeMan::SendVerifyReply -- SignMessage() failed\n"); LogPrintf("MasternodeMan::SendVerifyReply -- SignMessage() failed\n");
return; return;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig1, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, mnv.vchSig1, strMessage, strError)) {
LogPrintf("MasternodeMan::SendVerifyReply -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("MasternodeMan::SendVerifyReply -- VerifyMessage() failed, error: %s\n", strError);
return; return;
} }
@ -1283,10 +1283,10 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m
if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) { if(CAddress(mnpair.second.addr, NODE_NETWORK) == pnode->addr) {
bool fFound = false; bool fFound = false;
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
fFound = CHashSigner::VerifyHash(hash1, mnpair.second.pubKeyMasternode, mnv.vchSig1, strError); fFound = CHashSigner::VerifyHash(hash1, mnpair.second.keyIDMasternode, mnv.vchSig1, strError);
// we don't care about mnv with signature in old format // we don't care about mnv with signature in old format
} else { } else {
fFound = CMessageSigner::VerifyMessage(mnpair.second.pubKeyMasternode, mnv.vchSig1, strMessage1, strError); fFound = CMessageSigner::VerifyMessage(mnpair.second.keyIDMasternode, mnv.vchSig1, strMessage1, strError);
} }
if (fFound) { if (fFound) {
// found it! // found it!
@ -1297,23 +1297,23 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m
netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done"); netfulfilledman.AddFulfilledRequest(pnode->addr, strprintf("%s", NetMsgType::MNVERIFY)+"-done");
// we can only broadcast it if we are an activated masternode // we can only broadcast it if we are an activated masternode
if(activeMasternode.outpoint.IsNull()) continue; if(activeMasternodeInfo.outpoint.IsNull()) continue;
// update ... // update ...
mnv.addr = mnpair.second.addr; mnv.addr = mnpair.second.addr;
mnv.masternodeOutpoint1 = mnpair.second.outpoint; mnv.masternodeOutpoint1 = mnpair.second.outpoint;
mnv.masternodeOutpoint2 = activeMasternode.outpoint; mnv.masternodeOutpoint2 = activeMasternodeInfo.outpoint;
// ... and sign it // ... and sign it
std::string strError; std::string strError;
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash2 = mnv.GetSignatureHash2(blockHash); uint256 hash2 = mnv.GetSignatureHash2(blockHash);
if(!CHashSigner::SignHash(hash2, activeMasternode.keyMasternode, mnv.vchSig2)) { if(!CHashSigner::SignHash(hash2, activeMasternodeInfo.keyMasternode, mnv.vchSig2)) {
LogPrintf("MasternodeMan::ProcessVerifyReply -- SignHash() failed\n"); LogPrintf("MasternodeMan::ProcessVerifyReply -- SignHash() failed\n");
return; return;
} }
if(!CHashSigner::VerifyHash(hash2, activeMasternode.pubKeyMasternode, mnv.vchSig2, strError)) { if(!CHashSigner::VerifyHash(hash2, activeMasternodeInfo.keyIDMasternode, mnv.vchSig2, strError)) {
LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyHash() failed, error: %s\n", strError); LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyHash() failed, error: %s\n", strError);
return; return;
} }
@ -1321,12 +1321,12 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m
std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(),
mnv.masternodeOutpoint1.ToStringShort(), mnv.masternodeOutpoint2.ToStringShort()); mnv.masternodeOutpoint1.ToStringShort(), mnv.masternodeOutpoint2.ToStringShort());
if(!CMessageSigner::SignMessage(strMessage2, mnv.vchSig2, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage2, mnv.vchSig2, activeMasternodeInfo.keyMasternode)) {
LogPrintf("MasternodeMan::ProcessVerifyReply -- SignMessage() failed\n"); LogPrintf("MasternodeMan::ProcessVerifyReply -- SignMessage() failed\n");
return; return;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, mnv.vchSig2, strMessage2, strError)) {
LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("MasternodeMan::ProcessVerifyReply -- VerifyMessage() failed, error: %s\n", strError);
return; return;
} }
@ -1436,12 +1436,12 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif
uint256 hash1 = mnv.GetSignatureHash1(blockHash); uint256 hash1 = mnv.GetSignatureHash1(blockHash);
uint256 hash2 = mnv.GetSignatureHash2(blockHash); uint256 hash2 = mnv.GetSignatureHash2(blockHash);
if(!CHashSigner::VerifyHash(hash1, pmn1->pubKeyMasternode, mnv.vchSig1, strError)) { if(!CHashSigner::VerifyHash(hash1, pmn1->keyIDMasternode, mnv.vchSig1, strError)) {
LogPrintf("MasternodeMan::ProcessVerifyBroadcast -- VerifyHash() failed, error: %s\n", strError); LogPrintf("MasternodeMan::ProcessVerifyBroadcast -- VerifyHash() failed, error: %s\n", strError);
return; return;
} }
if(!CHashSigner::VerifyHash(hash2, pmn2->pubKeyMasternode, mnv.vchSig2, strError)) { if(!CHashSigner::VerifyHash(hash2, pmn2->keyIDMasternode, mnv.vchSig2, strError)) {
LogPrintf("MasternodeMan::ProcessVerifyBroadcast -- VerifyHash() failed, error: %s\n", strError); LogPrintf("MasternodeMan::ProcessVerifyBroadcast -- VerifyHash() failed, error: %s\n", strError);
return; return;
} }
@ -1450,12 +1450,12 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif
std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(), std::string strMessage2 = strprintf("%s%d%s%s%s", mnv.addr.ToString(false), mnv.nonce, blockHash.ToString(),
mnv.masternodeOutpoint1.ToStringShort(), mnv.masternodeOutpoint2.ToStringShort()); mnv.masternodeOutpoint1.ToStringShort(), mnv.masternodeOutpoint2.ToStringShort());
if(!CMessageSigner::VerifyMessage(pmn1->pubKeyMasternode, mnv.vchSig1, strMessage1, strError)) { if(!CMessageSigner::VerifyMessage(pmn1->keyIDMasternode, mnv.vchSig1, strMessage1, strError)) {
LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode1 failed, error: %s\n", strError); LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode1 failed, error: %s\n", strError);
return; return;
} }
if(!CMessageSigner::VerifyMessage(pmn2->pubKeyMasternode, mnv.vchSig2, strMessage2, strError)) { if(!CMessageSigner::VerifyMessage(pmn2->keyIDMasternode, mnv.vchSig2, strMessage2, strError)) {
LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode2 failed, error: %s\n", strError); LogPrintf("CMasternodeMan::ProcessVerifyBroadcast -- VerifyMessage() for masternode2 failed, error: %s\n", strError);
return; return;
} }
@ -1567,13 +1567,13 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr
Add(mnb); Add(mnb);
masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - new"); masternodeSync.BumpAssetLastTime("CMasternodeMan::CheckMnbAndUpdateMasternodeList - new");
// if it matches our Masternode privkey... // if it matches our Masternode privkey...
if(fMasternodeMode && mnb.pubKeyMasternode == activeMasternode.pubKeyMasternode) { if(fMasternodeMode && mnb.keyIDMasternode == activeMasternodeInfo.keyIDMasternode) {
mnb.nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE; mnb.nPoSeBanScore = -MASTERNODE_POSE_BAN_MAX_SCORE;
if(mnb.nProtocolVersion == PROTOCOL_VERSION) { if(mnb.nProtocolVersion == PROTOCOL_VERSION) {
// ... and PROTOCOL_VERSION, then we've been remotely activated ... // ... and PROTOCOL_VERSION, then we've been remotely activated ...
LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Got NEW Masternode entry: masternode=%s sigTime=%lld addr=%s\n", LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList -- Got NEW Masternode entry: masternode=%s sigTime=%lld addr=%s\n",
mnb.outpoint.ToStringShort(), mnb.sigTime, mnb.addr.ToString()); mnb.outpoint.ToStringShort(), mnb.sigTime, mnb.addr.ToString());
activeMasternode.ManageState(connman); legacyActiveMasternodeManager.ManageState(connman);
} else { } else {
// ... otherwise we need to reactivate our node, do not add it to the list and do not relay // ... otherwise we need to reactivate our node, do not add it to the list and do not relay
// but also do not ban the node we get this message from // but also do not ban the node we get this message from
@ -1643,11 +1643,11 @@ void CMasternodeMan::RemoveGovernanceObject(uint256 nGovernanceObjectHash)
} }
} }
void CMasternodeMan::CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce) void CMasternodeMan::CheckMasternode(const CKeyID& keyIDMasternode, bool fForce)
{ {
LOCK2(cs_main, cs); LOCK2(cs_main, cs);
for (auto& mnpair : mapMasternodes) { for (auto& mnpair : mapMasternodes) {
if (mnpair.second.pubKeyMasternode == pubKeyMasternode) { if (mnpair.second.keyIDMasternode == keyIDMasternode) {
mnpair.second.Check(fForce); mnpair.second.Check(fForce);
return; return;
} }

View File

@ -169,6 +169,7 @@ public:
bool Has(const COutPoint& outpoint); bool Has(const COutPoint& outpoint);
bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet); bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet);
bool GetMasternodeInfo(const CKeyID& keyIDMasternode, masternode_info_t& mnInfoRet);
bool GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet); bool GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet);
bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet); bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet);
@ -229,7 +230,7 @@ public:
bool AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash); bool AddGovernanceVote(const COutPoint& outpoint, uint256 nGovernanceObjectHash);
void RemoveGovernanceObject(uint256 nGovernanceObjectHash); void RemoveGovernanceObject(uint256 nGovernanceObjectHash);
void CheckMasternode(const CPubKey& pubKeyMasternode, bool fForce); void CheckMasternode(const CKeyID& keyIDMasternode, bool fForce);
bool IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt = -1); bool IsMasternodePingedWithin(const COutPoint& outpoint, int nSeconds, int64_t nTimeToCheckAt = -1);
void SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp); void SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp);

View File

@ -1973,7 +1973,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// we have no idea about (e.g we were offline)? How to handle them? // we have no idea about (e.g we were offline)? How to handle them?
} }
if(!dstx.CheckSignature(mn.pubKeyMasternode)) { if(!dstx.CheckSignature(mn.keyIDMasternode)) {
LogPrint("privatesend", "DSTX -- CheckSignature() failed for %s\n", hashTx.ToString()); LogPrint("privatesend", "DSTX -- CheckSignature() failed for %s\n", hashTx.ToString());
return false; return false;
} }

View File

@ -56,7 +56,7 @@ void CPrivateSendClient::ProcessMessage(CNode* pfrom, const std::string& strComm
masternode_info_t infoMn; masternode_info_t infoMn;
if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, infoMn)) return; if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, infoMn)) return;
if(!dsq.CheckSignature(infoMn.pubKeyMasternode)) { if(!dsq.CheckSignature(infoMn.keyIDMasternode)) {
// we probably have outdated info // we probably have outdated info
mnodeman.AskForMN(pfrom, dsq.masternodeOutpoint, connman); mnodeman.AskForMN(pfrom, dsq.masternodeOutpoint, connman);
return; return;

View File

@ -48,7 +48,7 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
if(dsa.nInputCount < 0 || dsa.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) return; if(dsa.nInputCount < 0 || dsa.nInputCount > PRIVATESEND_ENTRY_MAX_SIZE) return;
masternode_info_t mnInfo; masternode_info_t mnInfo;
if(!mnodeman.GetMasternodeInfo(activeMasternode.outpoint, mnInfo)) { if(!mnodeman.GetMasternodeInfo(activeMasternodeInfo.outpoint, mnInfo)) {
PushStatus(pfrom, STATUS_REJECTED, ERR_MN_LIST, connman); PushStatus(pfrom, STATUS_REJECTED, ERR_MN_LIST, connman);
return; return;
} }
@ -105,7 +105,7 @@ void CPrivateSendServer::ProcessMessage(CNode* pfrom, const std::string& strComm
masternode_info_t mnInfo; masternode_info_t mnInfo;
if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, mnInfo)) return; if(!mnodeman.GetMasternodeInfo(dsq.masternodeOutpoint, mnInfo)) return;
if(!dsq.CheckSignature(mnInfo.pubKeyMasternode)) { if(!dsq.CheckSignature(mnInfo.keyIDMasternode)) {
// we probably have outdated info // we probably have outdated info
mnodeman.AskForMN(pfrom, dsq.masternodeOutpoint, connman); mnodeman.AskForMN(pfrom, dsq.masternodeOutpoint, connman);
return; return;
@ -363,7 +363,7 @@ void CPrivateSendServer::CommitFinalTransaction(CConnman& connman)
// create and sign masternode dstx transaction // create and sign masternode dstx transaction
if(!CPrivateSend::GetDSTX(hashTx)) { if(!CPrivateSend::GetDSTX(hashTx)) {
CDarksendBroadcastTx dstxNew(finalTransaction, activeMasternode.outpoint, GetAdjustedTime()); CDarksendBroadcastTx dstxNew(finalTransaction, activeMasternodeInfo.outpoint, GetAdjustedTime());
dstxNew.Sign(); dstxNew.Sign();
CPrivateSend::AddDSTX(dstxNew); CPrivateSend::AddDSTX(dstxNew);
} }
@ -524,7 +524,7 @@ void CPrivateSendServer::CheckForCompleteQueue(CConnman& connman)
if(nState == POOL_STATE_QUEUE && IsSessionReady()) { if(nState == POOL_STATE_QUEUE && IsSessionReady()) {
SetState(POOL_STATE_ACCEPTING_ENTRIES); SetState(POOL_STATE_ACCEPTING_ENTRIES);
CDarksendQueue dsq(nSessionDenom, nSessionInputCount, activeMasternode.outpoint, GetAdjustedTime(), true); CDarksendQueue dsq(nSessionDenom, nSessionInputCount, activeMasternodeInfo.outpoint, GetAdjustedTime(), true);
LogPrint("privatesend", "CPrivateSendServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s)\n", dsq.ToString()); LogPrint("privatesend", "CPrivateSendServer::CheckForCompleteQueue -- queue is ready, signing and relaying (%s)\n", dsq.ToString());
dsq.Sign(); dsq.Sign();
dsq.Relay(connman); dsq.Relay(connman);
@ -739,7 +739,7 @@ bool CPrivateSendServer::CreateNewSession(const CDarksendAccept& dsa, PoolMessag
if(!fUnitTest) { if(!fUnitTest) {
//broadcast that I'm accepting entries, only if it's the first entry through //broadcast that I'm accepting entries, only if it's the first entry through
CDarksendQueue dsq(dsa.nDenom, dsa.nInputCount, activeMasternode.outpoint, GetAdjustedTime(), false); CDarksendQueue dsq(dsa.nDenom, dsa.nInputCount, activeMasternodeInfo.outpoint, GetAdjustedTime(), false);
LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString()); LogPrint("privatesend", "CPrivateSendServer::CreateNewSession -- signing and relaying new queue: %s\n", dsq.ToString());
dsq.Sign(); dsq.Sign();
dsq.Relay(connman); dsq.Relay(connman);

View File

@ -47,12 +47,12 @@ bool CDarksendQueue::Sign()
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::SignHash(hash, activeMasternode.keyMasternode, vchSig)) { if (!CHashSigner::SignHash(hash, activeMasternodeInfo.keyMasternode, vchSig)) {
LogPrintf("CDarksendQueue::Sign -- SignHash() failed\n"); LogPrintf("CDarksendQueue::Sign -- SignHash() failed\n");
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, activeMasternode.pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.keyIDMasternode, vchSig, strError)) {
LogPrintf("CDarksendQueue::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CDarksendQueue::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
@ -62,12 +62,12 @@ bool CDarksendQueue::Sign()
std::to_string(nTime) + std::to_string(nTime) +
std::to_string(fReady); std::to_string(fReady);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternodeInfo.keyMasternode)) {
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed, %s\n", ToString()); LogPrintf("CDarksendQueue::Sign -- SignMessage() failed, %s\n", ToString());
return false; return false;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendQueue::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CDarksendQueue::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -76,14 +76,14 @@ bool CDarksendQueue::Sign()
return true; return true;
} }
bool CDarksendQueue::CheckSignature(const CPubKey& pubKeyMasternode) const bool CDarksendQueue::CheckSignature(const CKeyID& keyIDMasternode) const
{ {
std::string strError = ""; std::string strError = "";
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
// we don't care about queues with old signature format // we don't care about queues with old signature format
LogPrintf("CDarksendQueue::CheckSignature -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CDarksendQueue::CheckSignature -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
@ -94,7 +94,7 @@ bool CDarksendQueue::CheckSignature(const CPubKey& pubKeyMasternode) const
std::to_string(nTime) + std::to_string(nTime) +
std::to_string(fReady); std::to_string(fReady);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature: %s; error: %s\n", ToString(), strError); LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature: %s; error: %s\n", ToString(), strError);
return false; return false;
} }
@ -127,24 +127,24 @@ bool CDarksendBroadcastTx::Sign()
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::SignHash(hash, activeMasternode.keyMasternode, vchSig)) { if (!CHashSigner::SignHash(hash, activeMasternodeInfo.keyMasternode, vchSig)) {
LogPrintf("CDarksendBroadcastTx::Sign -- SignHash() failed\n"); LogPrintf("CDarksendBroadcastTx::Sign -- SignHash() failed\n");
return false; return false;
} }
if (!CHashSigner::VerifyHash(hash, activeMasternode.pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, activeMasternodeInfo.keyIDMasternode, vchSig, strError)) {
LogPrintf("CDarksendBroadcastTx::Sign -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CDarksendBroadcastTx::Sign -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
} }
} else { } else {
std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime); std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime);
if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternode.keyMasternode)) { if(!CMessageSigner::SignMessage(strMessage, vchSig, activeMasternodeInfo.keyMasternode)) {
LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n"); LogPrintf("CDarksendBroadcastTx::Sign -- SignMessage() failed\n");
return false; return false;
} }
if(!CMessageSigner::VerifyMessage(activeMasternode.pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(activeMasternodeInfo.keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendBroadcastTx::Sign -- VerifyMessage() failed, error: %s\n", strError); LogPrintf("CDarksendBroadcastTx::Sign -- VerifyMessage() failed, error: %s\n", strError);
return false; return false;
} }
@ -153,14 +153,14 @@ bool CDarksendBroadcastTx::Sign()
return true; return true;
} }
bool CDarksendBroadcastTx::CheckSignature(const CPubKey& pubKeyMasternode) const bool CDarksendBroadcastTx::CheckSignature(const CKeyID& keyIDMasternode) const
{ {
std::string strError = ""; std::string strError = "";
if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) { if (sporkManager.IsSporkActive(SPORK_6_NEW_SIGS)) {
uint256 hash = GetSignatureHash(); uint256 hash = GetSignatureHash();
if (!CHashSigner::VerifyHash(hash, pubKeyMasternode, vchSig, strError)) { if (!CHashSigner::VerifyHash(hash, keyIDMasternode, vchSig, strError)) {
// we don't care about dstxes with old signature format // we don't care about dstxes with old signature format
LogPrintf("CDarksendBroadcastTx::CheckSignature -- VerifyHash() failed, error: %s\n", strError); LogPrintf("CDarksendBroadcastTx::CheckSignature -- VerifyHash() failed, error: %s\n", strError);
return false; return false;
@ -168,7 +168,7 @@ bool CDarksendBroadcastTx::CheckSignature(const CPubKey& pubKeyMasternode) const
} else { } else {
std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime); std::string strMessage = tx->GetHash().ToString() + std::to_string(sigTime);
if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { if(!CMessageSigner::VerifyMessage(keyIDMasternode, vchSig, strMessage, strError)) {
LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError); LogPrintf("CDarksendBroadcastTx::CheckSignature -- Got bad dstx signature, error: %s\n", strError);
return false; return false;
} }

View File

@ -249,7 +249,7 @@ public:
*/ */
bool Sign(); bool Sign();
/// Check if we have a valid Masternode address /// Check if we have a valid Masternode address
bool CheckSignature(const CPubKey& pubKeyMasternode) const; bool CheckSignature(const CKeyID& keyIDMasternode) const;
bool Relay(CConnman &connman); bool Relay(CConnman &connman);
@ -341,7 +341,7 @@ public:
uint256 GetSignatureHash() const; uint256 GetSignatureHash() const;
bool Sign(); bool Sign();
bool CheckSignature(const CPubKey& pubKeyMasternode) const; bool CheckSignature(const CKeyID& keyIDMasternode) const;
void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; } void SetConfirmedHeight(int nConfirmedHeightIn) { nConfirmedHeight = nConfirmedHeightIn; }
bool IsExpired(int nHeight); bool IsExpired(int nHeight);

View File

@ -215,7 +215,7 @@ void MasternodeList::updateMyMasternodeInfo(QString strAlias, QString strAddr, c
QTableWidgetItem *activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(fFound ? (infoMn.nTimeLastPing - infoMn.sigTime) : 0))); QTableWidgetItem *activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(fFound ? (infoMn.nTimeLastPing - infoMn.sigTime) : 0)));
QTableWidgetItem *lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", QTableWidgetItem *lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M",
fFound ? infoMn.nTimeLastPing + GetOffsetFromUtc() : 0))); fFound ? infoMn.nTimeLastPing + GetOffsetFromUtc() : 0)));
QTableWidgetItem *pubkeyItem = new QTableWidgetItem(QString::fromStdString(fFound ? CBitcoinAddress(infoMn.pubKeyCollateralAddress.GetID()).ToString() : "")); QTableWidgetItem *pubkeyItem = new QTableWidgetItem(QString::fromStdString(fFound ? CBitcoinAddress(infoMn.keyIDCollateralAddress).ToString() : ""));
ui->tableWidgetMyMasternodes->setItem(nNewRow, 0, aliasItem); ui->tableWidgetMyMasternodes->setItem(nNewRow, 0, aliasItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 1, addrItem); ui->tableWidgetMyMasternodes->setItem(nNewRow, 1, addrItem);
@ -302,7 +302,7 @@ void MasternodeList::updateNodeList()
QTableWidgetItem *statusItem = new QTableWidgetItem(QString::fromStdString(mn.GetStatus())); QTableWidgetItem *statusItem = new QTableWidgetItem(QString::fromStdString(mn.GetStatus()));
QTableWidgetItem *activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(mn.lastPing.sigTime - mn.sigTime))); QTableWidgetItem *activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(mn.lastPing.sigTime - mn.sigTime)));
QTableWidgetItem *lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", mn.lastPing.sigTime + offsetFromUtc))); QTableWidgetItem *lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", mn.lastPing.sigTime + offsetFromUtc)));
QTableWidgetItem *pubkeyItem = new QTableWidgetItem(QString::fromStdString(CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString())); QTableWidgetItem *pubkeyItem = new QTableWidgetItem(QString::fromStdString(CBitcoinAddress(mn.keyIDCollateralAddress).ToString()));
if (strCurrentFilter != "") if (strCurrentFilter != "")
{ {

View File

@ -223,10 +223,10 @@ UniValue gobject(const JSONRPCRequest& request)
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so."); throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so.");
} }
bool fMnFound = mnodeman.Has(activeMasternode.outpoint); bool fMnFound = mnodeman.Has(activeMasternodeInfo.outpoint);
DBG( std::cout << "gobject: submit activeMasternode.pubKeyMasternode = " << activeMasternode.pubKeyMasternode.GetHash().ToString() DBG( std::cout << "gobject: submit activeMasternodeInfo.keyIDMasternode = " << activeMasternodeInfo.keyIDMasternode.ToString()
<< ", outpoint = " << activeMasternode.outpoint.ToStringShort() << ", outpoint = " << activeMasternodeInfo.outpoint.ToStringShort()
<< ", params.size() = " << request.params.size() << ", params.size() = " << request.params.size()
<< ", fMnFound = " << fMnFound << std::endl; ); << ", fMnFound = " << fMnFound << std::endl; );
@ -274,8 +274,8 @@ UniValue gobject(const JSONRPCRequest& request)
// Attempt to sign triggers if we are a MN // Attempt to sign triggers if we are a MN
if(govobj.GetObjectType() == GOVERNANCE_OBJECT_TRIGGER) { if(govobj.GetObjectType() == GOVERNANCE_OBJECT_TRIGGER) {
if(fMnFound) { if(fMnFound) {
govobj.SetMasternodeOutpoint(activeMasternode.outpoint); govobj.SetMasternodeOutpoint(activeMasternodeInfo.outpoint);
govobj.Sign(activeMasternode.keyMasternode, activeMasternode.pubKeyMasternode); govobj.Sign(activeMasternodeInfo.keyMasternode, activeMasternodeInfo.keyIDMasternode);
} }
else { else {
LogPrintf("gobject(submit) -- Object submission rejected because node is not a masternode\n"); LogPrintf("gobject(submit) -- Object submission rejected because node is not a masternode\n");
@ -357,7 +357,7 @@ UniValue gobject(const JSONRPCRequest& request)
UniValue returnObj(UniValue::VOBJ); UniValue returnObj(UniValue::VOBJ);
CMasternode mn; CMasternode mn;
bool fMnFound = mnodeman.Get(activeMasternode.outpoint, mn); bool fMnFound = mnodeman.Get(activeMasternodeInfo.outpoint, mn);
if(!fMnFound) { if(!fMnFound) {
nFailed++; nFailed++;
@ -370,7 +370,7 @@ UniValue gobject(const JSONRPCRequest& request)
} }
CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome); CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome);
if(!vote.Sign(activeMasternode.keyMasternode, activeMasternode.pubKeyMasternode)) { if(!vote.Sign(activeMasternodeInfo.keyMasternode, activeMasternodeInfo.keyIDMasternode)) {
nFailed++; nFailed++;
statusObj.push_back(Pair("result", "failed")); statusObj.push_back(Pair("result", "failed"));
statusObj.push_back(Pair("errorMessage", "Failure to sign.")); statusObj.push_back(Pair("errorMessage", "Failure to sign."));
@ -443,8 +443,6 @@ UniValue gobject(const JSONRPCRequest& request)
std::vector<unsigned char> vchMasterNodeSignature; std::vector<unsigned char> vchMasterNodeSignature;
std::string strMasterNodeSignMessage; std::string strMasterNodeSignMessage;
CPubKey pubKeyCollateralAddress;
CKey keyCollateralAddress;
CPubKey pubKeyMasternode; CPubKey pubKeyMasternode;
CKey keyMasternode; CKey keyMasternode;
@ -480,7 +478,7 @@ UniValue gobject(const JSONRPCRequest& request)
} }
CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome); CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome);
if(!vote.Sign(keyMasternode, pubKeyMasternode)){ if(!vote.Sign(keyMasternode, pubKeyMasternode.GetID())){
nFailed++; nFailed++;
statusObj.push_back(Pair("result", "failed")); statusObj.push_back(Pair("result", "failed"));
statusObj.push_back(Pair("errorMessage", "Failure to sign.")); statusObj.push_back(Pair("errorMessage", "Failure to sign."));

View File

@ -253,7 +253,7 @@ UniValue masternode(const JSONRPCRequest& request)
obj.push_back(Pair("IP:port", mnInfo.addr.ToString())); obj.push_back(Pair("IP:port", mnInfo.addr.ToString()));
obj.push_back(Pair("protocol", mnInfo.nProtocolVersion)); obj.push_back(Pair("protocol", mnInfo.nProtocolVersion));
obj.push_back(Pair("outpoint", mnInfo.outpoint.ToStringShort())); obj.push_back(Pair("outpoint", mnInfo.outpoint.ToStringShort()));
obj.push_back(Pair("payee", CBitcoinAddress(mnInfo.pubKeyCollateralAddress.GetID()).ToString())); obj.push_back(Pair("payee", CBitcoinAddress(mnInfo.keyIDCollateralAddress).ToString()));
obj.push_back(Pair("lastseen", mnInfo.nTimeLastPing)); obj.push_back(Pair("lastseen", mnInfo.nTimeLastPing));
obj.push_back(Pair("activeseconds", mnInfo.nTimeLastPing - mnInfo.sigTime)); obj.push_back(Pair("activeseconds", mnInfo.nTimeLastPing - mnInfo.sigTime));
return obj; return obj;
@ -430,15 +430,15 @@ UniValue masternode(const JSONRPCRequest& request)
UniValue mnObj(UniValue::VOBJ); UniValue mnObj(UniValue::VOBJ);
mnObj.push_back(Pair("outpoint", activeMasternode.outpoint.ToStringShort())); mnObj.push_back(Pair("outpoint", activeMasternodeInfo.outpoint.ToStringShort()));
mnObj.push_back(Pair("service", activeMasternode.service.ToString())); mnObj.push_back(Pair("service", activeMasternodeInfo.service.ToString()));
CMasternode mn; CMasternode mn;
if(mnodeman.Get(activeMasternode.outpoint, mn)) { if(mnodeman.Get(activeMasternodeInfo.outpoint, mn)) {
mnObj.push_back(Pair("payee", CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString())); mnObj.push_back(Pair("payee", CBitcoinAddress(mn.keyIDCollateralAddress).ToString()));
} }
mnObj.push_back(Pair("status", activeMasternode.GetStatus())); mnObj.push_back(Pair("status", legacyActiveMasternodeManager.GetStatus()));
return mnObj; return mnObj;
} }
@ -538,7 +538,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
" payee - Print Dash address associated with a masternode (can be additionally filtered,\n" " payee - Print Dash address associated with a masternode (can be additionally filtered,\n"
" partial match)\n" " partial match)\n"
" protocol - Print protocol of a masternode (can be additionally filtered, exact match)\n" " protocol - Print protocol of a masternode (can be additionally filtered, exact match)\n"
" pubkey - Print the masternode (not collateral) public key\n" " keyid - Print the masternode (not collateral) key id\n"
" rank - Print rank of a masternode based on current block\n" " rank - Print rank of a masternode based on current block\n"
" sentinel - Print sentinel version of a masternode (can be additionally filtered, exact match)\n" " sentinel - Print sentinel version of a masternode (can be additionally filtered, exact match)\n"
" status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / SENTINEL_PING_EXPIRED / NEW_START_REQUIRED /\n" " status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / SENTINEL_PING_EXPIRED / NEW_START_REQUIRED /\n"
@ -592,7 +592,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
streamFull << std::setw(18) << streamFull << std::setw(18) <<
mn.GetStatus() << " " << mn.GetStatus() << " " <<
mn.nProtocolVersion << " " << mn.nProtocolVersion << " " <<
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " << CBitcoinAddress(mn.keyIDCollateralAddress).ToString() << " " <<
(int64_t)mn.lastPing.sigTime << " " << std::setw(8) << (int64_t)mn.lastPing.sigTime << " " << std::setw(8) <<
(int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " << std::setw(10) << (int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " << std::setw(10) <<
mn.GetLastPaidTime() << " " << std::setw(6) << mn.GetLastPaidTime() << " " << std::setw(6) <<
@ -607,7 +607,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
streamInfo << std::setw(18) << streamInfo << std::setw(18) <<
mn.GetStatus() << " " << mn.GetStatus() << " " <<
mn.nProtocolVersion << " " << mn.nProtocolVersion << " " <<
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " << CBitcoinAddress(mn.keyIDCollateralAddress).ToString() << " " <<
(int64_t)mn.lastPing.sigTime << " " << std::setw(8) << (int64_t)mn.lastPing.sigTime << " " << std::setw(8) <<
(int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " << (int64_t)(mn.lastPing.sigTime - mn.sigTime) << " " <<
mn.lastPing.GetSentinelString() << " " << mn.lastPing.GetSentinelString() << " " <<
@ -656,7 +656,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, (int64_t)mn.lastPing.sigTime)); obj.push_back(Pair(strOutpoint, (int64_t)mn.lastPing.sigTime));
} else if (strMode == "payee") { } else if (strMode == "payee") {
CBitcoinAddress address(mn.pubKeyCollateralAddress.GetID()); CBitcoinAddress address(mn.keyIDCollateralAddress);
std::string strPayee = address.ToString(); std::string strPayee = address.ToString();
if (strFilter !="" && strPayee.find(strFilter) == std::string::npos && if (strFilter !="" && strPayee.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) continue;
@ -665,9 +665,9 @@ UniValue masternodelist(const JSONRPCRequest& request)
if (strFilter !="" && strFilter != strprintf("%d", mn.nProtocolVersion) && if (strFilter !="" && strFilter != strprintf("%d", mn.nProtocolVersion) &&
strOutpoint.find(strFilter) == std::string::npos) continue; strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, mn.nProtocolVersion)); obj.push_back(Pair(strOutpoint, mn.nProtocolVersion));
} else if (strMode == "pubkey") { } else if (strMode == "keyid") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue; if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, HexStr(mn.pubKeyMasternode))); obj.push_back(Pair(strOutpoint, HexStr(mn.keyIDMasternode)));
} else if (strMode == "status") { } else if (strMode == "status") {
std::string strStatus = mn.GetStatus(); std::string strStatus = mn.GetStatus();
if (strFilter !="" && strStatus.find(strFilter) == std::string::npos && if (strFilter !="" && strStatus.find(strFilter) == std::string::npos &&
@ -852,8 +852,8 @@ UniValue masternodebroadcast(const JSONRPCRequest& request)
nSuccessful++; nSuccessful++;
resultObj.push_back(Pair("outpoint", mnb.outpoint.ToStringShort())); resultObj.push_back(Pair("outpoint", mnb.outpoint.ToStringShort()));
resultObj.push_back(Pair("addr", mnb.addr.ToString())); resultObj.push_back(Pair("addr", mnb.addr.ToString()));
resultObj.push_back(Pair("pubKeyCollateralAddress", CBitcoinAddress(mnb.pubKeyCollateralAddress.GetID()).ToString())); resultObj.push_back(Pair("keyIDCollateralAddress", CBitcoinAddress(mnb.keyIDCollateralAddress).ToString()));
resultObj.push_back(Pair("pubKeyMasternode", CBitcoinAddress(mnb.pubKeyMasternode.GetID()).ToString())); resultObj.push_back(Pair("keyIDMasternode", CBitcoinAddress(mnb.keyIDMasternode).ToString()));
resultObj.push_back(Pair("vchSig", EncodeBase64(&mnb.vchSig[0], mnb.vchSig.size()))); resultObj.push_back(Pair("vchSig", EncodeBase64(&mnb.vchSig[0], mnb.vchSig.size())));
resultObj.push_back(Pair("sigTime", mnb.sigTime)); resultObj.push_back(Pair("sigTime", mnb.sigTime));
resultObj.push_back(Pair("protocolVersion", mnb.nProtocolVersion)); resultObj.push_back(Pair("protocolVersion", mnb.nProtocolVersion));
@ -944,7 +944,7 @@ UniValue sentinelping(const JSONRPCRequest& request)
); );
} }
activeMasternode.UpdateSentinelPing(StringVersionToInt(request.params[0].get_str())); legacyActiveMasternodeManager.UpdateSentinelPing(StringVersionToInt(request.params[0].get_str()));
return true; return true;
} }