Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename minVoters to quorum #1578

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class CMainParams : public CChainParams {
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.voc.fee = 50 * COIN;
consensus.props.voc.majorityThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.minVoting = COIN / 100; // 1% of the masternodes must vote
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 130000; // tally votes every 130K blocks

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI of 200 per block (rate normalized to (COIN == 100%))
Expand Down Expand Up @@ -446,7 +446,7 @@ class CTestNetParams : public CChainParams {
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.voc.fee = 50 * COIN;
consensus.props.voc.majorityThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.minVoting = COIN / 100; // 1% of the masternodes must vote
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 70000; // tally votes every 70K blocks

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
Expand Down Expand Up @@ -647,7 +647,7 @@ class CDevNetParams : public CChainParams {
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.voc.fee = 5 * COIN;
consensus.props.voc.majorityThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.minVoting = COIN / 100; // 1% of the masternodes must vote
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 100; // tally votes every 1K blocks

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
Expand Down Expand Up @@ -840,7 +840,7 @@ class CRegTestParams : public CChainParams {
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.voc.fee = 5 * COIN;
consensus.props.voc.majorityThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.minVoting = COIN / 100; // 1% of the masternodes must vote
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 70; // tally votes every 70 blocks

consensus.vaultCreationFee = 1 * COIN;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct Params {
CAmount majorityThreshold;
} cfp, brp, voc;
uint32_t votingPeriod;
CAmount minVoting;
CAmount quorum;
};
CPropsParams props;

Expand Down
8 changes: 4 additions & 4 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const std::map<uint8_t, std::map<std::string, uint8_t>>& ATTRIBUTES::allowedKeys
{"voc_emergency_period", GovernanceKeys::VOCEmergencyPeriod},
{"voc_emergency_quorum", GovernanceKeys::VOCEmergencyQuorum},
{"voc_required_votes", GovernanceKeys::VOCMajority},
{"quorum", GovernanceKeys::MinVoters},
{"quorum", GovernanceKeys::Quorum},
{"voting_period", GovernanceKeys::VotingPeriod},
}
},
Expand Down Expand Up @@ -307,7 +307,7 @@ const std::map<uint8_t, std::map<uint8_t, std::string>>& ATTRIBUTES::displayKeys
{GovernanceKeys::VOCEmergencyPeriod, "voc_emergency_period"},
{GovernanceKeys::VOCEmergencyQuorum, "voc_emergency_quorum"},
{GovernanceKeys::VOCMajority, "voc_required_votes"},
{GovernanceKeys::MinVoters, "quorum"},
{GovernanceKeys::Quorum, "quorum"},
{GovernanceKeys::VotingPeriod, "voting_period"},
}
},
Expand Down Expand Up @@ -632,7 +632,7 @@ const std::map<uint8_t, std::map<uint8_t,
{GovernanceKeys::VOCEmergencyPeriod, VerifyUInt32},
{GovernanceKeys::VOCEmergencyQuorum, VerifyPct},
{GovernanceKeys::VOCMajority, VerifyPct},
{GovernanceKeys::MinVoters, VerifyPct},
{GovernanceKeys::Quorum, VerifyPct},
{GovernanceKeys::VotingPeriod, VerifyUInt32},
}
},
Expand Down Expand Up @@ -855,7 +855,7 @@ Res ATTRIBUTES::ProcessVariable(const std::string& key, std::optional<std::strin
&& typeKey != GovernanceKeys::CFPMajority && typeKey != GovernanceKeys::VOCFee
&& typeKey != GovernanceKeys::VOCMajority && typeKey != GovernanceKeys::VOCEmergencyPeriod
&& typeKey != GovernanceKeys::VOCEmergencyFee && typeKey != GovernanceKeys::VOCEmergencyQuorum
&& typeKey != GovernanceKeys::MinVoters && typeKey != GovernanceKeys::VotingPeriod)
&& typeKey != GovernanceKeys::Quorum && typeKey != GovernanceKeys::VotingPeriod)
return Res::Err("Unsupported key for Governance Proposal section - {%d}", typeKey);
} else {
return Res::Err("Unsupported Governance ID");
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ enum GovernanceKeys : uint8_t {
VOCEmergencyFee = 'g',
VOCEmergencyPeriod = 'h',
VOCMajority = 'i',
MinVoters = 'j',
Quorum = 'j',
VotingPeriod = 'k',
VOCEmergencyQuorum = 'l',
};
Expand Down
6 changes: 3 additions & 3 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,14 +1348,14 @@ CAmount CCustomCSView::GetMajorityFromAttributes(const CPropType& type) const
return 0;
}

CAmount CCustomCSView::GetMinVotersFromAttributes() const
CAmount CCustomCSView::GetQuorumFromAttributes() const
{
auto attributes = GetAttributes();
assert(attributes);

CDataStructureV0 MinVotersKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::MinVoters};
CDataStructureV0 QuorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::Quorum};

