diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index b1bdf357ec07d..b51683375372f 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -148,9 +148,10 @@ pub type OriginOf = as Dispatchable>::Origin; /// - `Block`: The block type of the runtime /// - `Context`: The context that is used when checking an extrinsic. /// - `UnsignedValidator`: The unsigned transaction validator of the runtime. -/// - `AllPallets`: Tuple that contains all modules. Will be used to call e.g. `on_initialize`. -/// - `OnRuntimeUpgrade`: Custom logic that should be called after a runtime upgrade. Modules are -/// already called by `AllPallets`. It will be called before all modules will be called. +/// - `AllPallets`: Tuple that contains all pallets. Will be used to call e.g. `on_initialize`, +/// it must include system pallet. +/// - `OnRuntimeUpgrade`: Custom logic that should be called after a runtime upgrade. Pallets are +/// already called by `AllPallets`. It will be called before all pallets will be called. pub struct Executive( PhantomData<(System, Block, Context, UnsignedValidator, AllPallets, OnRuntimeUpgrade)>, ); @@ -212,9 +213,6 @@ where pub fn execute_on_runtime_upgrade() -> frame_support::weights::Weight { let mut weight = 0; weight = weight.saturating_add(COnRuntimeUpgrade::on_runtime_upgrade()); - weight = weight.saturating_add( - as OnRuntimeUpgrade>::on_runtime_upgrade(), - ); weight = weight.saturating_add(::on_runtime_upgrade()); weight @@ -257,7 +255,7 @@ where #[cfg(feature = "try-runtime")] pub fn try_runtime_upgrade() -> Result { < - (frame_system::Pallet::, COnRuntimeUpgrade, AllPallets) + (COnRuntimeUpgrade, AllPallets) as OnRuntimeUpgrade >::pre_upgrade().unwrap(); @@ -265,7 +263,7 @@ where let weight = Self::execute_on_runtime_upgrade(); < - (frame_system::Pallet::, COnRuntimeUpgrade, AllPallets) + (COnRuntimeUpgrade, AllPallets) as OnRuntimeUpgrade >::post_upgrade().unwrap(); @@ -306,9 +304,6 @@ where digest, frame_system::InitKind::Full, ); - weight = weight.saturating_add( as OnInitialize< - System::BlockNumber, - >>::on_initialize(*block_number)); weight = weight.saturating_add( >::on_initialize(*block_number), ); @@ -419,26 +414,16 @@ where let mut remaining_weight = max_weight.saturating_sub(weight.total()); if remaining_weight > 0 { - let mut used_weight = - as OnIdle>::on_idle( - block_number, - remaining_weight, - ); - remaining_weight = remaining_weight.saturating_sub(used_weight); - used_weight = >::on_idle( + let used_weight = >::on_idle( block_number, remaining_weight, - ) - .saturating_add(used_weight); + ); >::register_extra_weight_unchecked( used_weight, DispatchClass::Mandatory, ); } - as OnFinalize>::on_finalize( - block_number, - ); >::on_finalize(block_number); } @@ -1364,8 +1349,6 @@ mod tests { let frame_system_upgrade_weight = frame_system::Pallet::::on_runtime_upgrade(); let custom_runtime_upgrade_weight = CustomOnRuntimeUpgrade::on_runtime_upgrade(); let runtime_upgrade_weight = ::on_runtime_upgrade(); - let frame_system_on_initialize_weight = - frame_system::Pallet::::on_initialize(block_number); let on_initialize_weight = >::on_initialize(block_number); let base_block_weight = @@ -1377,7 +1360,6 @@ mod tests { frame_system_upgrade_weight + custom_runtime_upgrade_weight + runtime_upgrade_weight + - frame_system_on_initialize_weight + on_initialize_weight + base_block_weight, ); }); diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 04bb2ead645d2..621d36224b3cf 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -206,32 +206,38 @@ fn decl_all_pallets<'a>( } // Make nested tuple structure like (((Babe, Consensus), Grandpa), ...) // But ignore the system pallet. - let all_pallets = names + let all_pallets_without_system = names .iter() .filter(|n| **n != SYSTEM_PALLET_NAME) .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); - let all_pallets_with_system = names + let all_pallets = names .iter() .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); quote!( #types /// All pallets included in the runtime as a nested tuple of types. - /// Excludes the System pallet. pub type AllPallets = ( #all_pallets ); + /// All pallets included in the runtime as a nested tuple of types. - pub type AllPalletsWithSystem = ( #all_pallets_with_system ); + #[deprecated(note = "use `AllPallets` instead")] + pub type AllPalletsWithSystem = AllPallets; + + /// All pallets included in the runtime as a nested tuple of types. + /// Excludes the System pallet. + pub type AllPalletsWithoutSystem = ( #all_pallets_without_system ); /// All modules included in the runtime as a nested tuple of types. /// Excludes the System pallet. #[deprecated(note = "use `AllPallets` instead")] #[allow(dead_code)] - pub type AllModules = ( #all_pallets ); + #[allow(deprecated)] + pub type AllModules = AllPalletsWithoutSystem; /// All modules included in the runtime as a nested tuple of types. #[deprecated(note = "use `AllPalletsWithSystem` instead")] #[allow(dead_code)] - pub type AllModulesWithSystem = ( #all_pallets_with_system ); + pub type AllModulesWithSystem = AllPallets; ) } diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index dc72be3ebdd49..a1b684ed86325 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -942,7 +942,7 @@ fn pallet_hooks_expand() { assert_eq!(AllPallets::on_initialize(1), 10); AllPallets::on_finalize(1); - assert_eq!(AllPallets::on_runtime_upgrade(), 30); + AllPallets::on_runtime_upgrade(); assert_eq!( frame_system::Pallet::::events()[0].event, @@ -956,6 +956,8 @@ fn pallet_hooks_expand() { frame_system::Pallet::::events()[2].event, Event::Example(pallet::Event::Something(30)), ); + + assert_eq!(Example::on_runtime_upgrade(), 30); }) } diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 34586e8414216..a69c51c498056 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -513,7 +513,7 @@ fn pallet_hooks_expand() { assert_eq!(AllPallets::on_initialize(1), 21); AllPallets::on_finalize(1); - assert_eq!(AllPallets::on_runtime_upgrade(), 61); + AllPallets::on_runtime_upgrade(); // The order is indeed reversed due to https://github.com/paritytech/substrate/issues/6280 assert_eq!( @@ -540,6 +540,8 @@ fn pallet_hooks_expand() { frame_system::Pallet::::events()[5].event, Event::Example(pallet::Event::Something(30)), ); + + assert_eq!(<(Example, Instance1Example)>::on_runtime_upgrade(), 61); }) }