Skip to content

Commit bc8be7c

Browse files
committed
[core] Fix masternode broadcast for networks != MAINNET (update)
1 parent ae72bf4 commit bc8be7c

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

src/activemasternode.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ void CActiveMasternode::ManageStatus()
6767
service = CService(strMasterNodeAddr);
6868
}
6969

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

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

@@ -266,17 +258,10 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
266258
}
267259

268260
CService service = CService(strService);
269-
if (Params().NetworkID() == CBaseChainParams::MAIN) {
270-
if (service.GetPort() != 51472) {
271-
errorMessage = strprintf("Invalid port %u for masternode %s - only 51472 is supported on mainnet.", service.GetPort(), strService);
272-
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
273-
return false;
274-
}
275-
} else if (service.GetPort() == 51472) {
276-
errorMessage = strprintf("Invalid port %u for masternode %s - 51472 is only supported on mainnet.", service.GetPort(), strService);
277-
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
261+
262+
// The service needs the correct default port to work properly
263+
if(!CMasternodeBroadcast::CheckDefaultPort(strService, errorMessage, "CActiveMasternode::Register()"))
278264
return false;
279-
}
280265

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

src/masternode.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,9 @@ bool CMasternodeBroadcast::Create(std::string strService, std::string strKeyMast
412412
return false;
413413
}
414414

415-
CService service = CService(strService);
416-
int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort();
417-
if (Params().NetworkID() == CBaseChainParams::MAIN) {
418-
if (service.GetPort() != mainnetDefaultPort) {
419-
strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort);
420-
LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet);
421-
return false;
422-
}
423-
} else if (service.GetPort() == mainnetDefaultPort) {
424-
strErrorRet = strprintf("Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort);
425-
LogPrint("masternode","CMasternodeBroadcast::Create -- %s\n", strErrorRet);
415+
// The service needs the correct default port to work properly
416+
if(!CheckDefaultPort(strService, strErrorRet, "CMasternodeBroadcast::Create"))
426417
return false;
427-
}
428418

429419
return Create(txin, CService(strService), keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
430420
}
@@ -466,6 +456,21 @@ bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollater
466456
return true;
467457
}
468458

459+
bool CMasternodeBroadcast::CheckDefaultPort(std::string strService, std::string& strErrorRet, std::string strContext)
460+
{
461+
CService service = CService(strService);
462+
int nDefaultPort = Params().GetDefaultPort();
463+
464+
if (service.GetPort() != nDefaultPort) {
465+
strErrorRet = strprintf("Invalid port %u for masternode %s, only %d is supported on %s-net.",
466+
service.GetPort(), strService, nDefaultPort, Params().NetworkIDString());
467+
LogPrint("masternode", "%s - %s\n", strContext, strErrorRet);
468+
return false;
469+
}
470+
471+
return true;
472+
}
473+
469474
bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
470475
{
471476
// make sure signature isn't in the future (past is OK)

src/masternode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class CMasternodeBroadcast : public CMasternode
328328
/// Create Masternode broadcast, needs to be relayed manually after that
329329
static bool Create(CTxIn vin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet);
330330
static bool Create(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline = false);
331+
static bool CheckDefaultPort(std::string strService, std::string& strErrorRet, std::string strContext);
331332
};
332333

333334
#endif

0 commit comments

Comments
 (0)