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(mainnet): ready runtime config #458

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cumulus_primitives_core::ParaId;
use pop_runtime_common::{AccountId, AuraId};
use pop_runtime_mainnet::SudoAddress;
use pop_runtime_mainnet::config::governance::SudoAddress;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
Expand Down
42 changes: 42 additions & 0 deletions runtime/mainnet/src/config/governance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::{parameter_types, AccountId, Runtime, RuntimeCall, RuntimeEvent, Ss58Codec};

// Multisig account for sudo, generated from the following signatories:
// - 15VPagCVayS6XvT5RogPYop3BJTJzwqR2mCGR1kVn3w58ygg
// - 142zako1kfvrpQ7pJKYR8iGUD58i4wjb78FUsmJ9WcXmkM5z
// - 15k9niqckMg338cFBoz9vWFGwnCtwPBquKvqJEfHApijZkDz
// - 14G3CUFnZUBnHZUhahexSZ6AgemaW9zMHBnGccy3df7actf4
// - Threshold 2
const SUDO_ADDRESS: &str = "15NMV2JX1NeMwarQiiZvuJ8ixUcvayFDcu1F9Wz1HNpSc8gP";

parameter_types! {
pub SudoAddress: AccountId = AccountId::from_ss58check(SUDO_ADDRESS).expect("sudo address is valid SS58");
}
impl pallet_sudo::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
}

#[cfg(test)]
mod tests {
use std::any::TypeId;

use super::*;

#[test]
fn sudo_account_matches() {
// Doesn't use SUDO_ADDRESS constant on purpose.
assert_eq!(
SudoAddress::get(),
AccountId::from_ss58check("15NMV2JX1NeMwarQiiZvuJ8ixUcvayFDcu1F9Wz1HNpSc8gP")
.expect("sudo address is valid SS58")
);
}
#[test]
fn sudo_does_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as pallet_sudo::Config>::WeightInfo>(),
TypeId::of::<()>(),
);
}
}
2 changes: 2 additions & 0 deletions runtime/mainnet/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod governance;
mod proxy;
mod utility;
pub mod xcm;
247 changes: 247 additions & 0 deletions runtime/mainnet/src/config/utility.rs
Original file line number Diff line number Diff line change
@@ -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<Runtime>;
}

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<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
>;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_preimage::weights::SubstrateWeight<Runtime>;
}

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<AccountId>;
type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>;
}

impl pallet_utility::Config for Runtime {
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
}

#[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::<<Runtime as pallet_utility::Config>::PalletsOrigin>(),
TypeId::of::<OriginCaller>(),
);
}

#[test]
fn utility_does_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as pallet_utility::Config>::WeightInfo>(),
TypeId::of::<()>(),
);
}

#[test]
fn multisig_uses_balances_for_deposits() {
assert_eq!(
TypeId::of::<<Runtime as pallet_multisig::Config>::Currency>(),
TypeId::of::<Balances>(),
);
}

#[test]
fn multisig_call_deposit_has_base_amount() {
assert_eq!(
<<Runtime as pallet_multisig::Config>::DepositBase as Get<Balance>>::get(),
deposit(1, 120)
);
}

#[test]
fn multisig_call_deposit_has_additional_factor() {
assert_eq!(
<<Runtime as pallet_multisig::Config>::DepositFactor as Get<Balance>>::get(),
deposit(0, 32)
);
}

#[test]
fn multisig_restricts_max_signatories() {
assert_eq!(<<Runtime as pallet_multisig::Config>::MaxSignatories as Get<u32>>::get(), 100);
}

#[test]
fn multisig_does_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as pallet_multisig::Config>::WeightInfo>(),
TypeId::of::<()>(),
);
}

#[test]
#[cfg(not(feature = "runtime-benchmarks"))]
fn scheduler_call_queue_per_block_is_limited() {
assert_eq!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::MaxScheduledPerBlock>(),
TypeId::of::<ConstU32<50>>(),
);
}

#[test]
#[cfg(feature = "runtime-benchmarks")]
fn scheduler_call_queue_per_block_is_limited() {
assert_eq!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::MaxScheduledPerBlock>(),
TypeId::of::<ConstU32<512>>(),
);
}

#[test]
fn scheduler_has_max_weight_per_dispatchable() {
assert_eq!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::MaximumWeight>(),
TypeId::of::<MaximumSchedulerWeight>(),
);

assert_eq!(
<<Runtime as pallet_scheduler::Config>::MaximumWeight as Get<Weight>>::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::<<Runtime as pallet_scheduler::Config>::OriginPrivilegeCmp>(),
TypeId::of::<EqualPrivilegeOnly>(),
);
}

#[test]
fn only_root_can_schedule() {
assert_eq!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::ScheduleOrigin>(),
TypeId::of::<EnsureRoot<AccountId>>(),
);
}

#[test]
fn scheduler_does_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::WeightInfo>(),
TypeId::of::<()>()
);
}

#[test]
fn scheduler_uses_preimage_to_look_up_calls() {
assert_eq!(
TypeId::of::<<Runtime as pallet_scheduler::Config>::Preimages>(),
TypeId::of::<Preimage>(),
);
}

#[test]
fn preimage_uses_balances_as_currency() {
assert_eq!(
TypeId::of::<<Runtime as pallet_preimage::Config>::Currency>(),
TypeId::of::<Balances>(),
);
}

#[test]
fn preimage_manage_origin_is_root() {
assert_eq!(
TypeId::of::<<Runtime as pallet_preimage::Config>::ManagerOrigin>(),
TypeId::of::<EnsureRoot<AccountId>>(),
);
}

#[test]
fn preimage_does_not_use_default_weights() {
assert_ne!(
TypeId::of::<<Runtime as pallet_preimage::Config>::WeightInfo>(),
TypeId::of::<()>()
);
}

#[test]
fn preimage_hold_reason_uses_linear_price() {
assert_eq!(
TypeId::of::<<Runtime as pallet_preimage::Config>::Consideration>(),
TypeId::of::<
HoldConsideration<
AccountId,
Balances,
PreimageHoldReason,
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
>,
>()
);
}

#[test]
fn preimage_base_deposit() {
assert_eq!(PreimageBaseDeposit::get(), deposit(2, 64));
}

#[test]
fn preimage_byte_deposit() {
assert_eq!(PreimageByteDeposit::get(), deposit(0, 1));
}
}
Loading