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

Refactor proposals related nomenclature #1634

Closed
wants to merge 4 commits into from
Closed
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
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/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ enum DFIPKeys : uint8_t {
};

enum GovernanceKeys : uint8_t {
FeeRedistribution = 'a',
FeeBurnPct = 'b',
CFPFee = 'd',
CFPApprovalThreshold = 'e',
VOCFee = 'f',
VOCEmergencyFee = 'g',
VOCEmergencyPeriod = 'h',
VOCApprovalThreshold = 'i',
Quorum = 'j',
VotingPeriod = 'k',
VOCEmergencyQuorum = 'l',
CFPMaxCycles = 'm',
FeeRedistribution = 'a',
FeeBurnPct = 'b',
CFPFee = 'd',
CFPApprovalThreshold = 'e',
VOCFee = 'f',
VOCEmergencyFee = 'g',
VOCEmergencyPeriod = 'h',
VOCApprovalThreshold = 'i',
Quorum = 'j',
VotingPeriod = 'k',
VOCEmergencyQuorum = 'l',
CFPMaxCycles = 'm',
};

enum TokenKeys : uint8_t {
Expand Down
25 changes: 12 additions & 13 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +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::CommunityFund: {
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 @@ -1303,40 +1302,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::CommunityFund:
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
55 changes: 28 additions & 27 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,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 @@ -706,12 +706,12 @@ class CCustomMetadataParseVisitor {
return !res ? res : serialize(obj);
}

Res operator()(CCreatePropMessage &obj) const {
Res operator()(CCreateProposalMessage &obj) const {
auto res = isPostGrandCentralFork();
return !res ? res : serialize(obj);
}

Res operator()(CPropVoteMessage &obj) const {
Res operator()(CProposalVoteMessage &obj) const {
auto res = isPostGrandCentralFork();
return !res ? res : serialize(obj);
}
Expand Down Expand Up @@ -801,8 +801,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 @@ -2865,8 +2865,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
// maker bonus only on fair dBTC/BTC (1:1) trades for now
DCT_ID BTC = FindTokenByPartialSymbolName(CICXOrder::TOKEN_BTC);
if (order->idToken == BTC && order->orderPrice == COIN) {
if ((IsTestNetwork() && height >= 1250000) ||
Params().NetworkIDString() == CBaseChainParams::REGTEST) {
if ((IsTestNetwork() && height >= 1250000) || Params().NetworkIDString() == CBaseChainParams::REGTEST) {
res = TransferTokenBalance(DCT_ID{0}, offer->takerFee * 50 / 100, CScript(), order->ownerAddress);
} else {
res = TransferTokenBalance(BTC, offer->takerFee * 50 / 100, CScript(), order->ownerAddress);
Expand Down Expand Up @@ -4398,26 +4397,26 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
return !res ? res : 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::CommunityFund:
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 Down Expand Up @@ -4449,36 +4448,37 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {

auto attributes = mnview.GetAttributes();
assert(attributes);
CDataStructureV0 cfpMaxCycles{AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPMaxCycles};
CDataStructureV0 cfpMaxCycles{
AttributeTypes::Governance, GovernanceIDs::Proposals, GovernanceKeys::CFPMaxCycles};
auto maxCycles = attributes->GetValue(cfpMaxCycles, static_cast<uint32_t>(MAX_CYCLES));

if (obj.nCycles < 1 || obj.nCycles > maxCycles )
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 @@ -4498,15 +4498,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 Expand Up @@ -5546,5 +5546,6 @@ Res storeGovVars(const CGovernanceHeightMessage &obj, CCustomCSView &view) {
}

bool IsTestNetwork() {
return Params().NetworkIDString() == CBaseChainParams::TESTNET || Params().NetworkIDString() == CBaseChainParams::DEVNET;
return Params().NetworkIDString() == CBaseChainParams::TESTNET ||
Params().NetworkIDString() == CBaseChainParams::DEVNET;
}
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 @@ -432,8 +432,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