Skip to content

Commit

Permalink
feat: add governance config fields to global params proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
devwckd committed Jan 8, 2025
1 parent 429277f commit c6b51f4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
1 change: 1 addition & 0 deletions pallets/governance/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ benchmarks! {
min_staking_fee: 1,
dividends_participation_weight: Percent::zero(),
proposal_cost: 0,
..Default::default()
};
let data = vec![0];

Expand Down
8 changes: 4 additions & 4 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ pub mod pallet {
#[pallet::constant]
type MaxApplicationDataLength: Get<u32>;

#[pallet::constant]
#[pallet::no_default_bounds]
type ApplicationExpiration: Get<BlockNumberFor<Self>>;

#[pallet::constant]
type MaxPenaltyPercentage: Get<Percent>;

Expand Down Expand Up @@ -492,6 +488,10 @@ pub mod pallet {
InvalidMinStakingFee,
/// Invalid params given to Emission proposal
InvalidEmissionProposalData,
/// Invalid proposal reward interval given to global params proposal
InvalidProposalRewardInterval,
/// Invalid agent application cost given to global params proposal
InvalidAgentApplicationCost,
}
}

Expand Down
58 changes: 54 additions & 4 deletions pallets/governance/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::config::GovernanceConfiguration;
use crate::frame::traits::ExistenceRequirement;
use crate::BlockAmount;

Check failure on line 3 in pallets/governance/src/proposal.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `crate::BlockAmount`

error[E0432]: unresolved import `crate::BlockAmount` --> pallets/governance/src/proposal.rs:3:5 | 3 | use crate::BlockAmount; | ^^^^^^^^^^^^^^^^^^ no `BlockAmount` in the root
use crate::BoundedBTreeSet;
use crate::BoundedVec;
use crate::DebugNoBound;
use crate::NotDelegatingVotingPower;
use crate::TypeInfo;
use crate::{
AccountIdOf, BalanceOf, DaoTreasuryAddress, Error, GlobalGovernanceConfig, Proposals,
UnrewardedProposals,
};
use crate::{GovernanceConfiguration, NotDelegatingVotingPower};
use codec::{Decode, Encode, MaxEncodedLen};
use polkadot_sdk::frame_election_provider_support::Get;
use polkadot_sdk::frame_support::traits::Currency;
Expand Down Expand Up @@ -98,6 +100,12 @@ impl<T: crate::Config> Proposal<T> {
min_staking_fee,
dividends_participation_weight,
proposal_cost,
proposal_expiration,
agent_application_cost,
agent_application_expiration,
proposal_reward_treasury_allocation,
max_proposal_reward_treasury_allocation,
proposal_reward_interval,
} = data;

