Skip to content

Commit

Permalink
[core] Fix masternode broadcast for networks != MAINNET (update)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs-X committed Jan 26, 2018
1 parent ae72bf4 commit bc8be7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
25 changes: 5 additions & 20 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,9 @@ void CActiveMasternode::ManageStatus()
service = CService(strMasterNodeAddr);
}

if (Params().NetworkID() == CBaseChainParams::MAIN) {
if (service.GetPort() != 51472) {
notCapableReason = strprintf("Invalid port: %u - only 51472 is supported on mainnet.", service.GetPort());
LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
return;
}
} else if (service.GetPort() == 51472) {
notCapableReason = strprintf("Invalid port: %u - 51472 is only supported on mainnet.", service.GetPort());
LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
// The service needs the correct default port to work properly
if(!CMasternodeBroadcast::CheckDefaultPort(strMasterNodeAddr, errorMessage, "CActiveMasternode::ManageStatus()"))
return;
}

LogPrintf("CActiveMasternode::ManageStatus() - Checking inbound connection to '%s'\n", service.ToString());

Expand Down Expand Up @@ -266,17 +258,10 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
}

CService service = CService(strService);
if (Params().NetworkID() == CBaseChainParams::MAIN) {
if (service.GetPort() != 51472) {
errorMessage = strprintf("Invalid port %u for masternode %s - only 51472 is supported on mainnet.", service.GetPort(), strService);
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
return false;
}
} else if (service.GetPort() == 51472) {
errorMessage = strprintf("Invalid port %u for masternode %s - 51472 is only supported on mainnet.", service.GetPort(), strService);
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);

// The service needs the correct default port to work properly
if(!CMasternodeBroadcast::CheckDefaultPort(strService, errorMessage, "CActiveMasternode::Register()"))
return false;
}

addrman.Add(CAddress(service), CNetAddr("127.0.0.1"), 2 * 60 * 60);

Expand Down
29 changes: 17 additions & 12 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,9 @@ bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMast
return false;
}

CService service = CService(strService);
int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort();
if (Params().NetworkID() == CBaseChainParams::MAIN) {
if (service.GetPort() != mainnetDefaultPort) {
strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort);
LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet);
return false;
}
} else if (service.GetPort() == mainnetDefaultPort) {
strErrorRet = strprintf("Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort);
LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet);
// The service needs the correct default port to work properly
if(!CheckDefaultPort(strService, strErrorRet, "CMasternodeBroadcast::Create"))
return false;
}

return Create(txin, CService(strService), keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
}
Expand Down Expand Up @@ -466,6 +456,21 @@ bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollater
return true;
}

bool CMasternodeBroadcast::CheckDefaultPort(std::string strService, std::string& strErrorRet, std::string strContext)
{
CService service = CService(strService);
int nDefaultPort = Params().GetDefaultPort();

if (service.GetPort() != nDefaultPort) {
strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on %s-net.",
service.GetPort(), strService, nDefaultPort, Params().NetworkIDString());
LogPrint("masternode", "%s - %s\n", strContext, strErrorRet);
return false;
}

return true;
}

bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
{
// make sure signature isn't in the future (past is OK)
Expand Down
1 change: 1 addition & 0 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class CMasternodeBroadcast : public CMasternode
/// Create Masternode broadcast, needs to be relayed manually after that
static bool Create(CTxIn vin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet);
static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline = false);
static bool CheckDefaultPort(std::string strService, std::string& strErrorRet, std::string strContext);
};

#endif

0 comments on commit bc8be7c

Please sign in to comment.