Skip to content

Commit

Permalink
Minor cleanup and restoration of some previous values
Browse files Browse the repository at this point in the history
  • Loading branch information
barrystyle committed Jul 7, 2019
1 parent 303b56c commit 5379db2
Show file tree
Hide file tree
Showing 12 changed files with 651 additions and 179 deletions.
25 changes: 11 additions & 14 deletions src/activemasternode.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ void CActiveMasternode::ManageStatus()
return;
}

if (status == ACTIVE_MASTERNODE_SYNC_IN_PROCESS) status = ACTIVE_MASTERNODE_INITIAL;
if (status == ACTIVE_MASTERNODE_SYNC_IN_PROCESS)
status = ACTIVE_MASTERNODE_INITIAL;

if (status == ACTIVE_MASTERNODE_INITIAL) {
CMasternode* pmn;
pmn = mnodeman.Find(pubKeyMasternode);
if (pmn != NULL) {
pmn->Check();
if (pmn->IsEnabled() && pmn->protocolVersion == PROTOCOL_VERSION) EnableHotColdMasterNode(pmn->vin, pmn->addr);
if (pmn->IsEnabled() && pmn->protocolVersion == PROTOCOL_VERSION)
EnableHotColdMasterNode(pmn->vin, pmn->addr);
}
}

Expand Down Expand Up @@ -68,17 +70,9 @@ void CActiveMasternode::ManageStatus()
service = CService(strMasterNodeAddr);
}

if (Params().NetworkID() == CBaseChainParams::MAIN) {
if (service.GetPort() != 40555) {
notCapableReason = strprintf("Invalid port: %u - only 40555 is supported on mainnet.", service.GetPort());
LogPrintf("CActiveMasternode::ManageStatus() - not capable: %s\n", notCapableReason);
return;
}
} else if (service.GetPort() == 40555) {
notCapableReason = strprintf("Invalid port: %u - 40555 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 @@ -233,6 +227,7 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
return false;
}

// The service needs the correct default port to work properly
if(!CMasternodeBroadcast::CheckDefaultPort(strService, errorMessage, "CActiveMasternode::Register()"))
return false;
Expand Down Expand Up @@ -360,7 +355,6 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
return GetVinFromOutput(*selectedOutput, vin, pubkey, secretKey);
}


// Extract Masternode vin information from output
bool CActiveMasternode::GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey)
{
Expand Down Expand Up @@ -422,6 +416,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()

// Filter
for (const COutput& out : vCoins) {

if(CMasternode::IsDepositCoins(out.tx->vout[out.i].nValue))
filteredCoins.push_back(out);
}
Expand All @@ -432,7 +427,8 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()
// when starting a Masternode, this can enable to run as a hot wallet with no funds
bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newService)
{
if (!fMasterNode) return false;
if (!fMasterNode)
return false;

status = ACTIVE_MASTERNODE_STARTED;

Expand All @@ -444,3 +440,4 @@ bool CActiveMasternode::EnableHotColdMasterNode(CTxIn& newVin, CService& newServ

return true;
}

2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-mnconf=<file>", strprintf(_("Specify masternode configuration file (default: %s)"), "masternode.conf"));
strUsage += HelpMessageOpt("-mnconflock=<n>", strprintf(_("Lock masternodes from masternode configuration file (default: %u)"), 1));
strUsage += HelpMessageOpt("-masternodeprivkey=<n>", _("Set the masternode private key"));
strUsage += HelpMessageOpt("-masternodeaddr=<n>", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:30555"));
strUsage += HelpMessageOpt("-masternodeaddr=<n>", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:40555"));

strUsage += HelpMessageGroup(_("SwiftX options:"));
strUsage += HelpMessageOpt("-enableswifttx=<n>", strprintf(_("Enable SwiftX, show confirmations for locked transactions (bool, default: %s)"), "true"));
Expand Down
69 changes: 46 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,9 @@ bool ActivateBestChain(CValidationState& state, CBlock* pblock, bool fAlreadyChe
uiInterface.NotifyBlockTip(hashNewTip);
}
} while (pindexMostWork != chainActive.Tip());
// CheckBlockIndex();

if(!IsInitialBlockDownload())
CheckBlockIndex();

// Write changes periodically to disk, after relay.
if (!FlushStateToDisk(state, FLUSH_STATE_PERIODIC)) {
Expand Down Expand Up @@ -3610,8 +3612,11 @@ bool ProcessNewBlock(CValidationState& state, CNode* pfrom, CBlock* pblock, CDis
bool ret = AcceptBlock (*pblock, state, &pindex, dbp, checked);
if (pindex && pfrom) {
mapBlockSource[pindex->GetBlockHash ()] = pfrom->GetId ();
}
// CheckBlockIndex ();
}

if(!IsInitialBlockDownload())
CheckBlockIndex();

if (!ret) {
// Check spamming
if(pindex && pfrom && GetBoolArg("-blockspamfilter", DEFAULT_BLOCK_SPAM_FILTER)) {
Expand Down Expand Up @@ -4702,6 +4707,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
AddTimeData(pfrom->addr, nTime);
}

else if (pfrom->nVersion == 0) {
// Must have a version message before anything else
Misbehaving(pfrom->GetId(), 1);
return false;
}

else if (strCommand == "verack") {
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));

Expand Down Expand Up @@ -4775,6 +4786,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,


else if (strCommand == "inv") {

vector<CInv> vInv;
vRecv >> vInv;
if (vInv.size() > MAX_INV_SZ) {
Expand All @@ -4785,20 +4797,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LOCK(cs_main);

std::vector<CInv> vToFetch;

for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) {
const CInv& inv = vInv[nInv];

boost::this_thread::interruption_point();
pfrom->AddInventoryKnown(inv);

bool fAlreadyHave = AlreadyHave(inv);
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);

if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK)
pfrom->AskFor(inv);


if (inv.type == MSG_BLOCK) {
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
Expand Down Expand Up @@ -5025,6 +5034,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
}

for (uint256 hash : vEraseQueue)
EraseOrphanTx(hash);
} else if (fMissingInputs) {
AddOrphanTx(tx, pfrom->GetId());

Expand Down Expand Up @@ -5252,12 +5263,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
} else {
sProblem = "Unsolicited pong without ping";
}
} else {
// This is most likely a bug in another implementation somewhere, cancel this ping
bPingFinished = true;
sProblem = "Short payload";
}

// else {
// // This is most likely a bug in another implementation somewhere, cancel this ping
// bPingFinished = true;
// sProblem = "Short payload";
// }

if (!(sProblem.empty())) {
LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n",
pfrom->id,
Expand Down Expand Up @@ -5430,19 +5443,26 @@ bool ProcessMessages(CNode* pfrom)
msg.hdr.nMessageSize, msg.vRecv.size(),
msg.complete() ? "Y" : "N");

// end, if an incomplete message is found
if (!msg.complete())
break;

/////////////////////////////////////////////////
CMessageHeader& hdr = msg.hdr;
string strCommand = hdr.GetCommand();
if (fDebug) LogPrintf("\e[32m%s\e[0m\n", strCommand.c_str());
/////////////////////////////////////////////////

// end, if an incomplete message is found
if (!msg.complete())
break;

// at this point, any failure means we can delete the current message
it++;

// Scan for message start
if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) {
LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id);
fOk = false;
break;
}

