From 8384082a2fdefff6c72e3eaa5b0ade3b20deed7d Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 11 Sep 2024 14:06:20 +0100 Subject: [PATCH 01/19] add randomness deposit param --- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbase/src/runtime_params.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 5e873b73b9..4002c48b8c 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1344,7 +1344,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::dynamic_params::pallet_randomness::Deposit; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 4916cc27df..5821a269f9 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -15,9 +15,9 @@ // along with Moonbeam. If not, see . //! Dynamic runtime parametes. -use crate::Runtime; use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; use sp_runtime::Perbill; +use crate::{Runtime, currency, Balance}; #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] pub mod dynamic_params { @@ -29,6 +29,13 @@ pub mod dynamic_params { #[codec(index = 0)] pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: Balance = 1 * currency::UNIT * currency::SUPPLY_FACTOR; + } } #[cfg(feature = "runtime-benchmarks")] From 89c33f2411f1870122251a000a6e53114182ab2e Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 11 Sep 2024 14:16:04 +0100 Subject: [PATCH 02/19] add test --- runtime/moonbase/src/runtime_params.rs | 2 +- test/suites/dev/moonbase/test-parameters/test-parameters.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 5821a269f9..7d5d9308b0 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -15,9 +15,9 @@ // along with Moonbeam. If not, see . //! Dynamic runtime parametes. +use crate::{currency, Balance, Runtime}; use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; use sp_runtime::Perbill; -use crate::{Runtime, currency, Balance}; #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] pub mod dynamic_params { diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 8ff2b8cd9a..429de74654 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -83,5 +83,6 @@ describeSuite({ } testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); + testParam("PalletRandomness", "Deposit", ["Balance", 1_000_000_000_000_000_000n * 100n]); }, }); From d4cdbd5d5b5b16d7c73ce44765624debb611d5a6 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 17 Sep 2024 10:07:01 +0000 Subject: [PATCH 03/19] add bounded type --- Cargo.lock | 1 + runtime/common/Cargo.toml | 2 + runtime/common/src/lib.rs | 1 + runtime/common/src/types.rs | 114 +++++++++++++++++++++++++ runtime/moonbase/src/lib.rs | 2 +- runtime/moonbase/src/runtime_params.rs | 16 +++- 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 runtime/common/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index 60f774d72d..ba23c72f28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7029,6 +7029,7 @@ dependencies = [ "pallet-xcm-transactor", "parity-scale-codec", "precompile-utils", + "scale-info", "sp-api", "sp-consensus-slots", "sp-core", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 8a9ff1de6b..e55822afb5 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -83,6 +83,7 @@ xcm-fee-payment-runtime-api = { workspace = true } # Parity parity-scale-codec = { workspace = true } +scale-info = { workspace = true } account = { workspace = true } @@ -110,6 +111,7 @@ std = [ "pallet-identity/std", "pallet-message-queue/std", "parity-scale-codec/std", + "scale-info/std", "precompile-utils/std", "sp-consensus-slots/std", "sp-core/std", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 747a8a326b..ccde3fffa5 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -24,6 +24,7 @@ mod impl_self_contained_call; mod impl_xcm_evm_runner; pub mod migrations; pub mod timestamp; +pub mod types; pub mod weights; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs new file mode 100644 index 0000000000..8744ca7bf7 --- /dev/null +++ b/runtime/common/src/types.rs @@ -0,0 +1,114 @@ +use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; +use scale_info::TypeInfo; +use sp_std::prelude::*; + +#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, TypeInfo, MaxEncodedLen)] +#[scale_info(skip_type_params(LOWER, UPPER))] +pub struct BoundedU128(u128); + +impl BoundedU128 { + pub fn new(value: u128) -> Result { + if value < L || value > U { + return Err("Value out of bounds"); + } + Ok(Self(value)) + } + + pub fn new_or_min(value: u128) -> Self { + if value < L || value > U { + Self(L) + } else { + Self(value) + } + } + + pub fn value(&self) -> u128 { + self.0 + } +} + +impl Decode for BoundedU128 { + fn decode( + input: &mut I, + ) -> Result { + let value = u128::decode(input)?; + if value < L || value > U { + return Err("Value out of bounds".into()); + } + Ok(Self(value)) + } +} + +impl EncodeLike for BoundedU128 {} + +#[macro_export] +macro_rules! expose_u128_get { + ($name:ident,$bounded_get:ty) => { + pub struct $name; + + impl sp_core::Get for $name { + fn get() -> u128 { + <$bounded_get>::get().value() + } + } + }; +} + +#[cfg(test)] +mod tests { + use frame_support::parameter_types; + use sp_core::Get; + + use super::*; + + #[test] + fn test_bounded_u128() { + let bounded = BoundedU128::<1, 10>::new(5).unwrap(); + assert_eq!(bounded.value(), 5); + + let bounded = BoundedU128::<1, 10>::new(0); + assert_eq!(bounded, Err("Value out of bounds")); + + let bounded = BoundedU128::<1, 10>::new(11); + assert_eq!(bounded, Err("Value out of bounds")); + + let bounded = BoundedU128::<1, 10>::new_or_min(0); + assert_eq!(bounded.value(), 1); + + let bounded = BoundedU128::<1, 10>::new_or_min(5); + assert_eq!(bounded.value(), 5); + + let bounded = BoundedU128::<1, 10>::new_or_min(11); + assert_eq!(bounded.value(), 1); + } + + #[test] + fn test_expose_u128_get() { + parameter_types! { + pub Bounded: BoundedU128::<1, 10> = BoundedU128::<1, 10>::new(4).unwrap(); + } + expose_u128_get!(Exposed, Bounded); + assert_eq!(Bounded::get().value(), Exposed::get()); + } + + #[test] + fn test_encode_decode() { + let bounded = BoundedU128::<1, 10>::new(5).unwrap(); + let encoded = bounded.encode(); + let decoded = BoundedU128::<1, 10>::decode(&mut &encoded[..]).unwrap(); + assert_eq!(bounded, decoded); + } + + #[test] + fn test_encode_invalid() { + let bounded = BoundedU128::<1, 10>::new(9); + let encoded = bounded.encode(); + let decoded = BoundedU128::<1, 3>::decode(&mut &encoded[..]); + assert_eq!(decoded, Err("Value out of bounds".into())); + + let bounded = BoundedU128::<1, 10>::new(9); + let encoded = bounded.encode(); + let decoded = BoundedU128::<100, 500>::decode(&mut &encoded[..]); + assert_eq!(decoded, Err("Value out of bounds".into())); + } +} diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 4002c48b8c..ad549c2b00 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1344,7 +1344,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = runtime_params::dynamic_params::pallet_randomness::Deposit; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 7d5d9308b0..3b77ed98b8 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -15,8 +15,10 @@ // along with Moonbeam. If not, see . //! Dynamic runtime parametes. -use crate::{currency, Balance, Runtime}; +use crate::{currency, Runtime}; use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; use sp_runtime::Perbill; #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] @@ -33,11 +35,21 @@ pub mod dynamic_params { #[dynamic_pallet_params] #[codec(index = 1)] pub mod pallet_randomness { + use sp_core::ConstU128; + #[codec(index = 0)] - pub static Deposit: Balance = 1 * currency::UNIT * currency::SUPPLY_FACTOR; + pub static Deposit: BoundedU128< + { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, + > = BoundedU128::new_or_min(10 * currency::UNIT * currency::SUPPLY_FACTOR); } } +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit +); + #[cfg(feature = "runtime-benchmarks")] impl Default for RuntimeParameters { fn default() -> Self { From 5439c122ed46b5cf7abc34684940e86a73c88878 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 17 Sep 2024 11:55:42 +0000 Subject: [PATCH 04/19] add copyright --- runtime/common/src/types.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 8744ca7bf7..5fc9b9c949 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -1,3 +1,18 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::prelude::*; From e0d04e47ad6e281d3e4417420f883827d91ac996 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Tue, 17 Sep 2024 12:25:34 +0000 Subject: [PATCH 05/19] fix test --- test/suites/dev/moonbase/test-parameters/test-parameters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 429de74654..1148e59d77 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -83,6 +83,6 @@ describeSuite({ } testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); - testParam("PalletRandomness", "Deposit", ["Balance", 1_000_000_000_000_000_000n * 100n]); + testParam("PalletRandomness", "Deposit", ["u128", 1_000_000_000_000_000_000n * 100n]); }, }); From 505a999382c12f415613c3d6f91ccad71f752d05 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Wed, 18 Sep 2024 13:01:27 +0000 Subject: [PATCH 06/19] fix value --- runtime/moonbase/src/runtime_params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 3b77ed98b8..97f390e423 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -41,7 +41,7 @@ pub mod dynamic_params { pub static Deposit: BoundedU128< { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::new_or_min(10 * currency::UNIT * currency::SUPPLY_FACTOR); + > = BoundedU128::new_or_min(1 * currency::UNIT * currency::SUPPLY_FACTOR); } } From 2028a2e32b628189bbe965fa290034df46d6a22c Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 19 Sep 2024 07:19:49 +0000 Subject: [PATCH 07/19] rename --- pallets/parachain-staking/src/benchmarks.rs | 8 ++++---- pallets/parachain-staking/src/lib.rs | 22 ++++++++++----------- pallets/parachain-staking/src/tests.rs | 8 ++++---- pallets/parachain-staking/src/types.rs | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pallets/parachain-staking/src/benchmarks.rs b/pallets/parachain-staking/src/benchmarks.rs index 9be9170173..c8ca765055 100644 --- a/pallets/parachain-staking/src/benchmarks.rs +++ b/pallets/parachain-staking/src/benchmarks.rs @@ -19,7 +19,7 @@ //! Benchmarking use crate::{ AwardedPts, BalanceOf, BottomDelegations, Call, CandidateBondLessRequest, Config, - DelegationAction, EnableMarkingOffline, Pallet, ParachainBondConfig, ParachainBondInfo, Points, + DelegationAction, EnableMarkingOffline, Pallet, InflationDistributionConfig, ParachainBondInfo, Points, Range, RewardPayment, Round, ScheduledRequest, TopDelegations, }; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; @@ -280,13 +280,13 @@ benchmarks! { let parachain_bond_account: T::AccountId = account("TEST", 0u32, USER_SEED); }: _(RawOrigin::Root, parachain_bond_account.clone()) verify { - assert_eq!(Pallet::::parachain_bond_info().account, parachain_bond_account); + assert_eq!(Pallet::::inflation_distribution_info().account, parachain_bond_account); } set_parachain_bond_reserve_percent { }: _(RawOrigin::Root, Percent::from_percent(33)) verify { - assert_eq!(Pallet::::parachain_bond_info().percent, Percent::from_percent(33)); + assert_eq!(Pallet::::inflation_distribution_info().percent, Percent::from_percent(33)); } // ROOT DISPATCHABLES @@ -1564,7 +1564,7 @@ benchmarks! { 0, min_candidate_stk::(), ).0; - >::put(ParachainBondConfig { + >::put(InflationDistributionConfig { account, percent: Percent::from_percent(50), }); diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 2e04e79d8c..3123ce0617 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -518,10 +518,10 @@ pub mod pallet { pub(crate) type TotalSelected = StorageValue<_, u32, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn parachain_bond_info)] + #[pallet::getter(fn inflation_distribution_info)] /// Parachain bond config info { account, percent_of_inflation } - pub(crate) type ParachainBondInfo = - StorageValue<_, ParachainBondConfig, ValueQuery>; + pub(crate) type InflationDistributionInfo = + StorageValue<_, InflationDistributionConfig, ValueQuery>; #[pallet::storage] #[pallet::getter(fn round)] @@ -787,7 +787,7 @@ pub mod pallet { // Set collator commission to default config >::put(self.collator_commission); // Set parachain bond config to default config - >::put(ParachainBondConfig { + >::put(InflationDistributionConfig { // must be set soon; if not => due inflation will be sent to collators/delegators account: T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .expect("infinite length input; no invalid inputs for type; qed"), @@ -880,12 +880,12 @@ pub mod pallet { new: T::AccountId, ) -> DispatchResultWithPostInfo { T::MonetaryGovernanceOrigin::ensure_origin(origin)?; - let ParachainBondConfig { + let InflationDistributionConfig { account: old, percent, - } = >::get(); + } = >::get(); ensure!(old != new, Error::::NoWritingSameValue); - >::put(ParachainBondConfig { + >::put(InflationDistributionConfig { account: new.clone(), percent, }); @@ -901,12 +901,12 @@ pub mod pallet { new: Percent, ) -> DispatchResultWithPostInfo { T::MonetaryGovernanceOrigin::ensure_origin(origin)?; - let ParachainBondConfig { + let InflationDistributionConfig { account, percent: old, - } = >::get(); + } = >::get(); ensure!(old != new, Error::::NoWritingSameValue); - >::put(ParachainBondConfig { + >::put(InflationDistributionConfig { account, percent: new, }); @@ -1839,7 +1839,7 @@ pub mod pallet { // reserve portion of issuance for parachain bond account let mut left_issuance = total_issuance; - let bond_config = >::get(); + let bond_config = >::get(); let parachain_bond_reserve = bond_config.percent * total_issuance; if let Ok(imb) = T::Currency::deposit_into_existing(&bond_config.account, parachain_bond_reserve) diff --git a/pallets/parachain-staking/src/tests.rs b/pallets/parachain-staking/src/tests.rs index 0d6ffa6355..1ee6970311 100644 --- a/pallets/parachain-staking/src/tests.rs +++ b/pallets/parachain-staking/src/tests.rs @@ -620,12 +620,12 @@ fn set_parachain_bond_account_event_emits_correctly() { #[test] fn set_parachain_bond_account_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(ParachainStaking::parachain_bond_info().account, 0); + assert_eq!(ParachainStaking::inflation_distribution_info().account, 0); assert_ok!(ParachainStaking::set_parachain_bond_account( RuntimeOrigin::root(), 11 )); - assert_eq!(ParachainStaking::parachain_bond_info().account, 11); + assert_eq!(ParachainStaking::inflation_distribution_info().account, 11); }); } @@ -649,7 +649,7 @@ fn set_parachain_bond_reserve_percent_event_emits_correctly() { fn set_parachain_bond_reserve_percent_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { assert_eq!( - ParachainStaking::parachain_bond_info().percent, + ParachainStaking::inflation_distribution_info().percent, Percent::from_percent(30) ); assert_ok!(ParachainStaking::set_parachain_bond_reserve_percent( @@ -657,7 +657,7 @@ fn set_parachain_bond_reserve_percent_storage_updates_correctly() { Percent::from_percent(50) )); assert_eq!( - ParachainStaking::parachain_bond_info().percent, + ParachainStaking::inflation_distribution_info().percent, Percent::from_percent(50) ); }); diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index d2dcbb292d..0d25d12100 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -1750,15 +1750,15 @@ impl< #[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)] /// Reserve information { account, percent_of_inflation } -pub struct ParachainBondConfig { +pub struct InflationDistributionConfig { /// Account which receives funds intended for parachain bond pub account: AccountId, /// Percent of inflation set aside for parachain bond account pub percent: Percent, } -impl Default for ParachainBondConfig { - fn default() -> ParachainBondConfig { - ParachainBondConfig { +impl Default for InflationDistributionConfig { + fn default() -> InflationDistributionConfig { + InflationDistributionConfig { account: A::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .expect("infinite length input; no invalid inputs for type; qed"), percent: Percent::zero(), From 6bf39b290a1adccd72a9667d9efea26ed3ef3f02 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 19 Sep 2024 07:52:03 +0000 Subject: [PATCH 08/19] Revert "rename" This reverts commit 2028a2e32b628189bbe965fa290034df46d6a22c. --- pallets/parachain-staking/src/benchmarks.rs | 8 ++++---- pallets/parachain-staking/src/lib.rs | 22 ++++++++++----------- pallets/parachain-staking/src/tests.rs | 8 ++++---- pallets/parachain-staking/src/types.rs | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pallets/parachain-staking/src/benchmarks.rs b/pallets/parachain-staking/src/benchmarks.rs index c8ca765055..9be9170173 100644 --- a/pallets/parachain-staking/src/benchmarks.rs +++ b/pallets/parachain-staking/src/benchmarks.rs @@ -19,7 +19,7 @@ //! Benchmarking use crate::{ AwardedPts, BalanceOf, BottomDelegations, Call, CandidateBondLessRequest, Config, - DelegationAction, EnableMarkingOffline, Pallet, InflationDistributionConfig, ParachainBondInfo, Points, + DelegationAction, EnableMarkingOffline, Pallet, ParachainBondConfig, ParachainBondInfo, Points, Range, RewardPayment, Round, ScheduledRequest, TopDelegations, }; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; @@ -280,13 +280,13 @@ benchmarks! { let parachain_bond_account: T::AccountId = account("TEST", 0u32, USER_SEED); }: _(RawOrigin::Root, parachain_bond_account.clone()) verify { - assert_eq!(Pallet::::inflation_distribution_info().account, parachain_bond_account); + assert_eq!(Pallet::::parachain_bond_info().account, parachain_bond_account); } set_parachain_bond_reserve_percent { }: _(RawOrigin::Root, Percent::from_percent(33)) verify { - assert_eq!(Pallet::::inflation_distribution_info().percent, Percent::from_percent(33)); + assert_eq!(Pallet::::parachain_bond_info().percent, Percent::from_percent(33)); } // ROOT DISPATCHABLES @@ -1564,7 +1564,7 @@ benchmarks! { 0, min_candidate_stk::(), ).0; - >::put(InflationDistributionConfig { + >::put(ParachainBondConfig { account, percent: Percent::from_percent(50), }); diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 3123ce0617..2e04e79d8c 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -518,10 +518,10 @@ pub mod pallet { pub(crate) type TotalSelected = StorageValue<_, u32, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn inflation_distribution_info)] + #[pallet::getter(fn parachain_bond_info)] /// Parachain bond config info { account, percent_of_inflation } - pub(crate) type InflationDistributionInfo = - StorageValue<_, InflationDistributionConfig, ValueQuery>; + pub(crate) type ParachainBondInfo = + StorageValue<_, ParachainBondConfig, ValueQuery>; #[pallet::storage] #[pallet::getter(fn round)] @@ -787,7 +787,7 @@ pub mod pallet { // Set collator commission to default config >::put(self.collator_commission); // Set parachain bond config to default config - >::put(InflationDistributionConfig { + >::put(ParachainBondConfig { // must be set soon; if not => due inflation will be sent to collators/delegators account: T::AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .expect("infinite length input; no invalid inputs for type; qed"), @@ -880,12 +880,12 @@ pub mod pallet { new: T::AccountId, ) -> DispatchResultWithPostInfo { T::MonetaryGovernanceOrigin::ensure_origin(origin)?; - let InflationDistributionConfig { + let ParachainBondConfig { account: old, percent, - } = >::get(); + } = >::get(); ensure!(old != new, Error::::NoWritingSameValue); - >::put(InflationDistributionConfig { + >::put(ParachainBondConfig { account: new.clone(), percent, }); @@ -901,12 +901,12 @@ pub mod pallet { new: Percent, ) -> DispatchResultWithPostInfo { T::MonetaryGovernanceOrigin::ensure_origin(origin)?; - let InflationDistributionConfig { + let ParachainBondConfig { account, percent: old, - } = >::get(); + } = >::get(); ensure!(old != new, Error::::NoWritingSameValue); - >::put(InflationDistributionConfig { + >::put(ParachainBondConfig { account, percent: new, }); @@ -1839,7 +1839,7 @@ pub mod pallet { // reserve portion of issuance for parachain bond account let mut left_issuance = total_issuance; - let bond_config = >::get(); + let bond_config = >::get(); let parachain_bond_reserve = bond_config.percent * total_issuance; if let Ok(imb) = T::Currency::deposit_into_existing(&bond_config.account, parachain_bond_reserve) diff --git a/pallets/parachain-staking/src/tests.rs b/pallets/parachain-staking/src/tests.rs index 1ee6970311..0d6ffa6355 100644 --- a/pallets/parachain-staking/src/tests.rs +++ b/pallets/parachain-staking/src/tests.rs @@ -620,12 +620,12 @@ fn set_parachain_bond_account_event_emits_correctly() { #[test] fn set_parachain_bond_account_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(ParachainStaking::inflation_distribution_info().account, 0); + assert_eq!(ParachainStaking::parachain_bond_info().account, 0); assert_ok!(ParachainStaking::set_parachain_bond_account( RuntimeOrigin::root(), 11 )); - assert_eq!(ParachainStaking::inflation_distribution_info().account, 11); + assert_eq!(ParachainStaking::parachain_bond_info().account, 11); }); } @@ -649,7 +649,7 @@ fn set_parachain_bond_reserve_percent_event_emits_correctly() { fn set_parachain_bond_reserve_percent_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { assert_eq!( - ParachainStaking::inflation_distribution_info().percent, + ParachainStaking::parachain_bond_info().percent, Percent::from_percent(30) ); assert_ok!(ParachainStaking::set_parachain_bond_reserve_percent( @@ -657,7 +657,7 @@ fn set_parachain_bond_reserve_percent_storage_updates_correctly() { Percent::from_percent(50) )); assert_eq!( - ParachainStaking::inflation_distribution_info().percent, + ParachainStaking::parachain_bond_info().percent, Percent::from_percent(50) ); }); diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index 0d25d12100..d2dcbb292d 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -1750,15 +1750,15 @@ impl< #[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)] /// Reserve information { account, percent_of_inflation } -pub struct InflationDistributionConfig { +pub struct ParachainBondConfig { /// Account which receives funds intended for parachain bond pub account: AccountId, /// Percent of inflation set aside for parachain bond account pub percent: Percent, } -impl Default for InflationDistributionConfig { - fn default() -> InflationDistributionConfig { - InflationDistributionConfig { +impl Default for ParachainBondConfig { + fn default() -> ParachainBondConfig { + ParachainBondConfig { account: A::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) .expect("infinite length input; no invalid inputs for type; qed"), percent: Percent::zero(), From cd96b7bb2027eff4a7f3efaaf576bd12bf10e8ef Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Mon, 30 Sep 2024 16:46:14 +0000 Subject: [PATCH 09/19] fix min, max, current --- runtime/moonbase/src/runtime_params.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 97f390e423..27af0366d5 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -39,9 +39,9 @@ pub mod dynamic_params { #[codec(index = 0)] pub static Deposit: BoundedU128< - { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 2 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::new_or_min(1 * currency::UNIT * currency::SUPPLY_FACTOR); + > = BoundedU128::new_or_min(100 * currency::UNIT * currency::SUPPLY_FACTOR); } } From cb47b0d5b4d5ca1aea84e14979de660ba31d54ce Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Mon, 30 Sep 2024 18:06:14 +0000 Subject: [PATCH 10/19] fix values --- runtime/moonbase/src/runtime_params.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 27af0366d5..97f390e423 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -39,9 +39,9 @@ pub mod dynamic_params { #[codec(index = 0)] pub static Deposit: BoundedU128< - { 2 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::new_or_min(100 * currency::UNIT * currency::SUPPLY_FACTOR); + > = BoundedU128::new_or_min(1 * currency::UNIT * currency::SUPPLY_FACTOR); } } From 154bd03b07d57e9868998cca92cc980159188c0c Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 11:36:08 +0000 Subject: [PATCH 11/19] add tests --- runtime/common/src/types.rs | 14 ++-- runtime/moonbase/src/runtime_params.rs | 2 +- .../test-parameters/test-parameters.ts | 76 ++++++++++++++++++- 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 5fc9b9c949..38c0fc3215 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -29,9 +29,11 @@ impl BoundedU128 { Ok(Self(value)) } - pub fn new_or_min(value: u128) -> Self { - if value < L || value > U { + pub fn safe_new(value: u128) -> Self { + if value < L { Self(L) + } else if value > U { + Self(U) } else { Self(value) } @@ -87,14 +89,14 @@ mod tests { let bounded = BoundedU128::<1, 10>::new(11); assert_eq!(bounded, Err("Value out of bounds")); - let bounded = BoundedU128::<1, 10>::new_or_min(0); + let bounded = BoundedU128::<1, 10>::safe_new(0); assert_eq!(bounded.value(), 1); - let bounded = BoundedU128::<1, 10>::new_or_min(5); + let bounded = BoundedU128::<1, 10>::safe_new(5); assert_eq!(bounded.value(), 5); - let bounded = BoundedU128::<1, 10>::new_or_min(11); - assert_eq!(bounded.value(), 1); + let bounded = BoundedU128::<1, 10>::safe_new(11); + assert_eq!(bounded.value(), 10); } #[test] diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 97f390e423..6310d84ebc 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -41,7 +41,7 @@ pub mod dynamic_params { pub static Deposit: BoundedU128< { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::new_or_min(1 * currency::UNIT * currency::SUPPLY_FACTOR); + > = BoundedU128::safe_new(1 * currency::UNIT * currency::SUPPLY_FACTOR); } } diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 1148e59d77..cbe11258ef 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -1,7 +1,7 @@ import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; import "@moonbeam-network/api-augment"; import { alith } from "@moonwall/util"; - +import { fail } from "assert"; const UNIT = 1_000_000_000_000_000_000n; const RUNTIME = "MoonbaseRuntime"; @@ -83,6 +83,78 @@ describeSuite({ } testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); - testParam("PalletRandomness", "Deposit", ["u128", 1_000_000_000_000_000_000n * 100n]); + testParam("PalletRandomness", "Deposit", ["u128", UNIT * 100n]); + + it({ + id: `T${testCounter++} - PalletRandomness - Deposit - CustomTests`, + title: "Deposit parameter should only be accepted in bounds", + test: async () => { + const MIN = 1n * UNIT; + const MAX = 1000n * UNIT; + + // used as an acceptable value + const AVG = (MIN + MAX) / 2n; + + + const param1 = parameterType( + context, + "PalletRandomness", + "Deposit", + MIN - 1n, + ); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + const param2 = parameterType( + context, + "PalletRandomness", + "Deposit", + MAX + 1n, + ); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + + const param3 = parameterType( + context, + "PalletRandomness", + "Deposit", + AVG, + ); + const res3 = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + expect( + res3.result?.successful, + "An extrinsic should be created, since the parameter is valid" + ).to.be.true; + + + }, + }); }, }); From bde86341c2ceb60dc0785147668bdd468cc16275 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 11:49:36 +0000 Subject: [PATCH 12/19] use const --- runtime/common/src/types.rs | 14 +++++++------- runtime/moonbase/src/runtime_params.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 38c0fc3215..787d2a0b0c 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -29,13 +29,13 @@ impl BoundedU128 { Ok(Self(value)) } - pub fn safe_new(value: u128) -> Self { - if value < L { + pub fn safe_new() -> Self { + if VAL < L { Self(L) - } else if value > U { + } else if VAL > U { Self(U) } else { - Self(value) + Self(VAL) } } @@ -89,13 +89,13 @@ mod tests { let bounded = BoundedU128::<1, 10>::new(11); assert_eq!(bounded, Err("Value out of bounds")); - let bounded = BoundedU128::<1, 10>::safe_new(0); + let bounded = BoundedU128::<1, 10>::safe_new::<0>(); assert_eq!(bounded.value(), 1); - let bounded = BoundedU128::<1, 10>::safe_new(5); + let bounded = BoundedU128::<1, 10>::safe_new::<5>(); assert_eq!(bounded.value(), 5); - let bounded = BoundedU128::<1, 10>::safe_new(11); + let bounded = BoundedU128::<1, 10>::safe_new::<11>(); assert_eq!(bounded.value(), 10); } diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 6310d84ebc..c410b4a95b 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -41,7 +41,7 @@ pub mod dynamic_params { pub static Deposit: BoundedU128< { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::safe_new(1 * currency::UNIT * currency::SUPPLY_FACTOR); + > = BoundedU128::safe_new::<{1 * currency::UNIT * currency::SUPPLY_FACTOR}>(); } } From 5e7b9ad4f536dd1ad6ae3b8aa9fbf6da30fdb0bd Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 11:53:16 +0000 Subject: [PATCH 13/19] format --- .../test-parameters/test-parameters.ts | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index cbe11258ef..46638a2be7 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -95,13 +95,7 @@ describeSuite({ // used as an acceptable value const AVG = (MIN + MAX) / 2n; - - const param1 = parameterType( - context, - "PalletRandomness", - "Deposit", - MIN - 1n, - ); + const param1 = parameterType(context, "PalletRandomness", "Deposit", MIN - 1n); try { await context.createBlock( context @@ -115,12 +109,7 @@ describeSuite({ expect(error.toString().toLowerCase()).to.contain("value out of bounds"); } - const param2 = parameterType( - context, - "PalletRandomness", - "Deposit", - MAX + 1n, - ); + const param2 = parameterType(context, "PalletRandomness", "Deposit", MAX + 1n); try { await context.createBlock( context @@ -134,13 +123,7 @@ describeSuite({ expect(error.toString().toLowerCase()).to.contain("value out of bounds"); } - - const param3 = parameterType( - context, - "PalletRandomness", - "Deposit", - AVG, - ); + const param3 = parameterType(context, "PalletRandomness", "Deposit", AVG); const res3 = await context.createBlock( context .polkadotJs() @@ -152,8 +135,6 @@ describeSuite({ res3.result?.successful, "An extrinsic should be created, since the parameter is valid" ).to.be.true; - - }, }); }, From 2ca6d613336539ac6b884b34a0a632e895455c4d Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 11:58:23 +0000 Subject: [PATCH 14/19] fmt --- runtime/moonbase/src/runtime_params.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index c410b4a95b..7b17fde9be 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -35,13 +35,11 @@ pub mod dynamic_params { #[dynamic_pallet_params] #[codec(index = 1)] pub mod pallet_randomness { - use sp_core::ConstU128; - #[codec(index = 0)] pub static Deposit: BoundedU128< { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::safe_new::<{1 * currency::UNIT * currency::SUPPLY_FACTOR}>(); + > = BoundedU128::safe_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); } } From ea1d74f766e7b18d3a82c936b91681fe784da6f1 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 16:04:49 +0300 Subject: [PATCH 15/19] Update runtime/common/src/types.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Éloïs --- runtime/common/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 787d2a0b0c..08a024029c 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -29,7 +29,7 @@ impl BoundedU128 { Ok(Self(value)) } - pub fn safe_new() -> Self { + pub fn const_new() -> Self { if VAL < L { Self(L) } else if VAL > U { From 63cfa400de3d514dc8f2ae74c0671754aca325e1 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 16:34:30 +0000 Subject: [PATCH 16/19] add docs --- runtime/common/src/types.rs | 12 +++++++++--- runtime/moonbase/src/runtime_params.rs | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 08a024029c..12abdbbbb4 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -22,6 +22,7 @@ use sp_std::prelude::*; pub struct BoundedU128(u128); impl BoundedU128 { + // Create a new instance with a value. If the value is out of bounds, it will return an error. pub fn new(value: u128) -> Result { if value < L || value > U { return Err("Value out of bounds"); @@ -29,6 +30,8 @@ impl BoundedU128 { Ok(Self(value)) } + /// Create a new instance with a constant value. If the value is out of bounds, it will be + /// clamped to the nearest bound. pub fn const_new() -> Self { if VAL < L { Self(L) @@ -39,6 +42,7 @@ impl BoundedU128 { } } + /// Get the value. pub fn value(&self) -> u128 { self.0 } @@ -58,6 +62,8 @@ impl Decode for BoundedU128 { impl EncodeLike for BoundedU128 {} + +/// Expose a `Get` implementation form a `Get` type. #[macro_export] macro_rules! expose_u128_get { ($name:ident,$bounded_get:ty) => { @@ -89,13 +95,13 @@ mod tests { let bounded = BoundedU128::<1, 10>::new(11); assert_eq!(bounded, Err("Value out of bounds")); - let bounded = BoundedU128::<1, 10>::safe_new::<0>(); + let bounded = BoundedU128::<1, 10>::const_new::<0>(); assert_eq!(bounded.value(), 1); - let bounded = BoundedU128::<1, 10>::safe_new::<5>(); + let bounded = BoundedU128::<1, 10>::const_new::<5>(); assert_eq!(bounded.value(), 5); - let bounded = BoundedU128::<1, 10>::safe_new::<11>(); + let bounded = BoundedU128::<1, 10>::const_new::<11>(); assert_eq!(bounded.value(), 10); } diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 7b17fde9be..fc0acb10cc 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -39,7 +39,7 @@ pub mod dynamic_params { pub static Deposit: BoundedU128< { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::safe_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); + > = BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); } } From 932463f93138c7e4b01dcb45d0a7c04595cf4aea Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 17:42:57 +0000 Subject: [PATCH 17/19] use macro to gen runtime params --- runtime/common/src/lib.rs | 1 + runtime/common/src/runtime_params.rs | 69 ++++++++++++++++++++++++++ runtime/common/src/types.rs | 1 - runtime/moonbase/src/runtime_params.rs | 46 ++--------------- 4 files changed, 75 insertions(+), 42 deletions(-) create mode 100644 runtime/common/src/runtime_params.rs diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index ccde3fffa5..e20dd922db 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ mod impl_on_charge_evm_transaction; mod impl_self_contained_call; mod impl_xcm_evm_runner; pub mod migrations; +pub mod runtime_params; pub mod timestamp; pub mod types; pub mod weights; diff --git a/runtime/common/src/runtime_params.rs b/runtime/common/src/runtime_params.rs new file mode 100644 index 0000000000..78989c4273 --- /dev/null +++ b/runtime/common/src/runtime_params.rs @@ -0,0 +1,69 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +/// Macro to generate runtime parameters. +#[macro_export] +macro_rules! gen_runtime_params { + ( + RuntimeConfig_TreasuryProportion: $RuntimeConfig_TreasuryProportion:expr, + PalletRandomness_Deposit: $PalletRandomness_Deposit:expr, + ) => { + use crate::{currency, Runtime}; + use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; + use moonbeam_runtime_common::expose_u128_get; + use moonbeam_runtime_common::types::BoundedU128; + use sp_runtime::Perbill; + + #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] + pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = $RuntimeConfig_TreasuryProportion; + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, + > = $PalletRandomness_Deposit; + } + } + + expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit + ); + + #[cfg(feature = "runtime-benchmarks")] + impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } + } + }; +} diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs index 12abdbbbb4..a6aeefc913 100644 --- a/runtime/common/src/types.rs +++ b/runtime/common/src/types.rs @@ -62,7 +62,6 @@ impl Decode for BoundedU128 { impl EncodeLike for BoundedU128 {} - /// Expose a `Get` implementation form a `Get` type. #[macro_export] macro_rules! expose_u128_get { diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index fc0acb10cc..1a5f08f68b 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -15,47 +15,11 @@ // along with Moonbeam. If not, see . //! Dynamic runtime parametes. -use crate::{currency, Runtime}; -use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; -use moonbeam_runtime_common::expose_u128_get; -use moonbeam_runtime_common::types::BoundedU128; -use sp_runtime::Perbill; -#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] -pub mod dynamic_params { - use super::*; - #[dynamic_pallet_params] - #[codec(index = 0)] - pub mod runtime_config { - // for fees, 80% are burned, 20% to the treasury - #[codec(index = 0)] - pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); - } +use moonbeam_runtime_common::gen_runtime_params; - #[dynamic_pallet_params] - #[codec(index = 1)] - pub mod pallet_randomness { - #[codec(index = 0)] - pub static Deposit: BoundedU128< - { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, - { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, - > = BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); - } -} - -expose_u128_get!( - PalletRandomnessDepositU128, - dynamic_params::pallet_randomness::Deposit +gen_runtime_params!( + RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), + PalletRandomness_Deposit: + BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(), ); - -#[cfg(feature = "runtime-benchmarks")] -impl Default for RuntimeParameters { - fn default() -> Self { - RuntimeParameters::RuntimeConfig( - dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( - dynamic_params::runtime_config::FeesTreasuryProportion, - Some(Perbill::from_percent(20)), - ), - ) - } -} From aab0e01c535bc7212ae0a3bde378222d14235b74 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 3 Oct 2024 20:24:50 +0000 Subject: [PATCH 18/19] add to other runtimes --- Cargo.lock | 2 ++ runtime/common/src/runtime_params.rs | 5 +++-- runtime/moonbase/src/runtime_params.rs | 3 ++- runtime/moonbeam/Cargo.toml | 4 ++++ runtime/moonbeam/src/lib.rs | 21 +++++++++++++++++--- runtime/moonbeam/src/runtime_params.rs | 26 +++++++++++++++++++++++++ runtime/moonriver/Cargo.toml | 4 ++++ runtime/moonriver/src/lib.rs | 21 +++++++++++++++++--- runtime/moonriver/src/runtime_params.rs | 26 +++++++++++++++++++++++++ 9 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 runtime/moonbeam/src/runtime_params.rs create mode 100644 runtime/moonriver/src/runtime_params.rs diff --git a/Cargo.lock b/Cargo.lock index a8f341241b..0d6b556bdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6914,6 +6914,7 @@ dependencies = [ "pallet-moonbeam-orbiters", "pallet-multisig", "pallet-parachain-staking", + "pallet-parameters", "pallet-precompile-benchmarks", "pallet-preimage", "pallet-proxy", @@ -7345,6 +7346,7 @@ dependencies = [ "pallet-moonbeam-orbiters", "pallet-multisig", "pallet-parachain-staking", + "pallet-parameters", "pallet-precompile-benchmarks", "pallet-preimage", "pallet-proxy", diff --git a/runtime/common/src/runtime_params.rs b/runtime/common/src/runtime_params.rs index 78989c4273..3ddea4d73b 100644 --- a/runtime/common/src/runtime_params.rs +++ b/runtime/common/src/runtime_params.rs @@ -18,6 +18,7 @@ #[macro_export] macro_rules! gen_runtime_params { ( + UNIT: $UNIT:ident, RuntimeConfig_TreasuryProportion: $RuntimeConfig_TreasuryProportion:expr, PalletRandomness_Deposit: $PalletRandomness_Deposit:expr, ) => { @@ -43,8 +44,8 @@ macro_rules! gen_runtime_params { pub mod pallet_randomness { #[codec(index = 0)] pub static Deposit: BoundedU128< - { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, - { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1 * currency::$UNIT * currency::SUPPLY_FACTOR }, + { 1_000 * currency::$UNIT * currency::SUPPLY_FACTOR }, > = $PalletRandomness_Deposit; } } diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 1a5f08f68b..038a31d9d1 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -//! Dynamic runtime parametes. +//! Dynamic runtime parameters for moonbase. use moonbeam_runtime_common::gen_runtime_params; gen_runtime_params!( + UNIT: UNIT, RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), PalletRandomness_Deposit: BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(), diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index 7d956c0b7b..17ccfc2b5c 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true } pallet-identity = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-parameters = { workspace = true } pallet-proxy = { workspace = true } pallet-referenda = { workspace = true } pallet-root-testing = { workspace = true } @@ -272,6 +273,7 @@ std = [ "pallet-parachain-staking/std", "pallet-precompile-benchmarks/std", "pallet-preimage/std", + "pallet-parameters/std", "pallet-proxy-genesis-companion/std", "pallet-proxy/std", "pallet-randomness/std", @@ -362,6 +364,7 @@ runtime-benchmarks = [ "pallet-parachain-staking/runtime-benchmarks", "pallet-precompile-benchmarks/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-parameters/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-randomness/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", @@ -404,6 +407,7 @@ try-runtime = [ "pallet-parachain-staking/try-runtime", "pallet-precompile-benchmarks/try-runtime", "pallet-preimage/try-runtime", + "pallet-parameters/try-runtime", "pallet-referenda/try-runtime", "pallet-relay-storage-roots/try-runtime", "pallet-root-testing/try-runtime", diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 16a5847413..9000e9b503 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -101,6 +101,8 @@ use sp_std::{convert::TryFrom, prelude::*}; use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; +use runtime_params::*; + #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -120,6 +122,7 @@ pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; pub mod governance; +pub mod runtime_params; pub mod xcm_config; use governance::councils::*; @@ -345,8 +348,11 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - // for fees, 80% are burned, 20% to the treasury - let (_, to_treasury) = fees.ration(80, 20); + let treasury_perbill = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_perbill.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -1345,7 +1351,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; @@ -1386,6 +1392,13 @@ impl pallet_precompile_benchmarks::Config for Runtime { type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo; } +impl pallet_parameters::Config for Runtime { + type AdminOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type RuntimeParameters = RuntimeParameters; + type WeightInfo = moonbeam_weights::pallet_parameters::WeightInfo; +} + construct_runtime! { pub enum Runtime { @@ -1475,6 +1488,8 @@ construct_runtime! { // Randomness Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, + + Parameters: pallet_parameters = 121, } } diff --git a/runtime/moonbeam/src/runtime_params.rs b/runtime/moonbeam/src/runtime_params.rs new file mode 100644 index 0000000000..e402481f8a --- /dev/null +++ b/runtime/moonbeam/src/runtime_params.rs @@ -0,0 +1,26 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Dynamic runtime parameters for moonbeam. + +use moonbeam_runtime_common::gen_runtime_params; + +gen_runtime_params!( + UNIT: GLMR, + RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), + PalletRandomness_Deposit: + BoundedU128::const_new::<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>(), +); diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index cac100dbe2..cd2d1db7b4 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true } pallet-identity = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-parameters = { workspace = true } pallet-proxy = { workspace = true } pallet-referenda = { workspace = true } pallet-root-testing = { workspace = true } @@ -272,6 +273,7 @@ std = [ "pallet-parachain-staking/std", "pallet-precompile-benchmarks/std", "pallet-preimage/std", + "pallet-parameters/std", "pallet-proxy-genesis-companion/std", "pallet-proxy/std", "pallet-randomness/std", @@ -367,6 +369,7 @@ runtime-benchmarks = [ "pallet-parachain-staking/runtime-benchmarks", "pallet-precompile-benchmarks/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-parameters/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-randomness/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", @@ -407,6 +410,7 @@ try-runtime = [ "pallet-parachain-staking/try-runtime", "pallet-precompile-benchmarks/try-runtime", "pallet-preimage/try-runtime", + "pallet-parameters/try-runtime", "pallet-referenda/try-runtime", "pallet-relay-storage-roots/try-runtime", "pallet-root-testing/try-runtime", diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 288cbc6310..b9511c6852 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -101,6 +101,8 @@ use sp_std::{convert::TryFrom, prelude::*}; use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm}; use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError; +use runtime_params::*; + use smallvec::smallvec; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -119,6 +121,7 @@ pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; pub mod governance; +pub mod runtime_params; pub mod xcm_config; mod migrations; @@ -347,8 +350,11 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - // for fees, 80% are burned, 20% to the treasury - let (_, to_treasury) = fees.ration(80, 20); + let treasury_perbill = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_perbill.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -1349,7 +1355,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; @@ -1390,6 +1396,13 @@ impl pallet_precompile_benchmarks::Config for Runtime { type WeightInfo = moonriver_weights::pallet_precompile_benchmarks::WeightInfo; } +impl pallet_parameters::Config for Runtime { + type AdminOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type RuntimeParameters = RuntimeParameters; + type WeightInfo = moonriver_weights::pallet_parameters::WeightInfo; +} + construct_runtime! { pub enum Runtime { @@ -1476,6 +1489,8 @@ construct_runtime! { // Randomness Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, + + Parameters: pallet_parameters = 121, } } diff --git a/runtime/moonriver/src/runtime_params.rs b/runtime/moonriver/src/runtime_params.rs new file mode 100644 index 0000000000..2cb7610714 --- /dev/null +++ b/runtime/moonriver/src/runtime_params.rs @@ -0,0 +1,26 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Dynamic runtime parameters for moonriver. + +use moonbeam_runtime_common::gen_runtime_params; + +gen_runtime_params!( + UNIT: MOVR, + RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), + PalletRandomness_Deposit: + BoundedU128::const_new::<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>(), +); From be6c4516e9afab95c34d106ca33aceb0e3b91040 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Mon, 7 Oct 2024 07:46:41 +0000 Subject: [PATCH 19/19] apply suggestions --- runtime/common/src/lib.rs | 1 - runtime/common/src/runtime_params.rs | 70 ------------------------- runtime/moonbase/src/runtime_params.rs | 48 ++++++++++++++--- runtime/moonbeam/src/lib.rs | 3 +- runtime/moonbeam/src/runtime_params.rs | 48 ++++++++++++++--- runtime/moonriver/src/lib.rs | 3 +- runtime/moonriver/src/runtime_params.rs | 48 ++++++++++++++--- 7 files changed, 128 insertions(+), 93 deletions(-) delete mode 100644 runtime/common/src/runtime_params.rs diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index e20dd922db..ccde3fffa5 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,7 +23,6 @@ mod impl_on_charge_evm_transaction; mod impl_self_contained_call; mod impl_xcm_evm_runner; pub mod migrations; -pub mod runtime_params; pub mod timestamp; pub mod types; pub mod weights; diff --git a/runtime/common/src/runtime_params.rs b/runtime/common/src/runtime_params.rs deleted file mode 100644 index 3ddea4d73b..0000000000 --- a/runtime/common/src/runtime_params.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2024 Moonbeam Foundation. -// This file is part of Moonbeam. - -// Moonbeam is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Moonbeam is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Moonbeam. If not, see . - -/// Macro to generate runtime parameters. -#[macro_export] -macro_rules! gen_runtime_params { - ( - UNIT: $UNIT:ident, - RuntimeConfig_TreasuryProportion: $RuntimeConfig_TreasuryProportion:expr, - PalletRandomness_Deposit: $PalletRandomness_Deposit:expr, - ) => { - use crate::{currency, Runtime}; - use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; - use moonbeam_runtime_common::expose_u128_get; - use moonbeam_runtime_common::types::BoundedU128; - use sp_runtime::Perbill; - - #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] - pub mod dynamic_params { - use super::*; - #[dynamic_pallet_params] - #[codec(index = 0)] - pub mod runtime_config { - // for fees, 80% are burned, 20% to the treasury - #[codec(index = 0)] - pub static FeesTreasuryProportion: Perbill = $RuntimeConfig_TreasuryProportion; - } - - #[dynamic_pallet_params] - #[codec(index = 1)] - pub mod pallet_randomness { - #[codec(index = 0)] - pub static Deposit: BoundedU128< - { 1 * currency::$UNIT * currency::SUPPLY_FACTOR }, - { 1_000 * currency::$UNIT * currency::SUPPLY_FACTOR }, - > = $PalletRandomness_Deposit; - } - } - - expose_u128_get!( - PalletRandomnessDepositU128, - dynamic_params::pallet_randomness::Deposit - ); - - #[cfg(feature = "runtime-benchmarks")] - impl Default for RuntimeParameters { - fn default() -> Self { - RuntimeParameters::RuntimeConfig( - dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( - dynamic_params::runtime_config::FeesTreasuryProportion, - Some(Perbill::from_percent(20)), - ), - ) - } - } - }; -} diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 038a31d9d1..2ac2a86141 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -16,11 +16,47 @@ //! Dynamic runtime parameters for moonbase. -use moonbeam_runtime_common::gen_runtime_params; +use crate::{currency, Runtime}; +use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; +use sp_runtime::Perbill; -gen_runtime_params!( - UNIT: UNIT, - RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), - PalletRandomness_Deposit: - BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(), +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); + } +} + +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit ); + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } +} diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 9000e9b503..da79b48758 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1431,6 +1431,7 @@ construct_runtime! { ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + Parameters: pallet_parameters = 38, // Has been permanently removed for safety reasons. // Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 40, @@ -1488,8 +1489,6 @@ construct_runtime! { // Randomness Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, - - Parameters: pallet_parameters = 121, } } diff --git a/runtime/moonbeam/src/runtime_params.rs b/runtime/moonbeam/src/runtime_params.rs index e402481f8a..7c37dbaf81 100644 --- a/runtime/moonbeam/src/runtime_params.rs +++ b/runtime/moonbeam/src/runtime_params.rs @@ -16,11 +16,47 @@ //! Dynamic runtime parameters for moonbeam. -use moonbeam_runtime_common::gen_runtime_params; +use crate::{currency, Runtime}; +use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; +use sp_runtime::Perbill; -gen_runtime_params!( - UNIT: GLMR, - RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), - PalletRandomness_Deposit: - BoundedU128::const_new::<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>(), +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::GLMR * currency::SUPPLY_FACTOR }, + { 1_000 * currency::GLMR * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>(); + } +} + +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit ); + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } +} diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index b9511c6852..ae6e28e118 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1435,6 +1435,7 @@ construct_runtime! { ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + Parameters: pallet_parameters = 38, // Sudo was previously index 40 @@ -1489,8 +1490,6 @@ construct_runtime! { // Randomness Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, - - Parameters: pallet_parameters = 121, } } diff --git a/runtime/moonriver/src/runtime_params.rs b/runtime/moonriver/src/runtime_params.rs index 2cb7610714..054a89ed26 100644 --- a/runtime/moonriver/src/runtime_params.rs +++ b/runtime/moonriver/src/runtime_params.rs @@ -16,11 +16,47 @@ //! Dynamic runtime parameters for moonriver. -use moonbeam_runtime_common::gen_runtime_params; +use crate::{currency, Runtime}; +use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; +use sp_runtime::Perbill; -gen_runtime_params!( - UNIT: MOVR, - RuntimeConfig_TreasuryProportion: Perbill::from_percent(20), - PalletRandomness_Deposit: - BoundedU128::const_new::<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>(), +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::MOVR * currency::SUPPLY_FACTOR }, + { 1_000 * currency::MOVR * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>(); + } +} + +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit ); + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } +}