Skip to content

Commit

Permalink
Refactor proposals related nomenclature (#1687)
Browse files Browse the repository at this point in the history
* Rename `prop` to `proposals`

* Update rpc_proposals.cpp

* Rename iterateProps

Co-authored-by: Mihailo Milenkovic <[email protected]>
Co-authored-by: Peter John Bushnell <[email protected]>
  • Loading branch information
3 people authored Jan 16, 2023
1 parent a4623ee commit 0989ff6
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 217 deletions.
6 changes: 3 additions & 3 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ struct Params {

CAmount vaultCreationFee;

struct CPropsParams {
struct CPropsSpecs {
struct CProposalParams {
struct CProposalSpecs {
CAmount fee;
CAmount minimumFee;
CAmount emergencyFee;
Expand All @@ -218,7 +218,7 @@ struct Params {
CAmount quorum;
CAmount feeBurnPct;
};
CPropsParams props;
CProposalParams props;

std::map<CommunityAccountType, CAmount> nonUtxoBlockSubsidies;
std::map<CommunityAccountType, uint32_t> newNonUTXOSubsidies;
Expand Down
24 changes: 12 additions & 12 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,26 @@ CAmount GetTokenCreationFee(int) {
return Params().GetConsensus().token.creationFee;
}

CAmount GetPropsCreationFee(int, const CCustomCSView &view, const CCreatePropMessage &msg) {
auto type = static_cast<CPropType>(msg.type);
auto options = static_cast<CPropOption>(msg.options);
CAmount GetProposalCreationFee(int, const CCustomCSView &view, const CCreateProposalMessage &msg) {
auto type = static_cast<CProposalType>(msg.type);
auto options = static_cast<CProposalOption>(msg.options);
auto attributes = view.GetAttributes();
assert(attributes);

CDataStructureV0 CFPKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPFee};
CDataStructureV0 VOCKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCFee};
CDataStructureV0 VOCEmergencyKey{
AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCEmergencyFee};
bool emergency = (options & CPropOption::Emergency);
bool emergency = (options & CProposalOption::Emergency);

CAmount cfpFee;
switch (type) {
case CPropType::CommunityFundProposal: {
case CProposalType::CommunityFundProposal: {
cfpFee = MultiplyAmounts(msg.nAmount, attributes->GetValue(CFPKey, Params().GetConsensus().props.cfp.fee));
auto minimumFee = Params().GetConsensus().props.cfp.minimumFee;
return minimumFee > cfpFee ? minimumFee : cfpFee;
}
case CPropType::VoteOfConfidence:
case CProposalType::VoteOfConfidence:
if (emergency)
return attributes->GetValue(VOCEmergencyKey, Params().GetConsensus().props.voc.emergencyFee);
else
Expand Down Expand Up @@ -1282,40 +1282,40 @@ uint32_t CCustomCSView::GetVotingPeriodFromAttributes() const {
return attributes->GetValue(votingKey, Params().GetConsensus().props.votingPeriod);
}

uint32_t CCustomCSView::GetEmergencyPeriodFromAttributes(const CPropType &type) const {
uint32_t CCustomCSView::GetEmergencyPeriodFromAttributes(const CProposalType &type) const {
auto attributes = GetAttributes();
assert(attributes);

CDataStructureV0 VOCKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCEmergencyPeriod};
return attributes->GetValue(VOCKey, Params().GetConsensus().props.emergencyPeriod);
}

CAmount CCustomCSView::GetApprovalThresholdFromAttributes(const CPropType &type) const {
CAmount CCustomCSView::GetApprovalThresholdFromAttributes(const CProposalType &type) const {
auto attributes = GetAttributes();
assert(attributes);

CDataStructureV0 CFPKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPApprovalThreshold};
CDataStructureV0 VOCKey{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::VOCApprovalThreshold};

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

return 0;
}

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

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

if (type == CPropType::VoteOfConfidence && emergency) {
if (type == CProposalType::VoteOfConfidence && emergency) {
return attributes->GetValue(vocEmergencyQuorumKey, COIN / 10) / 10000;
}

Expand Down
12 changes: 6 additions & 6 deletions src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CAmount GetTokenCollateralAmount();
CAmount GetMnCreationFee(int height);
CAmount GetTokenCreationFee(int height);
CAmount GetMnCollateralAmount(int height);
CAmount GetPropsCreationFee(int height, const CCustomCSView &view, const CCreatePropMessage &msg);
CAmount GetProposalCreationFee(int height, const CCustomCSView &view, const CCreateProposalMessage &msg);

enum class UpdateMasternodeType : uint8_t {
None = 0x00,
Expand Down Expand Up @@ -435,7 +435,7 @@ class CCustomCSView : public CMasternodesView,
public CLoanView,
public CVaultView,
public CSettingsView,
public CPropsView {
public CProposalView {
// clang-format off
void CheckPrefixes()
{
Expand Down Expand Up @@ -467,7 +467,7 @@ class CCustomCSView : public CMasternodesView,
LoanInterestV3ByVault,
CVaultView :: VaultKey, OwnerVaultKey, CollateralKey, AuctionBatchKey, AuctionHeightKey, AuctionBidKey,
CSettingsView :: KVSettings,
CPropsView :: ByType, ByCycle, ByMnVote, ByStatus
CProposalView :: ByType, ByCycle, ByMnVote, ByStatus
>();
}
// clang-format on
Expand Down Expand Up @@ -559,9 +559,9 @@ class CCustomCSView : public CMasternodesView,
void SetVaultHistoryStore();

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

struct DbVersion {
Expand Down
56 changes: 28 additions & 28 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ CCustomTxMessage customTypeToMessage(CustomTxType txType) {
case CustomTxType::Reject:
return CCustomTxMessageNone{};
case CustomTxType::CreateCfp:
return CCreatePropMessage{};
return CCreateProposalMessage{};
case CustomTxType::CreateVoc:
return CCreatePropMessage{};
return CCreateProposalMessage{};
case CustomTxType::Vote:
return CPropVoteMessage{};
return CProposalVoteMessage{};
case CustomTxType::ProposalFeeRedistribution:
return CCustomTxMessageNone{};
case CustomTxType::UnsetGovVariable:
Expand Down Expand Up @@ -418,8 +418,8 @@ class CCustomMetadataParseVisitor {
else if constexpr (IsOneOf<T,
CUpdateMasterNodeMessage,
CBurnTokensMessage,
CCreatePropMessage,
CPropVoteMessage,
CCreateProposalMessage,
CProposalVoteMessage,
CGovernanceUnsetMessage>())
return IsHardforkEnabled(consensus.GrandCentralHeight);
else if constexpr (IsOneOf<T,
Expand Down Expand Up @@ -532,8 +532,8 @@ Res CCustomTxVisitor::CheckCustomTx() const {
return Res::Ok();
}

Res CCustomTxVisitor::CheckProposalTx(const CCreatePropMessage &msg) const {
if (tx.vout[0].nValue != GetPropsCreationFee(height, mnview, msg) || tx.vout[0].nTokenId != DCT_ID{0})
Res CCustomTxVisitor::CheckProposalTx(const CCreateProposalMessage &msg) const {
if (tx.vout[0].nValue != GetProposalCreationFee(height, mnview, msg) || tx.vout[0].nTokenId != DCT_ID{0})
return Res::Err("malformed tx vouts (wrong creation fee)");

return Res::Ok();
Expand Down Expand Up @@ -3639,26 +3639,26 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
return mnview.StoreAuctionBid({obj.vaultId, obj.index}, {obj.from, obj.amount});
}

Res operator()(const CCreatePropMessage &obj) const {
Res operator()(const CCreateProposalMessage &obj) const {
auto res = IsOnChainGovernanceEnabled();
if (!res) {
return res;
}

switch (obj.type) {
case CPropType::CommunityFundProposal:
case CProposalType::CommunityFundProposal:
if (!HasAuth(obj.address))
return Res::Err("tx must have at least one input from proposal account");
break;

case CPropType::VoteOfConfidence:
case CProposalType::VoteOfConfidence:
if (obj.nAmount != 0)
return Res::Err("proposal amount in vote of confidence");

if (!obj.address.empty())
return Res::Err("vote of confidence address should be empty");

if (!(obj.options & CPropOption::Emergency) && obj.nCycles != VOC_CYCLES)
if (!(obj.options & CProposalOption::Emergency) && obj.nCycles != VOC_CYCLES)
return Res::Err("proposal cycles should be %d", int(VOC_CYCLES));
break;

Expand All @@ -3676,17 +3676,17 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
if (obj.title.empty())
return Res::Err("proposal title must not be empty");

if (obj.title.size() > MAX_PROP_TITLE_SIZE)
return Res::Err("proposal title cannot be more than %d bytes", MAX_PROP_TITLE_SIZE);
if (obj.title.size() > MAX_PROPOSAL_TITLE_SIZE)
return Res::Err("proposal title cannot be more than %d bytes", MAX_PROPOSAL_TITLE_SIZE);

if (obj.context.empty())
return Res::Err("proposal context must not be empty");

if (obj.context.size() > MAX_PROP_CONTEXT_SIZE)
return Res::Err("proposal context cannot be more than %d bytes", MAX_PROP_CONTEXT_SIZE);
if (obj.context.size() > MAX_PROPOSAL_CONTEXT_SIZE)
return Res::Err("proposal context cannot be more than %d bytes", MAX_PROPOSAL_CONTEXT_SIZE);

if (obj.contextHash.size() > MAX_PROP_CONTEXT_SIZE)
return Res::Err("proposal context hash cannot be more than %d bytes", MAX_PROP_CONTEXT_SIZE);
if (obj.contextHash.size() > MAX_PROPOSAL_CONTEXT_SIZE)
return Res::Err("proposal context hash cannot be more than %d bytes", MAX_PROPOSAL_CONTEXT_SIZE);

auto attributes = mnview.GetAttributes();
assert(attributes);
Expand All @@ -3696,30 +3696,30 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
if (obj.nCycles < 1 || obj.nCycles > maxCycles )
return Res::Err("proposal cycles can be between 1 and %d", maxCycles);

if ((obj.options & CPropOption::Emergency)) {
if ((obj.options & CProposalOption::Emergency)) {
if (obj.nCycles != 1) {
return Res::Err("emergency proposal cycles must be 1");
}

if (static_cast<CPropType>(obj.type) != CPropType::VoteOfConfidence) {
if (static_cast<CProposalType>(obj.type) != CProposalType::VoteOfConfidence) {
return Res::Err("only vote of confidence allowed with emergency option");
}
}

return mnview.CreateProp(tx.GetHash(), height, obj, tx.vout[0].nValue);
return mnview.CreateProposal(tx.GetHash(), height, obj, tx.vout[0].nValue);
}

Res operator()(const CPropVoteMessage &obj) const {
Res operator()(const CProposalVoteMessage &obj) const {
auto res = IsOnChainGovernanceEnabled();
if (!res) {
return res;
}

auto prop = mnview.GetProp(obj.propId);
auto prop = mnview.GetProposal(obj.propId);
if (!prop)
return Res::Err("proposal <%s> does not exist", obj.propId.GetHex());

if (prop->status != CPropStatusType::Voting)
if (prop->status != CProposalStatusType::Voting)
return Res::Err("proposal <%s> is not in voting period", obj.propId.GetHex());

auto node = mnview.GetMasternode(obj.masternodeId);
Expand All @@ -3739,15 +3739,15 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
return Res::Err("masternode <%s> does not mine at least one block", obj.masternodeId.GetHex());

switch (obj.vote) {
case CPropVoteType::VoteNo:
case CPropVoteType::VoteYes:
case CPropVoteType::VoteNeutral:
case CProposalVoteType::VoteNo:
case CProposalVoteType::VoteYes:
case CProposalVoteType::VoteNeutral:
break;
default:
return Res::Err("unsupported vote type");
}
auto vote = static_cast<CPropVoteType>(obj.vote);
return mnview.AddPropVote(obj.propId, obj.masternodeId, vote);
auto vote = static_cast<CProposalVoteType>(obj.vote);
return mnview.AddProposalVote(obj.propId, obj.masternodeId, vote);
}

Res operator()(const CCustomTxMessageNone &) const { return Res::Ok(); }
Expand Down
6 changes: 3 additions & 3 deletions src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CCustomTxVisitor {
Res HasCollateralAuth(const uint256 &collateralTx) const;
Res HasFoundationAuth() const;
Res CheckMasternodeCreationTx() const;
Res CheckProposalTx(const CCreatePropMessage &msg) const;
Res CheckProposalTx(const CCreateProposalMessage &msg) const;
Res CheckTokenCreationTx() const;
Res CheckCustomTx() const;
Res TransferTokenBalance(DCT_ID id, CAmount amount, const CScript &from, const CScript &to) const;
Expand Down Expand Up @@ -445,8 +445,8 @@ using CCustomTxMessage = std::variant<CCustomTxMessageNone,
CLoanPaybackLoanMessage,
CLoanPaybackLoanV2Message,
CAuctionBidMessage,
CCreatePropMessage,
CPropVoteMessage>;
CCreateProposalMessage,
CProposalVoteMessage>;

CCustomTxMessage customTypeToMessage(CustomTxType txType);
bool IsMempooledCustomTxCreate(const CTxMemPool &pool, const uint256 &txid);
Expand Down
Loading

0 comments on commit 0989ff6

Please sign in to comment.