Skip to content

Commit

Permalink
refactor: more CGovernanceVote cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 4, 2024
1 parent efc8c99 commit c32fac0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
12 changes: 4 additions & 8 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,10 @@ std::vector<CGovernanceVote> 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/governance/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 7 additions & 7 deletions src/governance/vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down
37 changes: 19 additions & 18 deletions src/governance/vote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<vote_outcome_enum_t> : 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<vote_signal_enum_t> : std::true_type {};

/**
* Governance Voting
Expand Down Expand Up @@ -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<unsigned char> vchSig;

Expand All @@ -80,9 +81,9 @@ class CGovernanceVote

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; }

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c32fac0

Please sign in to comment.