diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index ac404c5b3..27b15428d 100644 --- a/modules/dispatch/src/lib.rs +++ b/modules/dispatch/src/lib.rs @@ -38,10 +38,12 @@ use frame_support::{ dispatch::Dispatchable, ensure, traits::Get, - weights::{extract_actual_weight, GetDispatchInfo}, + weights::GetDispatchInfo, }; +use frame_support::dispatch::{DispatchInfo, DispatchResultWithPostInfo, Weight}; +use frame_support::pallet_prelude::Pays; use frame_system::RawOrigin; -use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify}; +use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify, Zero}; use sp_std::{fmt::Debug, prelude::*}; pub use pallet::*; @@ -370,6 +372,17 @@ impl, I: 'static> MessageDispatch } } +fn extract_actual_weight(result: &DispatchResultWithPostInfo, info: &DispatchInfo) -> Weight { + let post_info = match result { + Ok(post_info) => &post_info, + Err(err) => &err.post_info, + }; + match post_info.pays_fee { + Pays::Yes => post_info.calc_actual_weight(info), + Pays::No => Weight::zero() + } +} + /// Check if the message is allowed to be dispatched on the target chain given the sender's origin /// on the source chain. ///