Introduce OnSetCode type into system config trait. (#8496)

* Introduce OnSetCode type into system config trait.

* Docs.

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2021-04-01 14:20:24 +02:00
committed by GitHub
parent 34458e9b9c
commit 643d2b669f
65 changed files with 85 additions and 4 deletions
@@ -49,6 +49,7 @@ impl system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
}
impl pallet_template::Config for Test {
@@ -195,6 +195,8 @@ impl frame_system::Config for Runtime {
type SystemWeightInfo = ();
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
/// The set code logic, just the default since we're not a parachain.
type OnSetCode = ();
}
impl pallet_aura::Config for Runtime {
+1
View File
@@ -213,6 +213,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>;
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
}
impl pallet_utility::Config for Runtime {
+1
View File
@@ -65,6 +65,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -53,6 +53,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -70,6 +70,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_timestamp::Config for Test {
@@ -200,6 +200,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
pub struct TestSessionHandler;
+1
View File
@@ -447,6 +447,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -92,6 +92,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
@@ -75,6 +75,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
@@ -77,6 +77,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
@@ -90,6 +90,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const TransactionByteFee: u64 = 1;
@@ -104,6 +104,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types!{
+1
View File
@@ -80,6 +80,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -1004,6 +1004,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl Config<Instance1> for Test {
type Origin = Origin;
+1
View File
@@ -222,6 +222,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_balances::Config for Test {
type MaxLocks = ();
+1
View File
@@ -103,6 +103,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
@@ -161,6 +161,7 @@ impl frame_system::Config for Runtime {
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type OnSetCode = ();
}
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
@@ -1085,6 +1085,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -58,6 +58,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
@@ -82,6 +82,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
type Extrinsic = TestXt<Call, ()>;
@@ -66,6 +66,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -76,6 +76,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -670,6 +670,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
type Balance = u64;
+1
View File
@@ -70,6 +70,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -97,6 +97,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl<C> frame_system::offchain::SendTransactionTypes<C> for Test
+1
View File
@@ -71,6 +71,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -140,6 +140,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -68,6 +68,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -328,6 +328,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
ord_parameter_types! {
pub const One: u64 = 1;
@@ -71,6 +71,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl Config for Test {
+1
View File
@@ -71,6 +71,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -292,6 +292,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -70,6 +70,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
ord_parameter_types! {
@@ -65,6 +65,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -124,6 +124,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -73,6 +73,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -193,6 +193,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
fn new_test_ext() -> sp_io::TestExternalities {
+1
View File
@@ -70,6 +70,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+3 -2
View File
@@ -76,8 +76,8 @@ pub trait Config: system::Config {
type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;
/// The aggregated origin which the dispatch will take.
type Origin: OriginTrait<PalletsOrigin =
Self::PalletsOrigin> + From<Self::PalletsOrigin> + IsType<<Self as system::Config>::Origin>;
type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
+ From<Self::PalletsOrigin> + IsType<<Self as system::Config>::Origin>;
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + Clone + Eq;
@@ -835,6 +835,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl logger::Config for Test {
type Event = Event;
+1
View File
@@ -79,6 +79,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_balances::Config for Test {
@@ -67,6 +67,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -250,6 +250,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_timestamp::Config for Test {
+1
View File
@@ -91,6 +91,7 @@ impl frame_system::Config for Test {
type AccountData = pallet_balances::AccountData<u64>;
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_balances::Config for Test {
@@ -64,6 +64,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
+1
View File
@@ -150,6 +150,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
+1
View File
@@ -151,6 +151,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
// Implement the logger module's `Config` on the Test runtime.
@@ -395,6 +395,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -225,6 +225,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -217,6 +217,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -260,6 +260,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet::Config for Runtime {
type Event = Event;
@@ -166,6 +166,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
frame_support::construct_runtime!(
@@ -141,6 +141,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_test::Trait for Runtime {
+1
View File
@@ -89,6 +89,7 @@ impl system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl module::Config for Runtime {
@@ -61,6 +61,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl crate::Config for Test {}
+18 -2
View File
@@ -140,6 +140,18 @@ pub type ConsumedWeight = PerDispatchClass<Weight>;
pub use pallet::*;
/// Do something when we should be setting the code.
pub trait SetCode {
/// Set the code to the given blob.
fn set_code(code: Vec<u8>);
}
impl SetCode for () {
fn set_code(code: Vec<u8>) {
storage::unhashed::put_raw(well_known_keys::CODE, &code);
}
}
#[frame_support::pallet]
pub mod pallet {
use crate::{*, pallet_prelude::*, self as frame_system};
@@ -253,6 +265,10 @@ pub mod pallet {
/// an identifier of the chain.
#[pallet::constant]
type SS58Prefix: Get<u8>;
/// What to do if the user wants the code set to something. Just use `()` unless you are in
/// cumulus.
type OnSetCode: SetCode;
}
#[pallet::pallet]
@@ -329,7 +345,7 @@ pub mod pallet {
ensure_root(origin)?;
Self::can_set_code(&code)?;
storage::unhashed::put_raw(well_known_keys::CODE, &code);
T::OnSetCode::set_code(code);
Self::deposit_event(Event::CodeUpdated);
Ok(().into())
}
@@ -348,7 +364,7 @@ pub mod pallet {
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
storage::unhashed::put_raw(well_known_keys::CODE, &code);
T::OnSetCode::set_code(code);
Self::deposit_event(Event::CodeUpdated);
Ok(().into())
}
+1
View File
@@ -107,6 +107,7 @@ impl Config for Test {
type OnKilledAccount = RecordKilled;
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
pub type SysEvent = frame_system::Event<Test>;
+1
View File
@@ -352,6 +352,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const MinimumPeriod: u64 = 5;
+1
View File
@@ -76,6 +76,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
@@ -687,6 +687,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
+1
View File
@@ -77,6 +77,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -111,6 +111,7 @@ impl frame_system::Config for Test {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
+1
View File
@@ -464,6 +464,7 @@ mod tests {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
parameter_types! {
pub const MaxLocks: u32 = 10;
+1
View File
@@ -515,6 +515,7 @@ impl frame_system::Config for Runtime {
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
impl pallet_timestamp::Config for Runtime {