Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Avoid duplicate evm transact fees #136

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -360,6 +362,17 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
}
}

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.
///
Expand Down