From 5d58dd90c21e76bd96bffcf8d20c4ea374c89765 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 22 Nov 2017 17:27:06 +0300 Subject: [PATCH] Make sure to clear setAskFor in Dash submodules (#1730) * Make sure to clear setAskFor in Dash submodules Thanks @sidhujag for finding the bug * partially revert previous commit * skip mnv until mn list is synced --- src/governance.cpp | 25 +++++++++++++------------ src/instantx.cpp | 15 ++++++++------- src/masternode-payments.cpp | 8 +++++--- src/masternodeman.cpp | 9 ++++++++- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 4019ad43c..041025492 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -148,20 +148,20 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C { // MAKE SURE WE HAVE A VALID REFERENCE TO THE TIP BEFORE CONTINUING + CGovernanceObject govobj; + vRecv >> govobj; + + uint256 nHash = govobj.GetHash(); + + pfrom->setAskFor.erase(nHash); if(!masternodeSync.IsMasternodeListSynced()) { LogPrint("gobject", "MNGOVERNANCEOBJECT -- masternode list not synced\n"); return; } - CGovernanceObject govobj; - vRecv >> govobj; - - uint256 nHash = govobj.GetHash(); std::string strHash = nHash.ToString(); - pfrom->setAskFor.erase(nHash); - LogPrint("gobject", "MNGOVERNANCEOBJECT -- Received object: %s\n", strHash); if(!AcceptObjectMessage(nHash)) { @@ -232,22 +232,23 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C // A NEW GOVERNANCE OBJECT VOTE HAS ARRIVED else if (strCommand == NetMsgType::MNGOVERNANCEOBJECTVOTE) { + CGovernanceVote vote; + vRecv >> vote; + + uint256 nHash = vote.GetHash(); + + pfrom->setAskFor.erase(nHash); + // Ignore such messages until masternode list is synced if(!masternodeSync.IsMasternodeListSynced()) { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- masternode list not synced\n"); return; } - CGovernanceVote vote; - vRecv >> vote; - LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Received vote: %s\n", vote.ToString()); - uint256 nHash = vote.GetHash(); std::string strHash = nHash.ToString(); - pfrom->setAskFor.erase(nHash); - if(!AcceptVoteMessage(nHash)) { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Received unrequested vote object: %s, hash: %s, peer = %d\n", vote.ToString(), strHash, pfrom->GetId()); diff --git a/src/instantx.cpp b/src/instantx.cpp index 1d1c26671..8e849a758 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -45,9 +45,6 @@ void CInstantSend::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataSt if(fLiteMode) return; // disable all Dash specific functionality if(!sporkManager.IsSporkActive(SPORK_2_INSTANTSEND_ENABLED)) return; - // Ignore any InstantSend messages until masternode list is synced - if(!masternodeSync.IsMasternodeListSynced()) return; - // NOTE: NetMsgType::TXLOCKREQUEST is handled via ProcessMessage() in main.cpp if (strCommand == NetMsgType::TXLOCKVOTE) // InstantSend Transaction Lock Consensus Votes @@ -57,6 +54,14 @@ void CInstantSend::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataSt CTxLockVote vote; vRecv >> vote; + + uint256 nVoteHash = vote.GetHash(); + + pfrom->setAskFor.erase(nVoteHash); + + // Ignore any InstantSend messages until masternode list is synced + if(!masternodeSync.IsMasternodeListSynced()) return; + LOCK(cs_main); #ifdef ENABLE_WALLET if (pwalletMain) @@ -64,10 +69,6 @@ void CInstantSend::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataSt #endif LOCK(cs_instantsend); - uint256 nVoteHash = vote.GetHash(); - - pfrom->setAskFor.erase(nVoteHash); - if(mapTxLockVotes.count(nVoteHash)) return; mapTxLockVotes.insert(std::make_pair(nVoteHash, vote)); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 113ca8b80..f90c21e93 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -305,9 +305,6 @@ int CMasternodePayments::GetMinMasternodePaymentsProto() { void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman) { - // Ignore any payments messages until masternode list is synced - if(!masternodeSync.IsMasternodeListSynced()) return; - if(fLiteMode) return; // disable all Dash specific functionality if (strCommand == NetMsgType::MASTERNODEPAYMENTSYNC) { //Masternode Payments Request Sync @@ -342,6 +339,11 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand, pfrom->setAskFor.erase(nHash); + // TODO: clear setAskFor for MSG_MASTERNODE_PAYMENT_BLOCK too + + // Ignore any payments messages until masternode list is synced + if(!masternodeSync.IsMasternodeListSynced()) return; + { LOCK(cs_mapMasternodePaymentVotes); if(mapMasternodePaymentVotes.count(nHash)) { diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 53c22f5cd..bb1bc6b33 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -771,7 +771,6 @@ std::pair > CMasternodeMan::PopScheduledMnbRequestCo void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman) { if(fLiteMode) return; // disable all Dash specific functionality - if(!masternodeSync.IsBlockchainSynced()) return; if (strCommand == NetMsgType::MNANNOUNCE) { //Masternode Broadcast @@ -780,6 +779,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData pfrom->setAskFor.erase(mnb.GetHash()); + if(!masternodeSync.IsBlockchainSynced()) return; + LogPrint("masternode", "MNANNOUNCE -- Masternode announce, masternode=%s\n", mnb.vin.prevout.ToStringShort()); int nDos = 0; @@ -803,6 +804,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData pfrom->setAskFor.erase(nHash); + if(!masternodeSync.IsBlockchainSynced()) return; + LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort()); // Need LOCK2 here to ensure consistent locking order because the CheckAndUpdate call below locks cs_main @@ -909,6 +912,10 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData CMasternodeVerification mnv; vRecv >> mnv; + pfrom->setAskFor.erase(mnv.GetHash()); + + if(!masternodeSync.IsMasternodeListSynced()) return; + if(mnv.vchSig1.empty()) { // CASE 1: someone asked me to verify myself /IP we are using/ SendVerifyReply(pfrom, mnv, connman);