// Read header
if (!hdr.IsValid()) {
LogPrintf("PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n", SanitizeString(hdr.GetCommand()), pfrom->id);
Expand All @@ -5466,17 +5486,16 @@ bool ProcessMessages(CNode* pfrom)

// Process message
bool fRet = false;
/////////////////////////////////////////////////
if (fDebug) {
/////////////////////////////////////////////////
if (fDebug) {
char msgbuf[65536] = {0};
unsigned int msglen = vRecv.size();
if (msglen>65536) msglen = 65535;
memcpy(msgbuf, vRecv.str().c_str(), msglen);
for (unsigned int i = 0; i < msglen; i++)
printf("%02hhx", msgbuf[i]);
printf("\n");
}
/////////////////////////////////////////////////
if (msglen>65536) msglen = 65535;
memcpy(msgbuf, vRecv.str().c_str(), msglen);
for (unsigned int i = 0; i < msglen; i++) printf("%02hhx", msgbuf[i]);
printf("\n");
}
/////////////////////////////////////////////////
try {
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime);
boost::this_thread::interruption_point();
Expand Down Expand Up @@ -5515,6 +5534,10 @@ bool ProcessMessages(CNode* pfrom)

bool SendMessages(CNode* pto, bool fSendTrickle)
{
// Don't send anything until we get their version message
if (pto->nVersion == 0)
return true;

//
// Message: ping
//
Expand Down
28 changes: 14 additions & 14 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ bool CMasternodePaymentWinner::Sign(CKey& keyMasternode, CPubKey& pubKeyMasterno
payee.ToString();

if (!obfuScationSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
LogPrint("masternode","CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
return false;
}

if (!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) {
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
LogPrint("masternode","CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
return false;
}

Expand Down Expand Up @@ -408,8 +408,8 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
strPayeesPossible += "," + address2;
}

LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment to %s\n", strPayeesPossible.c_str());
// LogPrintf("CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str());
LogPrint("masternode","CMasternodePayments::IsTransactionValid - Missing required payment to %s\n", strPayeesPossible.c_str());
// LogPrint("masternode","CMasternodePayments::IsTransactionValid - Missing required payment of %s to %s\n", FormatMoney(requiredMasternodePayment).c_str(), strPayeesPossible.c_str());
return false;
}

Expand Down Expand Up @@ -496,22 +496,22 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError)

if (!pmn) {
strError = strprintf("Unknown Masternode %s", vinMasternode.prevout.hash.ToString());
LogPrintf("CMasternodePaymentWinner::IsValid - %s\n", strError);
LogPrint("masternode","CMasternodePaymentWinner::IsValid - %s\n", strError);
mnodeman.AskForMN(pnode, vinMasternode);
return false;
}

if (pmn->protocolVersion < ActiveProtocol()) {
strError = strprintf("Masternode protocol too old %d - req %d", pmn->protocolVersion, ActiveProtocol());
LogPrintf("CMasternodePaymentWinner::IsValid - %s\n", strError);
LogPrint("masternode","CMasternodePaymentWinner::IsValid - %s\n", strError);
return false;
}

int n = mnodeman.GetMasternodeRank(vinMasternode, nBlockHeight - 100, ActiveProtocol());

if(n == -1) {
strError = strprintf("Unknown Masternode (rank==-1) %s", vinMasternode.prevout.hash.ToString());
LogPrintf("CMasternodePaymentWinner::IsValid - %s\n", strError);
LogPrint("masternode","CMasternodePaymentWinner::IsValid - %s\n", strError);
return false;
}

Expand All @@ -520,7 +520,7 @@ bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError)
// We don't want to print all of these messages, or punish them unless they're way off
if (n > MNPAYMENTS_SIGNATURES_TOTAL * 2) {
strError = strprintf("Masternode not in the top %d (%d)", MNPAYMENTS_SIGNATURES_TOTAL * 2, n);
LogPrintf("CMasternodePaymentWinner::IsValid - %s\n", strError);
LogPrint("masternode","CMasternodePaymentWinner::IsValid - %s\n", strError);
if (masternodeSync.IsSynced()) Misbehaving(pnode->GetId(), 20);
}
return false;
Expand Down Expand Up @@ -551,15 +551,15 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
return false;
}

