@@ -61,10 +61,7 @@ extern crate alloc;
6161use alloc:: { boxed:: Box , vec:: Vec } ;
6262use codec:: { Decode , Encode } ;
6363use frame_support:: {
64- dispatch:: {
65- DispatchClass :: { Normal , Operational } ,
66- GetDispatchInfo , PostDispatchInfo , extract_actual_weight,
67- } ,
64+ dispatch:: { GetDispatchInfo , PostDispatchInfo , extract_actual_weight} ,
6865 traits:: { IsSubType , OriginTrait , UnfilteredDispatchable } ,
6966} ;
7067use sp_core:: TypeId ;
@@ -198,9 +195,9 @@ pub mod pallet {
198195 /// event is deposited.
199196 #[ pallet:: call_index( 0 ) ]
200197 #[ pallet:: weight( {
201- let ( dispatch_weight, dispatch_class , pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
198+ let ( dispatch_weight, pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
202199 let dispatch_weight = dispatch_weight. saturating_add( T :: WeightInfo :: batch( calls. len( ) as u32 ) ) ;
203- ( dispatch_weight, dispatch_class , pays)
200+ ( dispatch_weight, DispatchClass :: Normal , pays)
204201 } ) ]
205202 pub fn batch (
206203 origin : OriginFor < T > ,
@@ -268,7 +265,7 @@ pub mod pallet {
268265 // AccountData for inner call origin accountdata.
269266 . saturating_add( T :: DbWeight :: get( ) . reads_writes( 1 , 1 ) )
270267 . saturating_add( dispatch_info. call_weight) ,
271- dispatch_info . class ,
268+ DispatchClass :: Normal ,
272269 )
273270 } ) ]
274271 pub fn as_derivative (
@@ -310,9 +307,9 @@ pub mod pallet {
310307 /// - O(C) where C is the number of calls to be batched.
311308 #[ pallet:: call_index( 2 ) ]
312309 #[ pallet:: weight( {
313- let ( dispatch_weight, dispatch_class , pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
310+ let ( dispatch_weight, pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
314311 let dispatch_weight = dispatch_weight. saturating_add( T :: WeightInfo :: batch_all( calls. len( ) as u32 ) ) ;
315- ( dispatch_weight, dispatch_class , pays)
312+ ( dispatch_weight, DispatchClass :: Normal , pays)
316313 } ) ]
317314 pub fn batch_all (
318315 origin : OriginFor < T > ,
@@ -376,7 +373,7 @@ pub mod pallet {
376373 (
377374 T :: WeightInfo :: dispatch_as( )
378375 . saturating_add( dispatch_info. call_weight) ,
379- dispatch_info . class ,
376+ DispatchClass :: Normal ,
380377 )
381378 } ) ]
382379 pub fn dispatch_as (
@@ -409,9 +406,9 @@ pub mod pallet {
409406 /// - O(C) where C is the number of calls to be batched.
410407 #[ pallet:: call_index( 4 ) ]
411408 #[ pallet:: weight( {
412- let ( dispatch_weight, dispatch_class , pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
409+ let ( dispatch_weight, pays) = Pallet :: <T >:: weight_and_dispatch_class( calls) ;
413410 let dispatch_weight = dispatch_weight. saturating_add( T :: WeightInfo :: force_batch( calls. len( ) as u32 ) ) ;
414- ( dispatch_weight, dispatch_class , pays)
411+ ( dispatch_weight, DispatchClass :: Normal , pays)
415412 } ) ]
416413 pub fn force_batch (
417414 origin : OriginFor < T > ,
@@ -466,7 +463,7 @@ pub mod pallet {
466463 ///
467464 /// The dispatch origin for this call must be _Root_.
468465 #[ pallet:: call_index( 5 ) ]
469- #[ pallet:: weight( ( * weight, call . get_dispatch_info ( ) . class ) ) ]
466+ #[ pallet:: weight( ( * weight, DispatchClass :: Normal ) ) ]
470467 pub fn with_weight (
471468 origin : OriginFor < T > ,
472469 call : Box < <T as Config >:: RuntimeCall > ,
@@ -510,7 +507,7 @@ pub mod pallet {
510507 T :: WeightInfo :: if_else( )
511508 . saturating_add( main. call_weight)
512509 . saturating_add( fallback. call_weight) ,
513- if main . class == Operational && fallback . class == Operational { Operational } else { Normal } ,
510+ DispatchClass :: Normal ,
514511 )
515512 } ) ]
516513 pub fn if_else (
@@ -584,7 +581,7 @@ pub mod pallet {
584581 (
585582 T :: WeightInfo :: dispatch_as_fallible( )
586583 . saturating_add( dispatch_info. call_weight) ,
587- dispatch_info . class ,
584+ DispatchClass :: Normal ,
588585 )
589586 } ) ]
590587 pub fn dispatch_as_fallible (
@@ -604,32 +601,20 @@ pub mod pallet {
604601 }
605602
606603 impl < T : Config > Pallet < T > {
607- /// Get the accumulated `weight` and the dispatch class for the given `calls`.
608- fn weight_and_dispatch_class (
609- calls : & [ <T as Config >:: RuntimeCall ] ,
610- ) -> ( Weight , DispatchClass , Pays ) {
611- let dispatch_infos = calls. iter ( ) . map ( |call| call. get_dispatch_info ( ) ) ;
612- let pays = if dispatch_infos. clone ( ) . any ( |di| di. pays_fee == Pays :: No ) {
613- Pays :: No
614- } else {
615- Pays :: Yes
616- } ;
617- let ( dispatch_weight, dispatch_class) = dispatch_infos. fold (
618- ( Weight :: zero ( ) , DispatchClass :: Operational ) ,
619- |( total_weight, dispatch_class) : ( Weight , DispatchClass ) , di| {
620- (
621- total_weight. saturating_add ( di. call_weight ) ,
622- // If not all are `Operational`, we want to use `DispatchClass::Normal`.
623- if di. class == DispatchClass :: Normal {
624- di. class
625- } else {
626- dispatch_class
627- } ,
628- )
629- } ,
630- ) ;
604+ /// Get the accumulated `weight` and `pays` for the given `calls`.
605+ /// The outer dispatch class is intentionally always `Normal`.
606+ fn weight_and_dispatch_class ( calls : & [ <T as Config >:: RuntimeCall ] ) -> ( Weight , Pays ) {
607+ let mut total_weight = Weight :: zero ( ) ;
608+ let mut pays = Pays :: No ;
609+
610+ for di in calls. iter ( ) . map ( |call| call. get_dispatch_info ( ) ) {
611+ total_weight = total_weight. saturating_add ( di. call_weight ) ;
612+ if di. pays_fee == Pays :: Yes {
613+ pays = Pays :: Yes ;
614+ }
615+ }
631616
632- ( dispatch_weight , dispatch_class , pays)
617+ ( total_weight , pays)
633618 }
634619 }
635620}
0 commit comments