diff --git a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs index 0713da87a945..a471a2fa55ff 100644 --- a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs +++ b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs @@ -31,6 +31,7 @@ use sp_core::{self, RuntimeDebug}; #[doc(hidden)] pub use sp_std::marker::PhantomData; use sp_std::{self, fmt::Debug, prelude::*}; +use sp_weights::Weight; use tuplex::{PopFront, PushBack}; use super::{DispatchInfoOf, Dispatchable, OriginOf, PostDispatchInfoOf}; @@ -79,6 +80,11 @@ pub trait TransactionExtensionBase: TransactionExtensionInterior { Ok(Self::Implicit::decode(&mut &[][..]).map_err(|_| IndeterminateImplicit)?) } + /// The weight consumed by executing this extension instance fully during transaction dispatch. + fn weight(&self) -> Weight { + Weight::zero() + } + /// Returns the metadata for this extension. /// /// As a [`TransactionExtension`] can be a tuple of [`TransactionExtension`]s we need to return @@ -373,6 +379,11 @@ impl TransactionExtensionBase for Tuple { fn implicit(&self) -> Result { Ok(for_tuples!( ( #( Tuple.implicit()? ),* ) )) } + fn weight(&self) -> Weight { + let mut weight = Weight::zero(); + for_tuples!( #( weight += Tuple.weight(); )* ); + weight + } fn metadata() -> Vec { let mut ids = Vec::new(); for_tuples!( #( ids.extend(Tuple::metadata()); )* ); @@ -461,6 +472,9 @@ impl TransactionExtensionBase for () { fn implicit(&self) -> sp_std::result::Result { Ok(()) } + fn weight(&self) -> Weight { + Weight::zero() + } } impl TransactionExtension for () {