From 8b13160035aecf4215bc8a2fbea9676fe9e58718 Mon Sep 17 00:00:00 2001 From: Aki Wu Date: Fri, 17 Jun 2022 16:16:43 +0800 Subject: [PATCH] Avoid duplicate evm transact fees (#136) --- modules/dispatch/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/dispatch/src/lib.rs b/modules/dispatch/src/lib.rs index 834b31c1d..0bb9b566e 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::*; @@ -360,6 +362,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. ///