From fd1327031b4149d4852adf6aef0484336ec65f56 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 14 Nov 2016 13:07:11 -0500 Subject: [PATCH 1/5] Moved vote relaying into ProcessVote so that local votes are relayed --- src/governance.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/governance.cpp b/src/governance.cpp index 62e67e53b..7a7e866d6 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -223,7 +223,6 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C CGovernanceException exception; if(ProcessVote(pfrom, vote, exception)) { LogPrint("gobject", "CGovernanceManager -- Accepted vote\n"); - vote.Relay(); } else { LogPrint("gobject", "CGovernanceManager -- Rejected vote, error = %s\n", exception.what()); @@ -638,6 +637,8 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote, if(govobj.GetObjectType() == GOVERNANCE_OBJECT_WATCHDOG) { mnodeman.UpdateWatchdogVoteTime(vote.GetVinMasternode()); } + + vote.Relay(); } return fOk; } From 08e977efe503097f99fa69c4ae4b80cb6ee6ec86 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 14 Nov 2016 13:17:42 -0500 Subject: [PATCH 2/5] Change signature of Insert method to return indication of whether insertion succeeded --- src/cachemultimap.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cachemultimap.h b/src/cachemultimap.h index 4cdf12285..9a2bb5b2c 100644 --- a/src/cachemultimap.h +++ b/src/cachemultimap.h @@ -89,7 +89,7 @@ public: return nCurrentSize; } - void Insert(const K& key, const V& value) + bool Insert(const K& key, const V& value) { if(nCurrentSize == nMaxSize) { PruneLast(); @@ -102,7 +102,7 @@ public: if(mapIt.count(value) > 0) { // Don't insert duplicates - return; + return false; } listItems.push_front(item_t(key, value)); @@ -110,6 +110,7 @@ public: mapIt[value] = lit; ++nCurrentSize; + return true; } bool HasKey(const K& key) const From d167772643349a25235ce3d363dcfe8259cbeb58 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 14 Nov 2016 13:22:50 -0500 Subject: [PATCH 3/5] Only process orphan votes once --- src/governance.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 7a7e866d6..6a3aefe76 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -618,14 +618,15 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote, uint256 nHashGovobj = vote.GetParentHash(); object_m_it it = mapObjects.find(nHashGovobj); if(it == mapObjects.end()) { - mapOrphanVotes.Insert(nHashGovobj, vote); - RequestGovernanceObject(pfrom, nHashGovobj); - std::ostringstream ostr; - ostr << "CGovernanceManager::ProcessVote -- Unknown parent object " - << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() - << ", governance object hash = " << vote.GetParentHash().ToString() << "\n"; - LogPrintf(ostr.str().c_str()); - exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); + if(mapOrphanVotes.Insert(nHashGovobj, vote)) { + RequestGovernanceObject(pfrom, nHashGovobj); + std::ostringstream ostr; + ostr << "CGovernanceManager::ProcessVote -- Unknown parent object " + << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() + << ", governance object hash = " << vote.GetParentHash().ToString() << "\n"; + LogPrintf(ostr.str().c_str()); + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); + } return false; } @@ -814,14 +815,15 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, { int nMNIndex = governance.GetMasternodeIndex(vote.GetVinMasternode()); if(nMNIndex < 0) { - mapOrphanVotes.Insert(vote.GetVinMasternode(), vote); - if(pfrom) { - mnodeman.AskForMN(pfrom, vote.GetVinMasternode()); + if(mapOrphanVotes.Insert(vote.GetVinMasternode(), vote)) { + if(pfrom) { + mnodeman.AskForMN(pfrom, vote.GetVinMasternode()); + } + std::ostringstream ostr; + ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n"; + LogPrintf(ostr.str().c_str()); + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); } - std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n"; - LogPrintf(ostr.str().c_str()); - exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); return false; } From 31370decd7efcda258a1fd2ecd81f9ad0a121de5 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 14 Nov 2016 15:26:53 -0500 Subject: [PATCH 4/5] Changed log message handling due to code review suggestion --- src/governance.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 6a3aefe76..b6aeb48c2 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -618,14 +618,17 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote, uint256 nHashGovobj = vote.GetParentHash(); object_m_it it = mapObjects.find(nHashGovobj); if(it == mapObjects.end()) { + std::ostringstream ostr; + ostr << "CGovernanceManager::ProcessVote -- Unknown parent object " + << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() + << ", governance object hash = " << vote.GetParentHash().ToString() << "\n"; + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); if(mapOrphanVotes.Insert(nHashGovobj, vote)) { RequestGovernanceObject(pfrom, nHashGovobj); - std::ostringstream ostr; - ostr << "CGovernanceManager::ProcessVote -- Unknown parent object " - << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() - << ", governance object hash = " << vote.GetParentHash().ToString() << "\n"; LogPrintf(ostr.str().c_str()); - exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); + } + else { + LogPrint("gobject", ostr.str().c_str()); } return false; } @@ -815,14 +818,17 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, { int nMNIndex = governance.GetMasternodeIndex(vote.GetVinMasternode()); if(nMNIndex < 0) { + std::ostringstream ostr; + ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n"; + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); if(mapOrphanVotes.Insert(vote.GetVinMasternode(), vote)) { if(pfrom) { mnodeman.AskForMN(pfrom, vote.GetVinMasternode()); } - std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n"; LogPrintf(ostr.str().c_str()); - exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); + } + else { + LogPrint("gobject", ostr.str().c_str()); } return false; } From aaf96c9a007ce06d7c69b7872041da05f7640301 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Mon, 14 Nov 2016 15:28:46 -0500 Subject: [PATCH 5/5] Fix function name in log messages --- src/governance.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index b6aeb48c2..f8f616473 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -819,7 +819,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, int nMNIndex = governance.GetMasternodeIndex(vote.GetVinMasternode()); if(nMNIndex < 0) { std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Masternode index not found\n"; + ostr << "CGovernanceObject::ProcessVote -- Masternode index not found\n"; exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); if(mapOrphanVotes.Insert(vote.GetVinMasternode(), vote)) { if(pfrom) { @@ -841,14 +841,14 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, vote_signal_enum_t eSignal = vote.GetSignal(); if(eSignal == VOTE_SIGNAL_NONE) { std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Vote signal: none" << "\n"; + ostr << "CGovernanceObject::ProcessVote -- Vote signal: none" << "\n"; LogPrint("gobject", ostr.str().c_str()); exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); return false; } if(eSignal > MAX_SUPPORTED_VOTE_SIGNAL) { std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Unsupported vote signal:" << CGovernanceVoting::ConvertSignalToString(vote.GetSignal()) << "\n"; + ostr << "CGovernanceObject::ProcessVote -- Unsupported vote signal:" << CGovernanceVoting::ConvertSignalToString(vote.GetSignal()) << "\n"; LogPrintf(ostr.str().c_str()); exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20); return false; @@ -862,7 +862,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, int64_t nTimeDelta = nNow - voteInstance.nTime; if(nTimeDelta < GOVERNANCE_UPDATE_MIN) { std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Masternode voting too often " + ostr << "CGovernanceObject::ProcessVote -- Masternode voting too often " << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() << ", governance object hash = " << GetHash().ToString() << ", time delta = " << nTimeDelta << "\n"; @@ -873,7 +873,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, // Finally check that the vote is actually valid (done last because of cost of signature verification) if(!vote.IsValid(true)) { std::ostringstream ostr; - ostr << "CGovernanceObject::UpdateVote -- Invalid vote " + ostr << "CGovernanceObject::ProcessVote -- Invalid vote " << ", MN outpoint = " << vote.GetVinMasternode().prevout.ToStringShort() << ", governance object hash = " << GetHash().ToString() << ", vote hash = " << vote.GetHash().ToString() << "\n";