diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 7318708ecc..6b02357540 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -548,14 +548,10 @@ std::vector CGovernanceManager::GetCurrentVotes(const uint256& vote_rec_t voteRecord; if (!govobj.GetCurrentMNVotes(mnpair.first, voteRecord)) continue; - for (const auto& voteInstancePair : voteRecord.mapInstances) { - int signal = voteInstancePair.first; - int outcome = voteInstancePair.second.eOutcome; - int64_t nCreationTime = voteInstancePair.second.nCreationTime; - - CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome); - vote.SetTime(nCreationTime); - + for (const auto& [signal, vote_instance] : voteRecord.mapInstances) { + CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, + vote_instance.eOutcome); + vote.SetTime(vote_instance.nCreationTime); vecResult.push_back(vote); } } diff --git a/src/governance/object.cpp b/src/governance/object.cpp index a41fb48d00..6ae0ed619b 100644 --- a/src/governance/object.cpp +++ b/src/governance/object.cpp @@ -90,7 +90,7 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING); return false; } - if (eSignal > MAX_SUPPORTED_VOTE_SIGNAL) { + if (eSignal < VOTE_SIGNAL_NONE || eSignal >= VOTE_SIGNAL_UNKNOWN) { std::ostringstream ostr; ostr << "CGovernanceObject::ProcessVote -- Unsupported vote signal: " << CGovernanceVoting::ConvertSignalToString(vote.GetSignal()); LogPrintf("%s\n", ostr.str()); diff --git a/src/governance/vote.cpp b/src/governance/vote.cpp index 6f5e1f1709..5cfa2b1ac1 100644 --- a/src/governance/vote.cpp +++ b/src/governance/vote.cpp @@ -87,10 +87,10 @@ vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(const std::string& strVo CGovernanceVote::CGovernanceVote(const COutPoint& outpointMasternodeIn, const uint256& nParentHashIn, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) : - nVoteSignal(eVoteSignalIn), masternodeOutpoint(outpointMasternodeIn), nParentHash(nParentHashIn), nVoteOutcome(eVoteOutcomeIn), + nVoteSignal(eVoteSignalIn), nTime(GetAdjustedTime()) { UpdateHash(); @@ -197,15 +197,15 @@ bool CGovernanceVote::IsValid(const CDeterministicMNList& tip_mn_list, bool useV return false; } - // support up to MAX_SUPPORTED_VOTE_SIGNAL, can be extended - if (nVoteSignal > MAX_SUPPORTED_VOTE_SIGNAL) { - LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid signal(%d) - %s\n", nVoteSignal, GetHash().ToString()); + if (nVoteSignal < VOTE_SIGNAL_NONE || nVoteSignal >= VOTE_SIGNAL_UNKNOWN) { + LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid signal(%d) - %s\n", + nVoteSignal, GetHash().ToString()); return false; } - // 0=none, 1=yes, 2=no, 3=abstain. Beyond that reject votes - if (nVoteOutcome > 3) { - LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n", nVoteSignal, GetHash().ToString()); + if (nVoteOutcome < VOTE_OUTCOME_NONE || nVoteOutcome >= VOTE_OUTCOME_UNKNOWN) { + LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n", + nVoteOutcome, GetHash().ToString()); return false; } diff --git a/src/governance/vote.h b/src/governance/vote.h index 55573784a0..2b86c19471 100644 --- a/src/governance/vote.h +++ b/src/governance/vote.h @@ -18,24 +18,25 @@ class CKeyID; class PeerManager; // INTENTION OF MASTERNODES REGARDING ITEM -enum vote_outcome_enum_t : uint8_t { - VOTE_OUTCOME_NONE = 0, - VOTE_OUTCOME_YES = 1, - VOTE_OUTCOME_NO = 2, - VOTE_OUTCOME_ABSTAIN = 3 +enum vote_outcome_enum_t : int { + VOTE_OUTCOME_NONE = 0, + VOTE_OUTCOME_YES, + VOTE_OUTCOME_NO, + VOTE_OUTCOME_ABSTAIN, + VOTE_OUTCOME_UNKNOWN }; - +template<> struct is_serializable_enum : std::true_type {}; // SIGNAL VARIOUS THINGS TO HAPPEN: -enum vote_signal_enum_t : uint8_t { - VOTE_SIGNAL_NONE = 0, - VOTE_SIGNAL_FUNDING = 1, // -- fund this object for it's stated amount - VOTE_SIGNAL_VALID = 2, // -- this object checks out in sentinel engine - VOTE_SIGNAL_DELETE = 3, // -- this object should be deleted from memory entirely - VOTE_SIGNAL_ENDORSED = 4, // -- officially endorsed by the network somehow (delegation) +enum vote_signal_enum_t : int { + VOTE_SIGNAL_NONE = 0, + VOTE_SIGNAL_FUNDING, // -- fund this object for it's stated amount + VOTE_SIGNAL_VALID, // -- this object checks out in sentinel engine + VOTE_SIGNAL_DELETE, // -- this object should be deleted from memory entirely + VOTE_SIGNAL_ENDORSED, // -- officially endorsed by the network somehow (delegation) + VOTE_SIGNAL_UNKNOWN }; - -static constexpr int MAX_SUPPORTED_VOTE_SIGNAL = VOTE_SIGNAL_ENDORSED; +template<> struct is_serializable_enum : std::true_type {}; /** * Governance Voting @@ -63,10 +64,10 @@ class CGovernanceVote friend bool operator<(const CGovernanceVote& vote1, const CGovernanceVote& vote2); private: - int nVoteSignal{VOTE_SIGNAL_NONE}; // see VOTE_ACTIONS above COutPoint masternodeOutpoint; uint256 nParentHash; - int nVoteOutcome{VOTE_OUTCOME_NONE}; // see VOTE_OUTCOMES above + vote_outcome_enum_t nVoteOutcome{VOTE_OUTCOME_NONE}; + vote_signal_enum_t nVoteSignal{VOTE_SIGNAL_NONE}; int64_t nTime{0}; std::vector vchSig; @@ -80,9 +81,9 @@ public: int64_t GetTimestamp() const { return nTime; } - vote_signal_enum_t GetSignal() const { return vote_signal_enum_t(nVoteSignal); } + vote_signal_enum_t GetSignal() const { return nVoteSignal; } - vote_outcome_enum_t GetOutcome() const { return vote_outcome_enum_t(nVoteOutcome); } + vote_outcome_enum_t GetOutcome() const { return nVoteOutcome; } const uint256& GetParentHash() const { return nParentHash; } diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 11d6a936d0..0b9abd07b7 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -39,7 +39,7 @@ enum class TransactionError; struct CNodeStateStats; struct NodeContext; -enum vote_signal_enum_t : uint8_t; +enum vote_signal_enum_t : int; namespace interfaces { class Handler;