diff --git a/runtime/mainnet/src/config/mod.rs b/runtime/mainnet/src/config/mod.rs index 47d41aba..2b1fa446 100644 --- a/runtime/mainnet/src/config/mod.rs +++ b/runtime/mainnet/src/config/mod.rs @@ -1,4 +1,5 @@ pub mod governance; mod proxy; +mod utility; mod revive; pub mod xcm; diff --git a/runtime/mainnet/src/config/utility.rs b/runtime/mainnet/src/config/utility.rs new file mode 100644 index 00000000..1536707a --- /dev/null +++ b/runtime/mainnet/src/config/utility.rs @@ -0,0 +1,247 @@ +use frame_support::{pallet_prelude::ConstU32, traits::EqualPrivilegeOnly}; + +use crate::{ + deposit, parameter_types, AccountId, Balance, Balances, EnsureRoot, HoldConsideration, + LinearStoragePrice, OriginCaller, Perbill, Preimage, Runtime, RuntimeBlockWeights, RuntimeCall, + RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, Weight, +}; + +parameter_types! { + // One storage item; key size is 32 + 32; value is size 4+4+16+32 bytes = 120 bytes. + pub const DepositBase: Balance = deposit(1, 120); + // Additional storage item size of 32 bytes. + pub const DepositFactor: Balance = deposit(0, 32); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + +parameter_types! { + pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); + pub const PreimageBaseDeposit: Balance = deposit(2, 64); + pub const PreimageByteDeposit: Balance = deposit(0, 1); +} + +impl pallet_preimage::Config for Runtime { + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_preimage::weights::SubstrateWeight; +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(60) * + RuntimeBlockWeights::get().max_block; +} + +impl pallet_scheduler::Config for Runtime { + #[cfg(feature = "runtime-benchmarks")] + type MaxScheduledPerBlock = ConstU32<512>; + #[cfg(not(feature = "runtime-benchmarks"))] + type MaxScheduledPerBlock = ConstU32<50>; + type MaximumWeight = MaximumSchedulerWeight; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type PalletsOrigin = OriginCaller; + type Preimages = Preimage; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type ScheduleOrigin = EnsureRoot; + type WeightInfo = pallet_scheduler::weights::SubstrateWeight; +} + +impl pallet_utility::Config for Runtime { + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_utility::weights::SubstrateWeight; +} + +#[cfg(test)] +mod tests { + use std::any::TypeId; + + use frame_support::traits::Get; + + use super::*; + + #[test] + fn utility_caller_origin_provided_by_runtime() { + assert_eq!( + TypeId::of::<::PalletsOrigin>(), + TypeId::of::(), + ); + } + + #[test] + fn utility_does_not_use_default_weights() { + assert_ne!( + TypeId::of::<::WeightInfo>(), + TypeId::of::<()>(), + ); + } + + #[test] + fn multisig_uses_balances_for_deposits() { + assert_eq!( + TypeId::of::<::Currency>(), + TypeId::of::(), + ); + } + + #[test] + fn multisig_call_deposit_has_base_amount() { + assert_eq!( + <::DepositBase as Get>::get(), + deposit(1, 120) + ); + } + + #[test] + fn multisig_call_deposit_has_additional_factor() { + assert_eq!( + <::DepositFactor as Get>::get(), + deposit(0, 32) + ); + } + + #[test] + fn multisig_restricts_max_signatories() { + assert_eq!(<::MaxSignatories as Get>::get(), 100); + } + + #[test] + fn multisig_does_not_use_default_weights() { + assert_ne!( + TypeId::of::<::WeightInfo>(), + TypeId::of::<()>(), + ); + } + + #[test] + #[cfg(not(feature = "runtime-benchmarks"))] + fn scheduler_call_queue_per_block_is_limited() { + assert_eq!( + TypeId::of::<::MaxScheduledPerBlock>(), + TypeId::of::>(), + ); + } + + #[test] + #[cfg(feature = "runtime-benchmarks")] + fn scheduler_call_queue_per_block_is_limited() { + assert_eq!( + TypeId::of::<::MaxScheduledPerBlock>(), + TypeId::of::>(), + ); + } + + #[test] + fn scheduler_has_max_weight_per_dispatchable() { + assert_eq!( + TypeId::of::<::MaximumWeight>(), + TypeId::of::(), + ); + + assert_eq!( + <::MaximumWeight as Get>::get(), + Perbill::from_percent(60) * RuntimeBlockWeights::get().max_block, + ); + } + + #[test] + fn scheduler_privilege_cmp_is_equal_privilege_only() { + // EqualPrvilegeOnly can be used while ScheduleOrigin is reserve to Root. + assert_eq!( + TypeId::of::<::OriginPrivilegeCmp>(), + TypeId::of::(), + ); + } + + #[test] + fn only_root_can_schedule() { + assert_eq!( + TypeId::of::<::ScheduleOrigin>(), + TypeId::of::>(), + ); + } + + #[test] + fn scheduler_does_not_use_default_weights() { + assert_ne!( + TypeId::of::<::WeightInfo>(), + TypeId::of::<()>() + ); + } + + #[test] + fn scheduler_uses_preimage_to_look_up_calls() { + assert_eq!( + TypeId::of::<::Preimages>(), + TypeId::of::(), + ); + } + + #[test] + fn preimage_uses_balances_as_currency() { + assert_eq!( + TypeId::of::<::Currency>(), + TypeId::of::(), + ); + } + + #[test] + fn preimage_manage_origin_is_root() { + assert_eq!( + TypeId::of::<::ManagerOrigin>(), + TypeId::of::>(), + ); + } + + #[test] + fn preimage_does_not_use_default_weights() { + assert_ne!( + TypeId::of::<::WeightInfo>(), + TypeId::of::<()>() + ); + } + + #[test] + fn preimage_hold_reason_uses_linear_price() { + assert_eq!( + TypeId::of::<::Consideration>(), + TypeId::of::< + HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >, + >() + ); + } + + #[test] + fn preimage_base_deposit() { + assert_eq!(PreimageBaseDeposit::get(), deposit(2, 64)); + } + + #[test] + fn preimage_byte_deposit() { + assert_eq!(PreimageByteDeposit::get(), deposit(0, 1)); + } +} diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index a9e1a2ae..33ffd1b1 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -584,126 +584,6 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = (); } -parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(60) * - RuntimeBlockWeights::get().max_block; -} - -impl pallet_scheduler::Config for Runtime { - #[cfg(feature = "runtime-benchmarks")] - type MaxScheduledPerBlock = ConstU32<512>; - #[cfg(not(feature = "runtime-benchmarks"))] - type MaxScheduledPerBlock = ConstU32<50>; - type MaximumWeight = MaximumSchedulerWeight; - type OriginPrivilegeCmp = EqualPrivilegeOnly; - type PalletsOrigin = OriginCaller; - type Preimages = Preimage; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type RuntimeOrigin = RuntimeOrigin; - type ScheduleOrigin = EnsureRoot; - type WeightInfo = pallet_scheduler::weights::SubstrateWeight; -} - -parameter_types! { - pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); - pub const PreimageBaseDeposit: Balance = deposit(2, 64); - pub const PreimageByteDeposit: Balance = deposit(0, 1); -} - -impl pallet_preimage::Config for Runtime { - type Consideration = HoldConsideration< - AccountId, - Balances, - PreimageHoldReason, - LinearStoragePrice, - >; - type Currency = Balances; - type ManagerOrigin = EnsureRoot; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_preimage::weights::SubstrateWeight; -} - -parameter_types! { - // One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. - pub const DepositBase: Balance = deposit(1, 88); - // Additional storage item size of 32 bytes. - pub const DepositFactor: Balance = deposit(0, 32); - pub const MaxSignatories: u32 = 100; -} - -impl pallet_multisig::Config for Runtime { - type Currency = Balances; - type DepositBase = DepositBase; - type DepositFactor = DepositFactor; - type MaxSignatories = MaxSignatories; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_multisig::weights::SubstrateWeight; -} - -impl pallet_utility::Config for Runtime { - type PalletsOrigin = OriginCaller; - type RuntimeCall = RuntimeCall; - type RuntimeEvent = RuntimeEvent; - type WeightInfo = pallet_utility::weights::SubstrateWeight; -} - -const TREASURY_PALLET_ID: PalletId = PalletId(*b"treasury"); -pub(crate) type TreasuryPaymaster = PayFromAccount; - -parameter_types! { - pub const SpendPeriod: BlockNumber = 6 * DAYS; - pub const TreasuryPalletId: PalletId = TREASURY_PALLET_ID; - pub const MaxApprovals: u32 = 100; - pub const PayoutPeriod: BlockNumber = 30 * DAYS; - pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); -} - -#[cfg(feature = "runtime-benchmarks")] -pub struct BenchmarkHelper; -#[cfg(feature = "runtime-benchmarks")] -impl pallet_treasury::ArgumentsFactory<(), AccountId> for BenchmarkHelper { - fn create_asset_kind(_seed: u32) -> () { - () - } - - fn create_beneficiary(seed: [u8; 32]) -> AccountId { - let account_id = AccountId::from(seed); - Balances::force_set_balance( - crate::RuntimeOrigin::root(), - account_id.clone().into(), - EXISTENTIAL_DEPOSIT, - ) - .unwrap(); - account_id - } -} - -impl pallet_treasury::Config for Runtime { - type AssetKind = (); - type BalanceConverter = UnityAssetBalanceConversion; - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = BenchmarkHelper; - type Beneficiary = AccountId; - type BeneficiaryLookup = IdentityLookup; - type BlockNumberProvider = System; - type Burn = (); - type BurnDestination = (); - type Currency = Balances; - type MaxApprovals = MaxApprovals; - type PalletId = TreasuryPalletId; - type Paymaster = TreasuryPaymaster; - type PayoutPeriod = PayoutPeriod; - type RejectOrigin = EnsureRoot; - type RuntimeEvent = RuntimeEvent; - type SpendFunds = (); - /// Never allow origins except via the proposals process. - type SpendOrigin = NeverEnsureOrigin; - type SpendPeriod = SpendPeriod; - type WeightInfo = pallet_treasury::weights::SubstrateWeight; -} - #[frame_support::runtime] mod runtime { // Create the runtime by composing the FRAME pallets that were previously configured.