Skip to content

Commit

Permalink
fix: remove generic error from OnCheckEvmTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigoriy Simonov committed Oct 17, 2023
1 parent d48f8a8 commit 213a8c6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 136 deletions.
22 changes: 9 additions & 13 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl<T: Config> Pallet<T> {
let (base_fee, _) = T::FeeCalculator::min_gas_price();
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&origin);

let mut v = CheckEvmTransaction::<InvalidTransactionWrapper>::new(
let mut v = CheckEvmTransaction::new(
who.clone(),
CheckEvmTransactionConfig {
evm_config: T::config(),
Expand All @@ -510,16 +510,14 @@ impl<T: Config> Pallet<T> {
proof_size_base_cost,
);

T::OnCheckEvmTransaction::<InvalidTransactionWrapper>::on_check_evm_transaction(
&mut v, &origin,
)
.map_err(|e| e.0)?;
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &origin)
.map_err(|e| InvalidTransactionWrapper::from(e).0)?;

v.validate_in_pool_for()
v.validate_in_pool()
.and_then(|v| v.with_chain_id())
.and_then(|v| v.with_base_fee())
.and_then(|v| v.with_balance())
.map_err(|e| e.0)?;
.map_err(|e| InvalidTransactionWrapper::from(e).0)?;

// EIP-3607: https://eips.ethereum.org/EIPS/eip-3607
// Do not allow transactions for which `tx.sender` has any code deployed.
Expand Down Expand Up @@ -871,7 +869,7 @@ impl<T: Config> Pallet<T> {
let (base_fee, _) = T::FeeCalculator::min_gas_price();
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&origin);

let mut v = CheckEvmTransaction::<InvalidTransactionWrapper>::new(
let mut v = CheckEvmTransaction::new(
who,
CheckEvmTransactionConfig {
evm_config: T::config(),
Expand All @@ -885,16 +883,14 @@ impl<T: Config> Pallet<T> {
proof_size_base_cost,
);

T::OnCheckEvmTransaction::<InvalidTransactionWrapper>::on_check_evm_transaction(
&mut v, &origin,
)
.map_err(|e| TransactionValidityError::Invalid(e.0))?;
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &origin)
.map_err(|e| TransactionValidityError::Invalid(InvalidTransactionWrapper::from(e).0))?;

v.validate_in_block()
.and_then(|v| v.with_chain_id())
.and_then(|v| v.with_base_fee())
.and_then(|v| v.with_balance())
.map_err(|e| TransactionValidityError::Invalid(e.0))?;
.map_err(|e| TransactionValidityError::Invalid(InvalidTransactionWrapper::from(e).0))?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl pallet_evm::Config for Test {
type SuicideQuickClearLimit = SuicideQuickClearLimit;
type Timestamp = Timestamp;
type WeightInfo = ();
type OnCheckEvmTransaction<E: From<pallet_evm::TransactionValidationError>> = ();
type OnCheckEvmTransaction = ();
}

parameter_types! {
Expand Down
2 changes: 1 addition & 1 deletion frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl pallet_evm::Config for Test {
type GasLimitPovSizeRatio = ();
type Timestamp = Timestamp;
type WeightInfo = ();
type OnCheckEvmTransaction<E: From<pallet_evm::TransactionValidationError>> = ();
type OnCheckEvmTransaction = ();
}

pub(crate) struct MockHandle {
Expand Down
19 changes: 11 additions & 8 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ pub mod pallet {
}

// Called when transaction info for validation is created
type OnCheckEvmTransaction<E: From<TransactionValidationError>>: OnCheckEvmTransaction<
Self,
E,
>;
type OnCheckEvmTransaction: OnCheckEvmTransaction<Self>;
}

#[pallet::call]
Expand Down Expand Up @@ -1097,12 +1094,18 @@ impl<T> OnCreate<T> for Tuple {
}
}

pub trait OnCheckEvmTransaction<T: Config, E: From<TransactionValidationError>> {
fn on_check_evm_transaction(v: &mut CheckEvmTransaction<E>, origin: &H160) -> Result<(), E>;
pub trait OnCheckEvmTransaction<T: Config> {
fn on_check_evm_transaction(
v: &mut CheckEvmTransaction,
origin: &H160,
) -> Result<(), TransactionValidationError>;
}

impl<T: Config, E: From<TransactionValidationError>> OnCheckEvmTransaction<T, E> for () {
fn on_check_evm_transaction(_v: &mut CheckEvmTransaction<E>, _origin: &H160) -> Result<(), E> {
impl<T: Config> OnCheckEvmTransaction<T> for () {
fn on_check_evm_transaction(
_v: &mut CheckEvmTransaction,
_origin: &H160,
) -> Result<(), TransactionValidationError> {
Ok(())
}
}
3 changes: 1 addition & 2 deletions frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use sp_std::{boxed::Box, prelude::*, str::FromStr};
use crate::{
EnsureAddressNever, EnsureAddressRoot, FeeCalculator, IdentityAddressMapping,
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
TransactionValidationError,
};

frame_support::construct_runtime! {
Expand Down Expand Up @@ -156,7 +155,7 @@ impl crate::Config for Test {
type SuicideQuickClearLimit = SuicideQuickClearLimit;
type Timestamp = Timestamp;
type WeightInfo = ();
type OnCheckEvmTransaction<E: From<TransactionValidationError>> = ();
type OnCheckEvmTransaction = ();
}

/// Example PrecompileSet with only Identity precompile.
Expand Down
15 changes: 11 additions & 4 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ where
weight = weight.saturating_add(inner_weight);
let nonce = nonce.unwrap_or(source_account.nonce);

let mut v = fp_evm::CheckEvmTransaction::<Self::Error>::new(
let mut v = fp_evm::CheckEvmTransaction::new(
source_account,
fp_evm::CheckEvmTransactionConfig {
evm_config,
Expand All @@ -402,13 +402,20 @@ where
proof_size_base_cost,
);

T::OnCheckEvmTransaction::<Error<T>>::on_check_evm_transaction(&mut v, &source)
.map_err(|error| RunnerError { error, weight })?;
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &source).map_err(|error| {
RunnerError {
error: error.into(),
weight,
}
})?;

v.validate_in_block()
.and_then(|v| v.with_base_fee())
.and_then(|v| v.with_balance())
.map_err(|error| RunnerError { error, weight })?;
.map_err(|error| RunnerError {
error: error.into(),
weight,
})?;
Ok(())
}

Expand Down
Loading

0 comments on commit 213a8c6

Please sign in to comment.