Merge pull request #356 from UdjinM6/v0.12.0.x_mnping_blockhash

V0.12.0.x add recent (tip - 12) blockhash to mnping
This commit is contained in:
evan82 2015-06-09 20:04:12 -06:00
commit 07fbdfc525
2 changed files with 31 additions and 14 deletions

View File

@ -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<std::string>(sigTime);
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(sigTime);
if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) {
LogPrintf("CMasternodePing::Sign() - Error: %s\n", errorMessage.c_str());
@ -549,23 +551,37 @@ 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<std::string>(sigTime);
std::string strMessage = vin.ToString() + blockHash.ToString() + boost::lexical_cast<std::string>(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)
{
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;
@ -574,7 +590,6 @@ bool CMasternodePing::CheckAndUpdate(int& nDos)
return true;
}
}
}
return false;
}

View File

@ -309,6 +309,7 @@ class CMasternodePing
public:
CTxIn vin;
uint256 blockHash;
std::vector<unsigned char> vchSig;
int64_t sigTime; //dsee message times
//removed stop
@ -321,6 +322,7 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(vin);
READWRITE(blockHash);
READWRITE(sigTime);
READWRITE(vchSig);
}