5959//! # type Context = frame_system::ChainContext<Runtime>;
6060//! # pub type Block = generic::Block<Header, UncheckedExtrinsic>;
6161//! # pub type Balances = u64;
62- //! # pub type AllPallets = u64;
62+ //! # pub type AllPalletsWithSystem = u64;
6363//! # pub enum Runtime {};
6464//! # use sp_runtime::transaction_validity::{
6565//! # TransactionValidity, UnknownTransaction, TransactionSource,
7373//! # }
7474//! # }
7575//! /// Executive: handles dispatch to the various modules.
76- //! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllPallets >;
76+ //! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllPalletsWithSystem >;
7777//! ```
7878//!
7979//! ### Custom `OnRuntimeUpgrade` logic
9090//! # type Context = frame_system::ChainContext<Runtime>;
9191//! # pub type Block = generic::Block<Header, UncheckedExtrinsic>;
9292//! # pub type Balances = u64;
93- //! # pub type AllPallets = u64;
93+ //! # pub type AllPalletsWithSystem = u64;
9494//! # pub enum Runtime {};
9595//! # use sp_runtime::transaction_validity::{
9696//! # TransactionValidity, UnknownTransaction, TransactionSource,
111111//! }
112112//! }
113113//!
114- //! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllPallets , CustomOnRuntimeUpgrade>;
114+ //! pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllPalletsWithSystem , CustomOnRuntimeUpgrade>;
115115//! ```
116116
117117#![ cfg_attr( not( feature = "std" ) , no_std) ]
@@ -147,26 +147,41 @@ pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
147147/// - `Block`: The block type of the runtime
148148/// - `Context`: The context that is used when checking an extrinsic.
149149/// - `UnsignedValidator`: The unsigned transaction validator of the runtime.
150- /// - `AllPallets`: Tuple that contains all modules. Will be used to call e.g. `on_initialize`.
150+ /// - `AllPalletsWithSystem`: Tuple that contains all pallets including frame system pallet. Will be
151+ /// used to call hooks e.g. `on_initialize`.
151152/// - `OnRuntimeUpgrade`: Custom logic that should be called after a runtime upgrade. Modules are
152- /// already called by `AllPallets`. It will be called before all modules will be called.
153- pub struct Executive < System , Block , Context , UnsignedValidator , AllPallets , OnRuntimeUpgrade = ( ) > (
154- PhantomData < ( System , Block , Context , UnsignedValidator , AllPallets , OnRuntimeUpgrade ) > ,
153+ /// already called by `AllPalletsWithSystem`. It will be called before all modules will be called.
154+ pub struct Executive <
155+ System ,
156+ Block ,
157+ Context ,
158+ UnsignedValidator ,
159+ AllPalletsWithSystem ,
160+ OnRuntimeUpgrade = ( ) ,
161+ > (
162+ PhantomData < (
163+ System ,
164+ Block ,
165+ Context ,
166+ UnsignedValidator ,
167+ AllPalletsWithSystem ,
168+ OnRuntimeUpgrade ,
169+ ) > ,
155170) ;
156171
157172impl <
158173 System : frame_system:: Config + EnsureInherentsAreFirst < Block > ,
159174 Block : traits:: Block < Header = System :: Header , Hash = System :: Hash > ,
160175 Context : Default ,
161176 UnsignedValidator ,
162- AllPallets : OnRuntimeUpgrade
177+ AllPalletsWithSystem : OnRuntimeUpgrade
163178 + OnInitialize < System :: BlockNumber >
164179 + OnIdle < System :: BlockNumber >
165180 + OnFinalize < System :: BlockNumber >
166181 + OffchainWorker < System :: BlockNumber > ,
167182 COnRuntimeUpgrade : OnRuntimeUpgrade ,
168183 > ExecuteBlock < Block >
169- for Executive < System , Block , Context , UnsignedValidator , AllPallets , COnRuntimeUpgrade >
184+ for Executive < System , Block , Context , UnsignedValidator , AllPalletsWithSystem , COnRuntimeUpgrade >
170185where
171186 Block :: Extrinsic : Checkable < Context > + Codec ,
172187 CheckedOf < Block :: Extrinsic , Context > : Applyable + GetDispatchInfo ,
@@ -181,7 +196,7 @@ where
181196 Block ,
182197 Context ,
183198 UnsignedValidator ,
184- AllPallets ,
199+ AllPalletsWithSystem ,
185200 COnRuntimeUpgrade ,
186201 > :: execute_block ( block) ;
187202 }
@@ -192,13 +207,13 @@ impl<
192207 Block : traits:: Block < Header = System :: Header , Hash = System :: Hash > ,
193208 Context : Default ,
194209 UnsignedValidator ,
195- AllPallets : OnRuntimeUpgrade
210+ AllPalletsWithSystem : OnRuntimeUpgrade
196211 + OnInitialize < System :: BlockNumber >
197212 + OnIdle < System :: BlockNumber >
198213 + OnFinalize < System :: BlockNumber >
199214 + OffchainWorker < System :: BlockNumber > ,
200215 COnRuntimeUpgrade : OnRuntimeUpgrade ,
201- > Executive < System , Block , Context , UnsignedValidator , AllPallets , COnRuntimeUpgrade >
216+ > Executive < System , Block , Context , UnsignedValidator , AllPalletsWithSystem , COnRuntimeUpgrade >
202217where
203218 Block :: Extrinsic : Checkable < Context > + Codec ,
204219 CheckedOf < Block :: Extrinsic , Context > : Applyable + GetDispatchInfo ,
@@ -209,14 +224,7 @@ where
209224{
210225 /// Execute all `OnRuntimeUpgrade` of this runtime, and return the aggregate weight.
211226 pub fn execute_on_runtime_upgrade ( ) -> frame_support:: weights:: Weight {
212- let mut weight = 0 ;
213- weight = weight. saturating_add ( COnRuntimeUpgrade :: on_runtime_upgrade ( ) ) ;
214- weight = weight. saturating_add (
215- <frame_system:: Pallet < System > as OnRuntimeUpgrade >:: on_runtime_upgrade ( ) ,
216- ) ;
217- weight = weight. saturating_add ( <AllPallets as OnRuntimeUpgrade >:: on_runtime_upgrade ( ) ) ;
218-
219- weight
227+ <( COnRuntimeUpgrade , AllPalletsWithSystem ) as OnRuntimeUpgrade >:: on_runtime_upgrade ( )
220228 }
221229
222230 /// Execute given block, but don't do any of the `final_checks`.
@@ -255,19 +263,10 @@ where
255263 /// This should only be used for testing.
256264 #[ cfg( feature = "try-runtime" ) ]
257265 pub fn try_runtime_upgrade ( ) -> Result < frame_support:: weights:: Weight , & ' static str > {
258- <
259- ( frame_system:: Pallet :: < System > , COnRuntimeUpgrade , AllPallets )
260- as
261- OnRuntimeUpgrade
262- >:: pre_upgrade ( ) . unwrap ( ) ;
263-
266+ <( COnRuntimeUpgrade , AllPalletsWithSystem ) as OnRuntimeUpgrade >:: pre_upgrade ( ) . unwrap ( ) ;
264267 let weight = Self :: execute_on_runtime_upgrade ( ) ;
265268
266- <
267- ( frame_system:: Pallet :: < System > , COnRuntimeUpgrade , AllPallets )
268- as
269- OnRuntimeUpgrade
270- >:: post_upgrade ( ) . unwrap ( ) ;
269+ <( COnRuntimeUpgrade , AllPalletsWithSystem ) as OnRuntimeUpgrade >:: post_upgrade ( ) . unwrap ( ) ;
271270
272271 Ok ( weight)
273272 }
@@ -305,12 +304,9 @@ where
305304 digest,
306305 frame_system:: InitKind :: Full ,
307306 ) ;
308- weight = weight. saturating_add ( <frame_system :: Pallet < System > as OnInitialize <
307+ weight = weight. saturating_add ( <AllPalletsWithSystem as OnInitialize <
309308 System :: BlockNumber ,
310309 > >:: on_initialize ( * block_number) ) ;
311- weight = weight. saturating_add (
312- <AllPallets as OnInitialize < System :: BlockNumber > >:: on_initialize ( * block_number) ,
313- ) ;
314310 weight = weight. saturating_add (
315311 <System :: BlockWeights as frame_support:: traits:: Get < _ > >:: get ( ) . base_block ,
316312 ) ;
@@ -415,30 +411,20 @@ where
415411 fn idle_and_finalize_hook ( block_number : NumberFor < Block > ) {
416412 let weight = <frame_system:: Pallet < System > >:: block_weight ( ) ;
417413 let max_weight = <System :: BlockWeights as frame_support:: traits:: Get < _ > >:: get ( ) . max_block ;
418- let mut remaining_weight = max_weight. saturating_sub ( weight. total ( ) ) ;
414+ let remaining_weight = max_weight. saturating_sub ( weight. total ( ) ) ;
419415
420416 if remaining_weight > 0 {
421- let mut used_weight =
422- <frame_system:: Pallet < System > as OnIdle < System :: BlockNumber > >:: on_idle (
423- block_number,
424- remaining_weight,
425- ) ;
426- remaining_weight = remaining_weight. saturating_sub ( used_weight) ;
427- used_weight = <AllPallets as OnIdle < System :: BlockNumber > >:: on_idle (
417+ let used_weight = <AllPalletsWithSystem as OnIdle < System :: BlockNumber > >:: on_idle (
428418 block_number,
429419 remaining_weight,
430- )
431- . saturating_add ( used_weight) ;
420+ ) ;
432421 <frame_system:: Pallet < System > >:: register_extra_weight_unchecked (
433422 used_weight,
434423 DispatchClass :: Mandatory ,
435424 ) ;
436425 }
437426
438- <frame_system:: Pallet < System > as OnFinalize < System :: BlockNumber > >:: on_finalize (
439- block_number,
440- ) ;
441- <AllPallets as OnFinalize < System :: BlockNumber > >:: on_finalize ( block_number) ;
427+ <AllPalletsWithSystem as OnFinalize < System :: BlockNumber > >:: on_finalize ( block_number) ;
442428 }
443429
444430 /// Apply extrinsic outside of the block execution function.
@@ -567,7 +553,9 @@ where
567553 // as well.
568554 frame_system:: BlockHash :: < System > :: insert ( header. number ( ) , header. hash ( ) ) ;
569555
570- <AllPallets as OffchainWorker < System :: BlockNumber > >:: offchain_worker ( * header. number ( ) )
556+ <AllPalletsWithSystem as OffchainWorker < System :: BlockNumber > >:: offchain_worker (
557+ * header. number ( ) ,
558+ )
571559 }
572560}
573561
@@ -849,7 +837,7 @@ mod tests {
849837 Block < TestXt > ,
850838 ChainContext < Runtime > ,
851839 Runtime ,
852- AllPallets ,
840+ AllPalletsWithSystem ,
853841 CustomOnRuntimeUpgrade ,
854842 > ;
855843
@@ -1360,23 +1348,19 @@ mod tests {
13601348 ) ) ;
13611349
13621350 // All weights that show up in the `initialize_block_impl`
1363- let frame_system_upgrade_weight = frame_system:: Pallet :: < Runtime > :: on_runtime_upgrade ( ) ;
13641351 let custom_runtime_upgrade_weight = CustomOnRuntimeUpgrade :: on_runtime_upgrade ( ) ;
1365- let runtime_upgrade_weight = <AllPallets as OnRuntimeUpgrade >:: on_runtime_upgrade ( ) ;
1366- let frame_system_on_initialize_weight =
1367- frame_system:: Pallet :: < Runtime > :: on_initialize ( block_number) ;
1352+ let runtime_upgrade_weight =
1353+ <AllPalletsWithSystem as OnRuntimeUpgrade >:: on_runtime_upgrade ( ) ;
13681354 let on_initialize_weight =
1369- <AllPallets as OnInitialize < u64 > >:: on_initialize ( block_number) ;
1355+ <AllPalletsWithSystem as OnInitialize < u64 > >:: on_initialize ( block_number) ;
13701356 let base_block_weight =
13711357 <Runtime as frame_system:: Config >:: BlockWeights :: get ( ) . base_block ;
13721358
13731359 // Weights are recorded correctly
13741360 assert_eq ! (
13751361 frame_system:: Pallet :: <Runtime >:: block_weight( ) . total( ) ,
1376- frame_system_upgrade_weight +
1377- custom_runtime_upgrade_weight +
1362+ custom_runtime_upgrade_weight +
13781363 runtime_upgrade_weight +
1379- frame_system_on_initialize_weight +
13801364 on_initialize_weight + base_block_weight,
13811365 ) ;
13821366 } ) ;
0 commit comments