From 19d9a65f8af30a6cfe127903c9b53ddb4a333955 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 9 Jun 2015 04:36:33 +0300 Subject: [PATCH] add recent (tip - 12) block hash to mnping --- src/masternode.cpp | 41 ++++++++++++++++++++++++++++------------- src/masternode.h | 4 +++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index e6bdda2826..ae3cbad8e9 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -503,11 +503,13 @@ bool CMasternodeBroadcast::Sign(CKey& keyCollateralAddress) CMasternodePing::CMasternodePing() { vin = CTxIn(); + blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash(); } CMasternodePing::CMasternodePing(CTxIn& newVin) { vin = newVin; + blockHash = chainActive[chainActive.Height() - 12]->GetBlockHash(); } @@ -517,7 +519,7 @@ bool CMasternodePing::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) std::string strMasterNodeSignMessage; sigTime = GetAdjustedTime(); - std::string strMessage = boost::lexical_cast(sigTime); + std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) { LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str()); @@ -549,30 +551,43 @@ bool CMasternodePing::CheckAndUpdate(int& nDos) if(pmn != NULL && pmn->protocolVersion >= nMasternodeMinProtocol) { // LogPrintf("mnping - Found corresponding mn for vin: %s\n", vin.ToString().c_str()); - // take this only if it's newer - if(pmn->lastMnping < sigTime) + // take this only if it's newer and was last updated more then MASTERNODE_MIN_MNP_SECONDS ago + if(pmn->lastMnping < sigTime && !pmn->UpdatedWithin(MASTERNODE_MIN_MNP_SECONDS)) { - std::string strMessage = boost::lexical_cast(sigTime); + std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast(sigTime); std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) { - LogPrintf("mnping - Got bad Masternode address signature %s \n", vin.ToString().c_str()); + LogPrintf("mnping - Got bad Masternode address signature %s\n", vin.ToString()); nDos = 33; return false; } pmn->lastMnping = sigTime; - if(!pmn->UpdatedWithin(MASTERNODE_MIN_MNP_SECONDS)) + BlockMap::iterator mi = mapBlockIndex.find(blockHash); + if (mi != mapBlockIndex.end() && (*mi).second) { - pmn->UpdateLastSeen(); - pmn->Check(); - if(!pmn->IsEnabled()) return false; - - Relay(); - return true; + if((*mi).second->nHeight < chainActive.Height() - 24) + { + LogPrintf("mnping - Masternode %s block hash %s is too old\n", vin.ToString(), blockHash.ToString()); + nDos = 33; + return false; + } + } else { + if (fDebug) LogPrintf("mnping - Masternode %s block hash %s is unknown\n", vin.ToString(), blockHash.ToString()); + // maybe we stuck so we shouldn't ban this node, just fail to accept it + // TODO: or should we also request this block? + return false; } + + pmn->UpdateLastSeen(); + pmn->Check(); + if(!pmn->IsEnabled()) return false; + + Relay(); + return true; } } @@ -589,4 +604,4 @@ void CMasternodePing::Relay() BOOST_FOREACH(CNode* pnode, vNodes){ pnode->PushMessage("inv", vInv); } -} \ No newline at end of file +} diff --git a/src/masternode.h b/src/masternode.h index 1254d70e43..5262c2319f 100644 --- a/src/masternode.h +++ b/src/masternode.h @@ -309,6 +309,7 @@ class CMasternodePing public: CTxIn vin; + uint256 blockHash; std::vector vchSig; int64_t sigTime; //dsee message times //removed stop @@ -321,6 +322,7 @@ public: template inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(vin); + READWRITE(blockHash); READWRITE(sigTime); READWRITE(vchSig); } @@ -333,4 +335,4 @@ public: return Hash(BEGIN(vin), END(vin), BEGIN(sigTime), END(sigTime)); } }; -#endif \ No newline at end of file +#endif