From 9f2d79d9207db3af591e8f142eea866860c6571c Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Sun, 4 Dec 2016 15:33:39 -0500 Subject: [PATCH] Fix masternode rate checks (#1187) * Added logging to PushInventory * Fix LogPrint format * Log errors found during governance syncing * Turn off rate checks during syncing * Turn off rate check during maintenance --- src/governance.cpp | 52 +++++++++++++++++++++++++++++++++------------- src/net.h | 6 +++++- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 7379435e3..b4976214a 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -368,6 +368,8 @@ void CGovernanceManager::UpdateCachesAndClean() if(!pCurrentBlockIndex) return; + fRateChecksEnabled = false; + LogPrint("gobject", "CGovernanceManager::UpdateCachesAndClean -- After pCurrentBlockIndex (not NULL)\n"); // UPDATE CACHE FOR EACH OBJECT THAT IS FLAGGED DIRTYCACHE=TRUE @@ -423,6 +425,8 @@ void CGovernanceManager::UpdateCachesAndClean() ++it; } } + + fRateChecksEnabled = true; } CGovernanceObject *CGovernanceManager::FindGovernanceObject(const uint256& nHash) @@ -625,31 +629,51 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp) // SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT + LogPrint("gobject", "CGovernanceManager::Sync -- syncing to peer=%d, nProp = %s\n", pfrom->id, nProp.ToString()); + { LOCK(cs); + fRateChecksEnabled = false; for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { uint256 h = it->first; CGovernanceObject& govobj = it->second; - std::string strError; - if(govobj.IsSetCachedValid() && - (nProp == uint256() || h == nProp) && - govobj.IsValidLocally(pCurrentBlockIndex, strError, true)) { - // Push the inventory budget proposal message over to the other client - pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, h)); - ++nInvCount; + if((nProp != uint256()) && (h != nProp)) { + continue; + } - std::vector vecVotes = govobj.GetVoteFile().GetVotes(); - for(size_t i = 0; i < vecVotes.size(); ++i) { - if(!vecVotes[i].IsValid(true)) { - continue; - } - pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, vecVotes[i].GetHash())); - ++nInvCount; + LogPrint("gobject", "CGovernanceManager::Sync -- attempting to sync govobj: %s, peer=%d\n", govobj.GetHash().ToString(), pfrom->id); + + std::string strError; + bool fIsValid = govobj.IsValidLocally(pCurrentBlockIndex, strError, true); + if(!fIsValid) { + LogPrintf("CGovernanceManager::Sync -- not syncing invalid govobj: %s, strError = %s, fCachedValid = %d, peer=%d\n", + govobj.GetHash().ToString(), strError, govobj.IsSetCachedValid(), pfrom->id); + continue; + } + + if(!govobj.IsSetCachedValid()) { + LogPrintf("CGovernanceManager::Sync -- invalid flag cached, not syncing govobj: %s, fCachedValid = %d, peer=%d\n", + govobj.GetHash().ToString(), govobj.IsSetCachedValid(), pfrom->id); + continue; + } + + // Push the inventory budget proposal message over to the other client + LogPrint("gobject", "CGovernanceManager::Sync -- syncing govobj: %s, peer=%d\n", govobj.GetHash().ToString(), pfrom->id); + pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, h)); + ++nInvCount; + + std::vector vecVotes = govobj.GetVoteFile().GetVotes(); + for(size_t i = 0; i < vecVotes.size(); ++i) { + if(!vecVotes[i].IsValid(true)) { + continue; } + pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT_VOTE, vecVotes[i].GetHash())); + ++nInvCount; } } + fRateChecksEnabled = true; } pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_GOVOBJ, nInvCount); diff --git a/src/net.h b/src/net.h index a2b5b9152..bc57c8457 100644 --- a/src/net.h +++ b/src/net.h @@ -15,6 +15,7 @@ #include "streams.h" #include "sync.h" #include "uint256.h" +#include "util.h" #include #include @@ -510,8 +511,11 @@ public: { { LOCK(cs_inventory); - if (inv.type == MSG_TX && filterInventoryKnown.contains(inv.hash)) + if (inv.type == MSG_TX && filterInventoryKnown.contains(inv.hash)) { + LogPrint("net", "PushInventory -- filtered inv: %s peer=%d\n", inv.ToString(), id); return; + } + LogPrint("net", "PushInventory -- inv: %s peer=%d\n", inv.ToString(), id); vInventoryToSend.push_back(inv); } }