From 0bc6d92334e85560d4c7c629d29b433218d3b9b4 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Thu, 23 Feb 2017 07:29:00 -0500 Subject: [PATCH] Define current votes by creation time instead of arrival time (#1360) --- src/governance-object.cpp | 12 +++++++++++- src/governance-object.h | 7 +++++-- src/governance.cpp | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/governance-object.cpp b/src/governance-object.cpp index 0f8d7e9406..7a5407ec14 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -140,6 +140,16 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, it2 = recVote.mapInstances.insert(vote_instance_m_t::value_type(int(eSignal), vote_instance_t())).first; } vote_instance_t& voteInstance = it2->second; + + // Reject obsolete votes + if(vote.GetTimestamp() < voteInstance.nCreationTime) { + std::ostringstream ostr; + ostr << "CGovernanceObject::ProcessVote -- Obsolete vote" << "\n"; + LogPrint("gobject", ostr.str().c_str()); + exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_NONE); + return false; + } + int64_t nNow = GetTime(); int64_t nVoteTimeUpdate = voteInstance.nTime; if(governance.AreRateChecksEnabled()) { @@ -168,7 +178,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom, governance.AddInvalidVote(vote); return false; } - voteInstance = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate); + voteInstance = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp()); fileVotes.AddVote(vote); mnodeman.AddGovernanceVote(vote.GetVinMasternode(), vote.GetParentHash()); fDirtyCache = true; diff --git a/src/governance-object.h b/src/governance-object.h index 974c923dc2..874cdf3d5b 100644 --- a/src/governance-object.h +++ b/src/governance-object.h @@ -62,10 +62,12 @@ struct vote_instance_t { vote_outcome_enum_t eOutcome; int64_t nTime; + int64_t nCreationTime; - vote_instance_t(vote_outcome_enum_t eOutcomeIn = VOTE_OUTCOME_NONE, int64_t nTimeIn = 0) + vote_instance_t(vote_outcome_enum_t eOutcomeIn = VOTE_OUTCOME_NONE, int64_t nTimeIn = 0, int64_t nCreationTimeIn = 0) : eOutcome(eOutcomeIn), - nTime(nTimeIn) + nTime(nTimeIn), + nCreationTime(nCreationTimeIn) {} ADD_SERIALIZE_METHODS; @@ -76,6 +78,7 @@ struct vote_instance_t { int nOutcome = int(eOutcome); READWRITE(nOutcome); READWRITE(nTime); + READWRITE(nCreationTime); if(ser_action.ForRead()) { eOutcome = vote_outcome_enum_t(nOutcome); } diff --git a/src/governance.cpp b/src/governance.cpp index 72d728b8ee..227c09b430 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -20,7 +20,7 @@ std::map mapAskedForGovernanceObject; int nSubmittedFinalBudget; -const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-10"; +const std::string CGovernanceManager::SERIALIZATION_VERSION_STRING = "CGovernanceManager-Version-11"; CGovernanceManager::CGovernanceManager() : pCurrentBlockIndex(NULL), @@ -593,10 +593,10 @@ std::vector CGovernanceManager::GetCurrentVotes(const uint256& for (vote_instance_m_it it3 = voteRecord.mapInstances.begin(); it3 != voteRecord.mapInstances.end(); ++it3) { int signal = (it3->first); int outcome = ((it3->second).eOutcome); - int64_t nTime = ((it3->second).nTime); + int64_t nCreationTime = ((it3->second).nCreationTime); CGovernanceVote vote = CGovernanceVote(mnCollateralOutpoint, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome); - vote.SetTime(nTime); + vote.SetTime(nCreationTime); vecResult.push_back(vote); }