pallet_torus0::MinNameLength::<T>::set(min_name_length);
Expand All @@ -113,8 +121,15 @@ impl<T: crate::Config> Proposal<T> {
});
pallet_emission0::MaxAllowedWeights::<T>::set(max_allowed_weights);
pallet_emission0::MinStakePerWeight::<T>::set(min_stake_per_weight);
crate::GlobalGovernanceConfig::<T>::mutate(|config| {
config.proposal_cost = proposal_cost;

crate::GlobalGovernanceConfig::<T>::set(GovernanceConfiguration::<T> {
proposal_cost,
proposal_expiration,
agent_application_cost,
agent_application_expiration,
proposal_reward_treasury_allocation,
max_proposal_reward_treasury_allocation,
proposal_reward_interval,
});
}
ProposalData::TransferDaoTreasury { account, amount } => {
Expand Down Expand Up @@ -205,6 +220,12 @@ pub struct GlobalParamsData<T: crate::Config> {
pub min_staking_fee: u8,
pub dividends_participation_weight: Percent,
pub proposal_cost: BalanceOf<T>,
pub proposal_expiration: BlockAmount,
pub agent_application_cost: BalanceOf<T>,
pub agent_application_expiration: BlockAmount,
pub proposal_reward_treasury_allocation: Percent,
pub max_proposal_reward_treasury_allocation: BalanceOf<T>,
pub proposal_reward_interval: BlockAmount,
}

impl<T: crate::Config> Default for GlobalParamsData<T> {
Expand All @@ -220,6 +241,13 @@ impl<T: crate::Config> Default for GlobalParamsData<T> {
dividends_participation_weight:
<T as pallet_torus0::Config>::DefaultDividendsParticipationWeight::get(),
proposal_cost: T::DefaultProposalCost::get(),
proposal_expiration: T::DefaultProposalExpiration::get(),
agent_application_cost: T::DefaultAgentApplicationCost::get(),
agent_application_expiration: T::DefaultAgentApplicationExpiration::get(),
proposal_reward_treasury_allocation: T::DefaultProposalRewardTreasuryAllocation::get(),
max_proposal_reward_treasury_allocation:
T::DefaultMaxProposalRewardTreasuryAllocation::get(),
proposal_reward_interval: T::DefaultProposalRewardInterval::get(),
}
}
}
Expand Down Expand Up @@ -261,6 +289,21 @@ impl<T: crate::Config> GlobalParamsData<T> {
crate::Error::<T>::InvalidProposalCost
);

ensure!(
(5_400..u64::MAX).contains(&self.proposal_expiration),
crate::Error::<T>::InvalidProposalExpiration
);

ensure!(
self.agent_application_cost <= 100_000_000_000_000_000_000_000,
crate::Error::<T>::InvalidAgentApplicationCost
);

ensure!(
self.proposal_reward_interval <= 100_000,
crate::Error::<T>::InvalidProposalRewardInterval
);

Ok(())
}
}
Expand Down Expand Up @@ -385,10 +428,17 @@ fn add_proposal<T: crate::Config>(

let current_block = <polkadot_sdk::frame_system::Pallet<T>>::block_number();

let expiration_block = match &data {
ProposalData::Emission { .. } => {
(current_block + 21_600).max(current_block + config.proposal_expiration)

Check failure on line 433 in pallets/governance/src/proposal.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> pallets/governance/src/proposal.rs:433:30 | 433 | (current_block + 21_600).max(current_block + config.proposal_expiration) | ------------- ^^^^^^ expected associated type, found integer | | | expected because this is `<<<T as polkadot_sdk::frame_system::Config>::Block as polkadot_sdk::polkadot_sdk_frame::traits::Block>::Header as polkadot_sdk::polkadot_sdk_frame::traits::Header>::Number` | = note: expected associated type `<<<T as polkadot_sdk::frame_system::Config>::Block as polkadot_sdk::polkadot_sdk_frame::traits::Block>::Header as polkadot_sdk::polkadot_sdk_frame::traits::Header>::Number` found type `{integer}` = help: consider constraining the associated type `<<<T as polkadot_sdk::frame_system::Config>::Block as polkadot_sdk::polkadot_sdk_frame::traits::Block>::Header as polkadot_sdk::polkadot_sdk_frame::traits::Header>::Number` to `{integer}` or calling a method that returns `<<<T as polkadot_sdk::frame_system::Config>::Block as polkadot_sdk::polkadot_sdk_frame::traits::Block>::Header as polkadot_sdk::polkadot_sdk_frame::traits::Header>::Number` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
}
_ => current_block + config.proposal_expiration,
};

let proposal = Proposal::<T> {
id: proposal_id,
proposer,
expiration_block: current_block + config.proposal_expiration,
expiration_block,
data,
status: ProposalStatus::Open {
votes_for: BoundedBTreeSet::new(),
Expand Down
2 changes: 0 additions & 2 deletions runtime/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ impl pallet_governance::Config for Runtime {

type MaxApplicationDataLength = ConstU32<256>;

type ApplicationExpiration = ConstU64<2000>;

type MaxPenaltyPercentage = MaxPenaltyPercentage;

type DefaultTreasuryEmissionFee = DefaultTreasuryEmissionFee;
Expand Down
2 changes: 0 additions & 2 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ impl pallet_governance::Config for Test {

type MaxApplicationDataLength = ConstU32<256>;

type ApplicationExpiration = ConstU64<2000>;

type MaxPenaltyPercentage = MaxPenaltyPercentage;

type DefaultTreasuryEmissionFee = DefaultTreasuryEmissionFee;
Expand Down

0 comments on commit c6b51f4

Please sign in to comment.