Skip to content

Commit 07cf3bd

Browse files
author
Grigoriy Simonov
committed
fix: remove generic error from OnCheckEvmTransaction
1 parent 6c79fbe commit 07cf3bd

File tree

9 files changed

+124
-136
lines changed

9 files changed

+124
-136
lines changed

frame/ethereum/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<T: Config> Pallet<T> {
492492
let (base_fee, _) = T::FeeCalculator::min_gas_price();
493493
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&origin);
494494

495-
let mut v = CheckEvmTransaction::<InvalidTransactionWrapper>::new(
495+
let mut v = CheckEvmTransaction::new(
496496
who.clone(),
497497
CheckEvmTransactionConfig {
498498
evm_config: T::config(),
@@ -506,16 +506,14 @@ impl<T: Config> Pallet<T> {
506506
proof_size_base_cost,
507507
);
508508

509-
T::OnCheckEvmTransaction::<InvalidTransactionWrapper>::on_check_evm_transaction(
510-
&mut v, &origin,
511-
)
512-
.map_err(|e| e.0)?;
509+
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &origin)
510+
.map_err(|e| InvalidTransactionWrapper::from(e).0)?;
513511

514-
v.validate_in_pool_for()
512+
v.validate_in_pool()
515513
.and_then(|v| v.with_chain_id())
516514
.and_then(|v| v.with_base_fee())
517515
.and_then(|v| v.with_balance())
518-
.map_err(|e| e.0)?;
516+
.map_err(|e| InvalidTransactionWrapper::from(e).0)?;
519517

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

870-
let mut v = CheckEvmTransaction::<InvalidTransactionWrapper>::new(
868+
let mut v = CheckEvmTransaction::new(
871869
who,
872870
CheckEvmTransactionConfig {
873871
evm_config: T::config(),
@@ -881,16 +879,14 @@ impl<T: Config> Pallet<T> {
881879
proof_size_base_cost,
882880
);
883881

884-
T::OnCheckEvmTransaction::<InvalidTransactionWrapper>::on_check_evm_transaction(
885-
&mut v, &origin,
886-
)
887-
.map_err(|e| TransactionValidityError::Invalid(e.0))?;
882+
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &origin)
883+
.map_err(|e| TransactionValidityError::Invalid(InvalidTransactionWrapper::from(e).0))?;
888884

889885
v.validate_in_block()
890886
.and_then(|v| v.with_chain_id())
891887
.and_then(|v| v.with_base_fee())
892888
.and_then(|v| v.with_balance())
893-
.map_err(|e| TransactionValidityError::Invalid(e.0))?;
889+
.map_err(|e| TransactionValidityError::Invalid(InvalidTransactionWrapper::from(e).0))?;
894890

895891
Ok(())
896892
}

frame/ethereum/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl pallet_evm::Config for Test {
180180
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
181181
type Timestamp = Timestamp;
182182
type WeightInfo = ();
183-
type OnCheckEvmTransaction<E: From<pallet_evm::TransactionValidationError>> = ();
183+
type OnCheckEvmTransaction = ();
184184
}
185185

186186
parameter_types! {

frame/evm/precompile/dispatch/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl pallet_evm::Config for Test {
166166
type GasLimitPovSizeRatio = ();
167167
type Timestamp = Timestamp;
168168
type WeightInfo = ();
169-
type OnCheckEvmTransaction<E: From<pallet_evm::TransactionValidationError>> = ();
169+
type OnCheckEvmTransaction = ();
170170
}
171171

172172
pub(crate) struct MockHandle {

frame/evm/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ pub mod pallet {
179179
}
180180

181181
// Called when transaction info for validation is created
182-
type OnCheckEvmTransaction<E: From<TransactionValidationError>>: OnCheckEvmTransaction<
183-
Self,
184-
E,
185-
>;
182+
type OnCheckEvmTransaction: OnCheckEvmTransaction<Self>;
186183
}
187184

188185
#[pallet::call]
@@ -1054,12 +1051,18 @@ impl<T> OnCreate<T> for Tuple {
10541051
}
10551052
}
10561053

1057-
pub trait OnCheckEvmTransaction<T: Config, E: From<TransactionValidationError>> {
1058-
fn on_check_evm_transaction(v: &mut CheckEvmTransaction<E>, origin: &H160) -> Result<(), E>;
1054+
pub trait OnCheckEvmTransaction<T: Config> {
1055+
fn on_check_evm_transaction(
1056+
v: &mut CheckEvmTransaction,
1057+
origin: &H160,
1058+
) -> Result<(), TransactionValidationError>;
10591059
}
10601060

1061-
impl<T: Config, E: From<TransactionValidationError>> OnCheckEvmTransaction<T, E> for () {
1062-
fn on_check_evm_transaction(_v: &mut CheckEvmTransaction<E>, _origin: &H160) -> Result<(), E> {
1061+
impl<T: Config> OnCheckEvmTransaction<T> for () {
1062+
fn on_check_evm_transaction(
1063+
_v: &mut CheckEvmTransaction,
1064+
_origin: &H160,
1065+
) -> Result<(), TransactionValidationError> {
10631066
Ok(())
10641067
}
10651068
}

frame/evm/src/mock.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use sp_std::{boxed::Box, prelude::*, str::FromStr};
3333
use crate::{
3434
EnsureAddressNever, EnsureAddressRoot, FeeCalculator, IdentityAddressMapping,
3535
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
36-
TransactionValidationError,
3736
};
3837

3938
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
@@ -163,7 +162,7 @@ impl crate::Config for Test {
163162
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
164163
type Timestamp = Timestamp;
165164
type WeightInfo = ();
166-
type OnCheckEvmTransaction<E: From<TransactionValidationError>> = ();
165+
type OnCheckEvmTransaction = ();
167166
}
168167

169168
/// Example PrecompileSet with only Identity precompile.

frame/evm/src/runner/stack.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ where
377377
weight = weight.saturating_add(inner_weight);
378378
let nonce = nonce.unwrap_or(source_account.nonce);
379379

380-
let mut v = fp_evm::CheckEvmTransaction::<Self::Error>::new(
380+
let mut v = fp_evm::CheckEvmTransaction::new(
381381
source_account,
382382
fp_evm::CheckEvmTransactionConfig {
383383
evm_config,
@@ -402,13 +402,20 @@ where
402402
proof_size_base_cost,
403403
);
404404

405-
T::OnCheckEvmTransaction::<Error<T>>::on_check_evm_transaction(&mut v, &source)
406-
.map_err(|error| RunnerError { error, weight })?;
405+
T::OnCheckEvmTransaction::on_check_evm_transaction(&mut v, &source).map_err(|error| {
406+
RunnerError {
407+
error: error.into(),
408+
weight,
409+
}
410+
})?;
407411

408412
v.validate_in_block()
409413
.and_then(|v| v.with_base_fee())
410414
.and_then(|v| v.with_balance())
411-
.map_err(|error| RunnerError { error, weight })?;
415+
.map_err(|error| RunnerError {
416+
error: error.into(),
417+
weight,
418+
})?;
412419
Ok(())
413420
}
414421

precompiles/tests-external/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ mod tests {
254254
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
255255
type Timestamp = Timestamp;
256256
type WeightInfo = pallet_evm::weights::SubstrateWeight<Runtime>;
257+
type OnCheckEvmTransaction = ();
257258
}
258259

259260
parameter_types! {

0 commit comments

Comments
 (0)