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

Add fields to getgovproposal #1583

Merged
merged 30 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8dcc5b6
Renames contexthash->currentHash
dcorral Nov 17, 2022
c3e28c7
Renames nextCycle->currentCycle
dcorral Nov 17, 2022
ba19e76
Renames finalizeAfter->endHeight
dcorral Nov 17, 2022
c2503e8
Fixes typo currentHash->contextHash
dcorral Nov 17, 2022
b9d4ae5
Renames endHeight->proposalEndHeight
dcorral Nov 17, 2022
ae8eea7
Merge branch 'master' of github.com:DeFiCh/ain into fix/proposal-govv…
dcorral Nov 17, 2022
7e2f1bb
Adds cycleEndHeight to listgovproposals
dcorral Nov 17, 2022
4304202
Fix lint error remove unnecessary include
dcorral Nov 17, 2022
ce747ec
Merge branch 'master' into fix/proposal-govvar-changes
dcorral Nov 17, 2022
b633c4b
Update test/functional/feature_on_chain_government.py
dcorral Nov 17, 2022
8542986
Update src/masternodes/proposals.cpp
dcorral Nov 17, 2022
68e5ed9
Rename approval->votes and fix tests
dcorral Nov 17, 2022
882818f
Merge branch 'master' into fix/proposal-govvar-changes
prasannavl Nov 17, 2022
ff7ce75
Merge branch 'master' into fix/proposal-govvar-changes
prasannavl Nov 17, 2022
15863f7
Add missing fields in getgovproposal and remove ends fields
dcorral Nov 17, 2022
2ba97a8
Add missing fields to getgovproposal
dcorral Nov 17, 2022
da44b74
Merge branch 'master' into fix/add-fields-getgovproposal
dcorral Nov 17, 2022
0683181
Use approvalThreshold and quorum from attributes
dcorral Nov 21, 2022
46371b0
Merge branch 'master' into fix/add-fields-getgovproposal
dcorral Nov 21, 2022
c35ca96
GetQuorumFromAttributes handles VOCEmergencyQuorum
Jouzo Nov 21, 2022
39723b6
Adds cycle parameter to listgovproposals
dcorral Nov 21, 2022
8fff643
Clean tests, fix quorum value checking
dcorral Nov 22, 2022
4c339fe
Adds cycle to listgovvotes
dcorral Nov 22, 2022
89373e2
Fix lint error
dcorral Nov 22, 2022
4bf2935
Add param checks for cycle in listgovvote
dcorral Nov 22, 2022
ebfdb2c
Merge branch 'master' into fix/add-fields-getgovproposal
prasannavl Nov 22, 2022
f47700e
Remove unnided param cycle from client.cpp to fix lint
dcorral Nov 22, 2022
0f9b64c
Adds functional test
dcorral Nov 22, 2022
8d71edb
Renames listgovvotes to listgovproposalvotes
dcorral Nov 22, 2022
cc8e476
Restore cycle check in client.cpp
dcorral Nov 22, 2022
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
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 @@ -443,9 +443,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 @@ -644,9 +644,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 @@ -837,9 +837,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 @@ -206,7 +206,7 @@ struct Params {
struct CPropsParams {
struct CPropsSpecs {
CAmount fee;
CAmount majorityThreshold;
CAmount approvalThreshold;
} cfp, brp, voc;
uint32_t votingPeriod;
CAmount quorum;
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,9 +1340,9 @@ 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;
Expand Down
53 changes: 37 additions & 16 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@

#include <functional>

UniValue propToJSON(CPropId const& propId, CPropObject const& prop)
UniValue propToJSON(CPropId const& propId, CPropObject const& prop, CCustomCSView const& view)
{
CDataStructureV0 cfpMajority{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPMajority};
CDataStructureV0 vocMajority{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCMajority};
CDataStructureV0 quorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::Quorum};

auto attributes = view.GetAttributes();
if (!attributes)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Attributes access failure");
auto quorum = attributes->GetValue(quorumKey, Params().GetConsensus().props.quorum);

uint32_t approvalThreshold{0};
switch(prop.type) {
case CPropType::CommunityFundProposal:
approvalThreshold = attributes->GetValue(cfpMajority, Params().GetConsensus().props.cfp.approvalThreshold) / 10000;
break;
case CPropType::VoteOfConfidence:
approvalThreshold = attributes->GetValue(vocMajority, Params().GetConsensus().props.voc.approvalThreshold) / 10000;
break;
}

Jouzo marked this conversation as resolved.
Show resolved Hide resolved
UniValue ret(UniValue::VOBJ);
ret.pushKV("proposalId", propId.GetHex());
ret.pushKV("title", prop.title);
Expand All @@ -21,8 +40,8 @@ UniValue propToJSON(CPropId const& propId, CPropObject const& prop)
ret.pushKV("proposalEndHeight", static_cast<int32_t>(prop.proposalEndHeight));
ret.pushKV("payoutAddress", ScriptToString(prop.address));
ret.pushKV("votingPeriod", static_cast<int32_t>(prop.votingPeriod));
ret.pushKV("majority", strprintf("%d.%02d%%", prop.majority / 100, prop.majority % 100));
ret.pushKV("quorum", strprintf("%d.%02d%%", prop.quorum / 10000, prop.quorum % 10000));
ret.pushKV("approvalThreshold", strprintf("%d.%02d%%", approvalThreshold / 100, approvalThreshold % 100));
ret.pushKV("quorum", strprintf("%d.%02d%%", quorum / 10000, quorum % 10000));
ret.pushKV("fee", ValueFromAmount(prop.fee));
ret.pushKV("feeBurnAmount", ValueFromAmount(prop.feeBurnAmount));
if (prop.options)
Expand Down Expand Up @@ -495,7 +514,7 @@ UniValue getgovproposal(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Proposal <%s> does not exist", propId.GetHex()));
}
if (prop->status != CPropStatusType::Voting) {
return propToJSON(propId, *prop);
return propToJSON(propId, *prop, view);
}

int targetHeight;
Expand All @@ -514,7 +533,7 @@ UniValue getgovproposal(const JSONRPCRequest& request)
});

