difftreelog
refactor move evm sponsoring effects to validity
in: master
5 files changed
pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth--- 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<T>(_);
-}
-
-type NegativeImbalanceOf<C, T> =
- <C as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
-
-pub struct ChargeEvmLiquidityInfo<T>
-where
- T: Config,
- T: pallet_evm::Config,
-{
- who: H160,
- negative_imbalance: NegativeImbalanceOf<<T as Config>::Currency, T>,
}
pub struct TransactionValidityHack<T: Config>(PhantomData<*const T>);
@@ -60,69 +48,11 @@
fn who_pays_fee(origin: H160, reason: &WithdrawReason) -> Option<T::CrossAccountId> {
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<T: Config>(PhantomData<*const T>);
-impl<T> pallet_evm::OnChargeEVMTransaction<T> for OnChargeTransaction<T>
-where
- T: Config,
- T: pallet_evm::Config,
-{
- type LiquidityInfo = Option<ChargeEvmLiquidityInfo<T>>;
-
- fn withdraw_fee(
- who: &T::CrossAccountId,
- reason: WithdrawReason,
- fee: U256,
- ) -> core::result::Result<Self::LiquidityInfo, pallet_evm::Error<T>> {
- 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::<<T as Config>::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,
- ) {
- <EVMCurrencyAdapter<<T as Config>::Currency, ()> as pallet_evm::OnChargeEVMTransaction<T>>::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) {
- <EVMCurrencyAdapter<<T as Config>::Currency, ()> as pallet_evm::OnChargeEVMTransaction<T>>::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>(
pallets/unique/src/eth/sponsoring.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617//! Implements EVM sponsoring logic via OnChargeEVMTransaction17//! Implements EVM sponsoring logic via TransactionValidityHack181819use crate::{Config, sponsorship::*};19use crate::{Config, sponsorship::*};20use evm_coder::{Call, abi::AbiReader};20use evm_coder::{Call, abi::AbiReader};runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -301,7 +301,7 @@
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
type ChainId = ChainId;
type Runner = pallet_evm::runner::stack::Runner<Self>;
- type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;
+ type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;
type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;
type FindAuthor = EthereumFindAuthor<Aura>;
}
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -280,7 +280,7 @@
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
type ChainId = ChainId;
type Runner = pallet_evm::runner::stack::Runner<Self>;
- type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;
+ type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;
type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;
type FindAuthor = EthereumFindAuthor<Aura>;
}
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -279,7 +279,7 @@
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
type ChainId = ChainId;
type Runner = pallet_evm::runner::stack::Runner<Self>;
- type OnChargeTransaction = pallet_evm_transaction_payment::OnChargeTransaction<Self>;
+ type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees>;
type TransactionValidityHack = pallet_evm_transaction_payment::TransactionValidityHack<Self>;
type FindAuthor = EthereumFindAuthor<Aura>;
}