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 Sep 11, 2023
1 parent e13a219 commit 2ed134d
Show file tree
Hide file tree
Showing 9 changed files with 124 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 @@ -492,7 +492,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 @@ -506,16 +506,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 @@ -867,7 +865,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 @@ -881,16 +879,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 @@ -180,7 +180,7 @@ impl pallet_evm::Config for Test {
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
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 @@ -166,7 +166,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 @@ -179,10 +179,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 @@ -1054,12 +1051,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 @@ -33,7 +33,6 @@ use sp_std::{boxed::Box, prelude::*, str::FromStr};
use crate::{
EnsureAddressNever, EnsureAddressRoot, FeeCalculator, IdentityAddressMapping,
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
TransactionValidationError,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down Expand Up @@ -163,7 +162,7 @@ impl crate::Config for Test {
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
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
1 change: 1 addition & 0 deletions precompiles/tests-external/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ mod tests {
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type Timestamp = Timestamp;
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
type OnCheckEvmTransaction = ();
}

parameter_types! {
Expand Down
Loading

0 comments on commit 2ed134d

Please sign in to comment.