if (activeMasternodes.empty()) {
return propToJSON(propId, *prop);
return propToJSON(propId, *prop, view);
}

uint32_t voteYes = 0, voters = 0;
Expand All @@ -532,27 +551,29 @@ UniValue getgovproposal(const JSONRPCRequest& request)
}, CMnVotePerCycle{propId, prop->cycle});

if (!voters) {
return propToJSON(propId, *prop);
return propToJSON(propId, *prop, view);
}

uint32_t majorityThreshold = 0, votes = 0;
uint32_t approvalThreshold = 0, votes = 0;
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 quorumKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::Quorum};

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

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

if (valid) {
switch(prop->type) {
case CPropType::CommunityFundProposal:
majorityThreshold = attributes->GetValue(cfpMajority, Params().GetConsensus().props.cfp.majorityThreshold) / 10000;
approvalThreshold = attributes->GetValue(cfpMajority, Params().GetConsensus().props.cfp.approvalThreshold) / 10000;
break;
case CPropType::VoteOfConfidence:
majorityThreshold = attributes->GetValue(vocMajority, Params().GetConsensus().props.voc.majorityThreshold) / 10000;
approvalThreshold = attributes->GetValue(vocMajority, Params().GetConsensus().props.voc.approvalThreshold) / 10000;
break;
}
votes = lround(voteYes * 10000.f / voters);
Expand All @@ -565,7 +586,7 @@ UniValue getgovproposal(const JSONRPCRequest& request)
ret.pushKV("contextHash", prop->contextHash);
auto type = static_cast<CPropType>(prop->type);
ret.pushKV("type", CPropTypeToString(type));
if (valid && votes >= majorityThreshold) {
if (valid && votes >= approvalThreshold) {
ret.pushKV("status", "Approved");
} else {
ret.pushKV("status", "Rejected");
Expand All @@ -576,8 +597,8 @@ UniValue getgovproposal(const JSONRPCRequest& request)
ret.pushKV("proposalEndHeight", static_cast<int32_t>(prop->proposalEndHeight));
ret.pushKV("payoutAddress", ScriptToString(prop->address));
ret.pushKV("votingPeriod", static_cast<int32_t>(prop->votingPeriod));
ret.pushKV("majority", strprintf("%d.%02d%%", prop->majority / 100, prop->majority % 100));
ret.pushKV("quorum", strprintf("%d.%02d%%", prop->quorum / 10000, prop->quorum % 10000));
ret.pushKV("approvalThreshold", strprintf("%d.%02d%%", approvalThreshold / 100, approvalThreshold % 100));
ret.pushKV("quorum", strprintf("%d.%02d%%", quorum / 10000, quorum % 10000));
ret.pushKV("fee", ValueFromAmount(prop->fee));
ret.pushKV("feeBurnAmount", ValueFromAmount(prop->feeBurnAmount));

Expand All @@ -594,8 +615,8 @@ UniValue getgovproposal(const JSONRPCRequest& request)
ret.pushKV("options", array);
}

ret.pushKV("votes", strprintf("%d.%02d of %d.%02d%%", votes / 100, votes % 100, majorityThreshold / 100, majorityThreshold % 100));
ret.pushKV("votingPercent", strprintf("%d.%02d of %d.%02d%%", allVotes / 100, allVotes % 100, prop->quorum / 10000, prop->quorum % 10000));
ret.pushKV("votes", strprintf("%d.%02d of %d.%02d%%", votes / 100, votes % 100, approvalThreshold / 100, approvalThreshold % 100));
ret.pushKV("votingPercent", strprintf("%d.%02d of %d.%02d%%", allVotes / 100, allVotes % 100, quorum / 10000, quorum % 10000));


return ret;
Expand Down Expand Up @@ -658,7 +679,7 @@ UniValue listgovproposals(const JSONRPCRequest& request)
if (type && type != uint8_t(prop.type)) {
return true;
}
ret.push_back(propToJSON(propId, prop));
ret.push_back(propToJSON(propId, prop, view));
return true;
}, status);

Expand Down
4 changes: 2 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4268,10 +4268,10 @@ void CChainState::ProcessProposalEvents(const CBlockIndex* pindex, CCustomCSView

switch(prop.type) {
case CPropType::CommunityFundProposal:
majorityThreshold = attributes->GetValue(cfpMajority, chainparams.GetConsensus().props.cfp.majorityThreshold) / 10000;
majorityThreshold = attributes->GetValue(cfpMajority, chainparams.GetConsensus().props.cfp.approvalThreshold) / 10000;
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
break;
case CPropType::VoteOfConfidence:
majorityThreshold = attributes->GetValue(vocMajority, chainparams.GetConsensus().props.voc.majorityThreshold) / 10000;
majorityThreshold = attributes->GetValue(vocMajority, chainparams.GetConsensus().props.voc.approvalThreshold) / 10000;
break;
}

Expand Down
Empty file modified test/functional/feature_on_chain_government.py
100644 → 100755
Empty file.