LogPrintf("CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString());
LogPrint("masternode","CMasternodePayments::ProcessBlock() Start nHeight %d - vin %s. \n", nBlockHeight, activeMasternode.vin.prevout.hash.ToString());
// pay to the oldest MN that still had no payment but its input is old enough and it was active long enough

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

if (!obfuScationSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) {
LogPrintf("CMasternodePayments::ProcessBlock() - Error upon calling SetKey: %s\n", errorMessage.c_str());
LogPrint("masternode","CMasternodePayments::ProcessBlock() - Error upon calling SetKey: %s\n", errorMessage.c_str());
return false;
}

Expand All @@ -574,7 +574,7 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
auto pmn = mnodeman.GetNextMasternodeInQueueForPayment(nBlockHeight, mnlevel, true, nCount);

if(!pmn) {
LogPrintf("CMasternodePayments::ProcessBlock() Failed to find masternode level %d to pay \n", mnlevel);
LogPrint("masternode","CMasternodePayments::ProcessBlock() Failed to find masternode level %d to pay \n", mnlevel);
continue;
}

Expand All @@ -587,14 +587,14 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)
ExtractDestination(payee, address1);
CBitcoinAddress address2{address1};

LogPrintf("CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d level %d. \n", address2.ToString().c_str(), newWinner.nBlockHeight, mnlevel);
LogPrint("masternode","CMasternodePayments::ProcessBlock() Winner payee %s nHeight %d level %d. \n", address2.ToString().c_str(), newWinner.nBlockHeight, mnlevel);

LogPrintf("CMasternodePayments::ProcessBlock() - Signing Winner level %d\n", mnlevel);
LogPrint("masternode","CMasternodePayments::ProcessBlock() - Signing Winner level %d\n", mnlevel);

if(!newWinner.Sign(keyMasternode, pubKeyMasternode))
continue;

LogPrintf("CMasternodePayments::ProcessBlock() - AddWinningMasternode level %d\n", mnlevel);
LogPrint("masternode","CMasternodePayments::ProcessBlock() - AddWinningMasternode level %d\n", mnlevel);

if(!AddWinningMasternode(newWinner))
continue;
Expand Down
7 changes: 4 additions & 3 deletions src/masternode-sync.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void CMasternodeSync::GetNextAsset()
RequestedMasternodeAssets = MASTERNODE_SYNC_MNW;
break;
case (MASTERNODE_SYNC_MNW):
LogPrintf("CMasternodeSync::GetNextAsset - Sync has finished\n");
LogPrint("masternode","CMasternodeSync::GetNextAsset - Sync has finished\n");
RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
break;
}
Expand Down Expand Up @@ -287,6 +287,7 @@ void CMasternodeSync::Process()
pnode->FulfilledRequest("getspork");

pnode->PushMessage("getsporks"); //get current network sporks
if (RequestedMasternodeAttempt >= 2) GetNextAsset();
RequestedMasternodeAttempt++;
return;
}
Expand All @@ -308,7 +309,7 @@ void CMasternodeSync::Process()
if (lastMasternodeList == 0 &&
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
if (IsSporkActive(SPORK_4_MASTERNODE_PAYMENT_ENFORCEMENT)) {
LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
LogPrint("masternode","CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED;
RequestedMasternodeAttempt = 0;
lastFailure = GetTime();
Expand Down Expand Up @@ -348,7 +349,7 @@ void CMasternodeSync::Process()
if (lastMasternodeWinner == 0 &&
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
if (IsSporkActive(SPORK_4_MASTERNODE_PAYMENT_ENFORCEMENT)) {
LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
LogPrint("masternode","CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n");
RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED;
RequestedMasternodeAttempt = 0;
lastFailure = GetTime();
Expand Down
Loading

0 comments on commit 5379db2

Please sign in to comment.