return attributes->GetValue(MinVotersKey, Params().GetConsensus().props.minVoting);
return attributes->GetValue(QuorumKey, Params().GetConsensus().props.quorum);
}

CAmount CCustomCSView::GetFeeBurnPctFromAttributes() const
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class CCustomCSView
uint32_t GetVotingPeriodFromAttributes() const override;
uint32_t GetEmergencyPeriodFromAttributes(const CPropType& type) const override;
CAmount GetMajorityFromAttributes(const CPropType& type) const override;
CAmount GetMinVotersFromAttributes() const override;
CAmount GetQuorumFromAttributes() const override;
CAmount GetFeeBurnPctFromAttributes() const override;

struct DbVersion { static constexpr uint8_t prefix() { return 'D'; } };
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Res CPropsView::CreateProp(const CPropId& propId, uint32_t height, const CCreate
prop.creationHeight = height;
prop.votingPeriod = (emergency ? GetEmergencyPeriodFromAttributes(type) : GetVotingPeriodFromAttributes());
prop.majority = GetMajorityFromAttributes(type);
prop.minVoters = GetMinVotersFromAttributes();
prop.quorum = GetQuorumFromAttributes();
prop.fee = fee;
prop.feeBurnAmount = MultiplyAmounts(fee, GetFeeBurnPctFromAttributes());

Expand Down
6 changes: 3 additions & 3 deletions src/masternodes/proposals.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct CPropObject : public CCreatePropMessage {

uint32_t votingPeriod;
CAmount majority;
CAmount minVoters;
CAmount quorum;
CAmount fee;
CAmount feeBurnAmount;

Expand All @@ -114,7 +114,7 @@ struct CPropObject : public CCreatePropMessage {
READWRITE(finalHeight);
READWRITE(votingPeriod);
READWRITE(majority);
READWRITE(minVoters);
READWRITE(quorum);
READWRITE(fee);
READWRITE(feeBurnAmount);
}
Expand Down Expand Up @@ -155,7 +155,7 @@ class CPropsView : public virtual CStorageView
virtual uint32_t GetVotingPeriodFromAttributes() const = 0;
virtual uint32_t GetEmergencyPeriodFromAttributes(const CPropType& type) const = 0;
virtual CAmount GetMajorityFromAttributes(const CPropType& type) const = 0;
virtual CAmount GetMinVotersFromAttributes() const = 0;
virtual CAmount GetQuorumFromAttributes() const = 0;
virtual CAmount GetFeeBurnPctFromAttributes() const = 0;

struct ByType { static constexpr uint8_t prefix() { return 0x2B; } };
Expand Down
8 changes: 4 additions & 4 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,14 @@ UniValue getgovproposal(const JSONRPCRequest& request)
auto allVotes = lround(voters * 10000.f / activeMasternodes.size());
CDataStructureV0 cfpMajority{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPMajority};
CDataStructureV0 vocMajority{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCMajority};
CDataStructureV0 minVoting{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::MinVoters};
CDataStructureV0 quorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::Quorum};

auto attributes = view.GetAttributes();
if (!attributes)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Attributes access failure");

auto minVotes = attributes->GetValue(minVoting, Params().GetConsensus().props.minVoting) / 10000;
auto valid = allVotes > minVotes;
auto quorum = attributes->GetValue(quorumKey, Params().GetConsensus().props.quorum) / 10000;
auto valid = allVotes > quorum;

if (valid) {
switch(prop->type) {
Expand Down Expand Up @@ -580,7 +580,7 @@ UniValue getgovproposal(const JSONRPCRequest& request)
if (valid) {
ret.pushKV("approval", strprintf("%d.%02d of %d.%02d%%", votes / 100, votes % 100, majorityThreshold / 100, majorityThreshold % 100));
} else {
ret.pushKV("validity", strprintf("%d.%02d of %d.%02d%%", allVotes / 100, allVotes % 100, minVotes / 100, minVotes % 100));
ret.pushKV("validity", strprintf("%d.%02d of %d.%02d%%", allVotes / 100, allVotes % 100, quorum / 100, quorum % 100));
}

auto target = Params().GetConsensus().pos.nTargetSpacing;
Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4246,15 +4246,15 @@ void CChainState::ProcessProposalEvents(const CBlockIndex* pindex, CCustomCSView
}
}

CDataStructureV0 minVoting{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::MinVoters};
CDataStructureV0 quorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::Quorum};
CDataStructureV0 vocEmergencyQuorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCEmergencyQuorum};

bool emergency = prop.options & CPropOption::Emergency;
uint64_t quorum;
if (prop.type == CPropType::VoteOfConfidence && emergency) {
quorum = attributes->GetValue(vocEmergencyQuorumKey, COIN / 10) / 10000;
} else {
quorum = attributes->GetValue(minVoting, chainparams.GetConsensus().props.minVoting) / 10000;
quorum = attributes->GetValue(quorumKey, chainparams.GetConsensus().props.quorum) / 10000;
}

if (lround(voters.size() * 10000.f / activeMasternodes.size()) <= quorum) {
Expand Down