--- a/pallets/evm-transaction-payment/src/lib.rs +++ b/pallets/evm-transaction-payment/src/lib.rs @@ -20,8 +20,8 @@ use fp_evm::WithdrawReason; use frame_support::traits::{Currency, IsSubType}; pub use pallet::*; -use pallet_evm::{EVMCurrencyAdapter, EnsureAddressOrigin, account::CrossAccountId}; -use sp_core::{H160, U256}; +use pallet_evm::{EnsureAddressOrigin, account::CrossAccountId}; +use sp_core::H160; use sp_runtime::{TransactionOutcome, DispatchError}; use up_sponsorship::SponsorshipHandler; @@ -41,18 +41,6 @@ #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); -} - -type NegativeImbalanceOf = - ::AccountId>>::NegativeImbalance; - -pub struct ChargeEvmLiquidityInfo -where - T: Config, - T: pallet_evm::Config, -{ - who: H160, - negative_imbalance: NegativeImbalanceOf<::Currency, T>, } pub struct TransactionValidityHack(PhantomData<*const T>); @@ -60,69 +48,11 @@ fn who_pays_fee(origin: H160, reason: &WithdrawReason) -> Option { match reason { WithdrawReason::Call { target, input } => { - // This method is only used for checking, we shouldn't touch storage in it - frame_support::storage::with_transaction(|| { - let origin_sub = T::CrossAccountId::from_eth(origin); - TransactionOutcome::Rollback(Ok::<_, DispatchError>( - T::EvmSponsorshipHandler::get_sponsor( - &origin_sub, - &(*target, input.clone()), - ), - )) - }) - // FIXME: it may fail with DispatchError in case of depth limit - .ok()? + let origin_sub = T::CrossAccountId::from_eth(origin); + T::EvmSponsorshipHandler::get_sponsor(&origin_sub, &(*target, input.clone())) } _ => None, } - } -} -pub struct OnChargeTransaction(PhantomData<*const T>); -impl pallet_evm::OnChargeEVMTransaction for OnChargeTransaction -where - T: Config, - T: pallet_evm::Config, -{ - type LiquidityInfo = Option>; - - fn withdraw_fee( - who: &T::CrossAccountId, - reason: WithdrawReason, - fee: U256, - ) -> core::result::Result> { - let who_pays_fee = if let WithdrawReason::Call { target, input } = &reason { - T::EvmSponsorshipHandler::get_sponsor(who, &(*target, input.clone())) - .unwrap_or(who.clone()) - } else { - who.clone() - }; - - let negative_imbalance = EVMCurrencyAdapter::<::Currency, ()>::withdraw_fee( - &who_pays_fee, - reason, - fee, - )?; - - Ok(negative_imbalance.map(|i| ChargeEvmLiquidityInfo { - who: who_pays_fee.as_eth().clone(), - negative_imbalance: i, - })) - } - - fn correct_and_deposit_fee( - who: &T::CrossAccountId, - corrected_fee: U256, - already_withdrawn: Self::LiquidityInfo, - ) { - ::Currency, ()> as pallet_evm::OnChargeEVMTransaction>::correct_and_deposit_fee( - &already_withdrawn.as_ref().map(|e| T::CrossAccountId::from_eth(e.who)).unwrap_or(who.clone()), - corrected_fee, - already_withdrawn.map(|e| e.negative_imbalance), - ) - } - - fn pay_priority_fee(tip: U256) { - ::Currency, ()> as pallet_evm::OnChargeEVMTransaction>::pay_priority_fee(tip) } } @@ -147,7 +77,7 @@ ) .ok()?; let who = T::CrossAccountId::from_sub(who.clone()); - // Effects from EvmSponsorshipHandler are applied in OnChargeEvmTransaction by pallet_evm::runner + // Effects from EvmSponsorshipHandler are applied by pallet_evm::runner // TODO: Should we implement simulation mode (test, but do not apply effects) in `up-sponsorship`? let sponsor = frame_support::storage::with_transaction(|| { TransactionOutcome::Rollback(Ok::<_, DispatchError>( --- a/pallets/unique/src/eth/sponsoring.rs +++ b/pallets/unique/src/eth/sponsoring.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . -//! Implements EVM sponsoring logic via OnChargeEVMTransaction +//! Implements EVM sponsoring logic via TransactionValidityHack use crate::{Config, sponsorship::*}; use evm_coder::{Call, abi::AbiReader}; --- a/runtime/opal/src/lib.rs +++ b/runtime/opal/src/lib.rs @@ -301,7 +301,7 @@ type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate; type ChainId = ChainId; type Runner = pallet_evm::runner::stack::Runner; - type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction; + type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter; type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack; type FindAuthor = EthereumFindAuthor; } --- a/runtime/quartz/src/lib.rs +++ b/runtime/quartz/src/lib.rs @@ -280,7 +280,7 @@ type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate; type ChainId = ChainId; type Runner = pallet_evm::runner::stack::Runner; - type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction; + type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter; type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack; type FindAuthor = EthereumFindAuthor; } --- a/runtime/unique/src/lib.rs +++ b/runtime/unique/src/lib.rs @@ -279,7 +279,7 @@ type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate; type ChainId = ChainId; type Runner = pallet_evm::runner::stack::Runner; - type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction; + type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter; type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack; type FindAuthor = EthereumFindAuthor; }