Skip to content

Commit

Permalink
Add fields to getgovproposal (#1583)
Browse files Browse the repository at this point in the history
* Renames contexthash->currentHash

* Renames nextCycle->currentCycle

* Renames finalizeAfter->endHeight

* Fixes typo currentHash->contextHash

* Renames endHeight->proposalEndHeight

* Adds cycleEndHeight to listgovproposals

* Fix lint error remove unnecessary include

* Update test/functional/feature_on_chain_government.py

Co-authored-by: Jouzo <[email protected]>

* Update src/masternodes/proposals.cpp

Co-authored-by: Jouzo <[email protected]>

* Rename approval->votes and fix tests

* Add missing fields in getgovproposal and remove ends fields

* Add missing fields to getgovproposal

* Use approvalThreshold and quorum from attributes

Renames mojority to approvalThreshold.

* GetQuorumFromAttributes handles VOCEmergencyQuorum

* Adds cycle parameter to listgovproposals

Remove unnecessary atributes of prop object
Rename Majority->ApprovalThreshold

* Clean tests, fix quorum value checking

* Adds cycle to listgovvotes

* Fix lint error

* Add param checks for cycle in listgovvote

* Remove unnided param cycle from client.cpp to fix lint

* Adds functional test

* Renames listgovvotes to listgovproposalvotes

* Restore cycle check in client.cpp

Co-authored-by: Jouzo <[email protected]>
Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2022
1 parent ff03e48 commit bf6c416
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 103 deletions.
16 changes: 8 additions & 8 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ class CMainParams : public CChainParams {
consensus.vaultCreationFee = 2 * COIN;

consensus.props.cfp.fee = COIN / 100; // 1%
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.cfp.approvalThreshold = 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.voc.approvalThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 130000; // tally votes every 130K blocks

Expand Down Expand Up @@ -446,9 +446,9 @@ class CTestNetParams : public CChainParams {
consensus.vaultCreationFee = 1 * COIN;

consensus.props.cfp.fee = COIN / 100; // 1%
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.cfp.approvalThreshold = 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.voc.approvalThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 70000; // tally votes every 70K blocks

Expand Down Expand Up @@ -650,9 +650,9 @@ class CDevNetParams : public CChainParams {
consensus.vaultCreationFee = 1 * COIN;

consensus.props.cfp.fee = COIN / 100; // 1%
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.cfp.approvalThreshold = 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.voc.approvalThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 100; // tally votes every 1K blocks

Expand Down Expand Up @@ -846,9 +846,9 @@ class CRegTestParams : public CChainParams {
consensus.spv.minConfirmations = 6;

consensus.props.cfp.fee = COIN / 100; // 1%
consensus.props.cfp.majorityThreshold = COIN / 2; // vote pass with over 50% majority
consensus.props.cfp.approvalThreshold = 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.voc.approvalThreshold = 66670000; // vote pass with over 66.67% majority
consensus.props.quorum = COIN / 100; // 1% of the masternodes must vote
consensus.props.votingPeriod = 70; // tally votes every 70 blocks

Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct Params {
struct CPropsParams {
struct CPropsSpecs {
CAmount fee;
CAmount majorityThreshold;
CAmount approvalThreshold;
} cfp, brp, voc;
uint32_t votingPeriod;
CAmount quorum;
Expand Down
17 changes: 11 additions & 6 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ uint32_t CCustomCSView::GetEmergencyPeriodFromAttributes(const CPropType& type)
return attributes->GetValue(VOCKey, uint32_t{8640});
}

CAmount CCustomCSView::GetMajorityFromAttributes(const CPropType& type) const
CAmount CCustomCSView::GetApprovalThresholdFromAttributes(const CPropType& type) const
{
auto attributes = GetAttributes();
assert(attributes);
Expand All @@ -1340,22 +1340,27 @@ CAmount CCustomCSView::GetMajorityFromAttributes(const CPropType& type) const

switch(type) {
case CPropType::CommunityFundProposal:
return attributes->GetValue(CFPKey, Params().GetConsensus().props.cfp.majorityThreshold) / 10000;
return attributes->GetValue(CFPKey, Params().GetConsensus().props.cfp.approvalThreshold) / 10000;
case CPropType::VoteOfConfidence:
return attributes->GetValue(VOCKey, Params().GetConsensus().props.voc.majorityThreshold) / 10000;
return attributes->GetValue(VOCKey, Params().GetConsensus().props.voc.approvalThreshold) / 10000;
}

return 0;
}

CAmount CCustomCSView::GetQuorumFromAttributes() const
CAmount CCustomCSView::GetQuorumFromAttributes(const CPropType& type, bool emergency) const
{
auto attributes = GetAttributes();
assert(attributes);

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

return attributes->GetValue(QuorumKey, Params().GetConsensus().props.quorum);
if (type == CPropType::VoteOfConfidence && emergency) {
return attributes->GetValue(vocEmergencyQuorumKey, COIN / 10) / 10000;
}

return attributes->GetValue(quorumKey, Params().GetConsensus().props.quorum) / 10000;
}

CAmount CCustomCSView::GetFeeBurnPctFromAttributes() const
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ class CCustomCSView

uint32_t GetVotingPeriodFromAttributes() const override;
uint32_t GetEmergencyPeriodFromAttributes(const CPropType& type) const override;
CAmount GetMajorityFromAttributes(const CPropType& type) const override;
CAmount GetQuorumFromAttributes() const override;
CAmount GetApprovalThresholdFromAttributes(const CPropType& type) const override;
CAmount GetQuorumFromAttributes(const CPropType& type, bool emergency = false) const override;
CAmount GetFeeBurnPctFromAttributes() const override;

struct DbVersion { static constexpr uint8_t prefix() { return 'D'; } };
Expand Down
2 changes: 0 additions & 2 deletions src/masternodes/proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ 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.quorum = GetQuorumFromAttributes();
prop.fee = fee;
prop.feeBurnAmount = MultiplyAmounts(fee, GetFeeBurnPctFromAttributes());

Expand Down
9 changes: 2 additions & 7 deletions src/masternodes/proposals.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,9 @@ struct CPropObject : public CCreatePropMessage {
uint32_t proposalEndHeight{};

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


// memory only
CPropStatusType status{};
uint8_t cycle{};
Expand All @@ -114,8 +111,6 @@ struct CPropObject : public CCreatePropMessage {
READWRITE(creationHeight);
READWRITE(proposalEndHeight);
READWRITE(votingPeriod);
READWRITE(majority);
READWRITE(quorum);
READWRITE(fee);
READWRITE(feeBurnAmount);
}
Expand Down Expand Up @@ -155,8 +150,8 @@ 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 GetQuorumFromAttributes() const = 0;
virtual CAmount GetApprovalThresholdFromAttributes(const CPropType& type) const = 0;
virtual CAmount GetQuorumFromAttributes(const CPropType& type, bool emergency = false) const = 0;
virtual CAmount GetFeeBurnPctFromAttributes() const = 0;

struct ByType { static constexpr uint8_t prefix() { return 0x2B; } };
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_customtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class CCustomTxRpcVisitor
if (auto prop = mnview.GetProp(propId)) {
proposalEndHeight = prop->proposalEndHeight;
} else {
auto votingPeriod = (emergency ? mnview.GetEmergencyPeriodFromAttributes(type) : mnview.GetVotingPeriodFromAttributes());
auto votingPeriod = prop->votingPeriod;
proposalEndHeight = height + (votingPeriod - height % votingPeriod);
for (uint8_t i = 1; i <= obj.nCycles; ++i) {
proposalEndHeight += votingPeriod;
Expand Down
Loading

0 comments on commit bf6c416

Please sign in to comment.