Skip to content

Commit c4a518a

Browse files
[backport] Add CallOrCreateInfo to ValidatedTransaction apply result. (polkadot-evm#1099) (#158)
Add `CallOrCreateInfo` to `ValidatedTransaction` apply result. (polkadot-evm#1099) * Add 'CallOrCreateInfo' to 'ValidatedTransaction' apply result. * fmt Co-authored-by: Shaun Wang <spxwang@gmail.com>
1 parent 53de160 commit c4a518a

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

frame/ethereum/src/lib.rs

+32-27
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ use fp_evm::{
4242
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
4343
use frame_support::{
4444
codec::{Decode, Encode, MaxEncodedLen},
45-
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
45+
dispatch::{
46+
DispatchErrorWithPostInfo, DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo,
47+
},
4648
scale_info::TypeInfo,
4749
traits::{EnsureOrigin, Get, PalletInfoAccess, Time},
4850
weights::Weight,
@@ -55,7 +57,7 @@ use sp_runtime::{
5557
transaction_validity::{
5658
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
5759
},
58-
DispatchErrorWithPostInfo, RuntimeDebug, SaturatedConversion,
60+
RuntimeDebug, SaturatedConversion,
5961
};
6062
use sp_std::{marker::PhantomData, prelude::*};
6163

@@ -241,7 +243,7 @@ pub mod pallet {
241243
Self::validate_transaction_in_block(source, &transaction).expect(
242244
"pre-block transaction verification failed; the block cannot be built",
243245
);
244-
let r = Self::apply_validated_transaction(source, transaction)
246+
let (r, _) = Self::apply_validated_transaction(source, transaction)
245247
.expect("pre-block apply transaction failed; the block cannot be built");
246248

247249
weight = weight.saturating_add(r.actual_weight.unwrap_or_default());
@@ -290,7 +292,7 @@ pub mod pallet {
290292
"pre log already exists; block is invalid",
291293
);
292294

293-
Self::apply_validated_transaction(source, transaction)
295+
Self::apply_validated_transaction(source, transaction).map(|(post_info, _)| post_info)
294296
}
295297
}
296298

@@ -558,14 +560,14 @@ impl<T: Config> Pallet<T> {
558560
fn apply_validated_transaction(
559561
source: H160,
560562
transaction: Transaction,
561-
) -> DispatchResultWithPostInfo {
563+
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
562564
let (to, _, info) = Self::execute(source, &transaction, None)?;
563565

564566
let pending = Pending::<T>::get();
565567
let transaction_hash = transaction.hash();
566568
let transaction_index = pending.len() as u32;
567569

568-
let (reason, status, weight_info, used_gas, dest, extra_data) = match info {
570+
let (reason, status, weight_info, used_gas, dest, extra_data) = match info.clone() {
569571
CallOrCreateInfo::Call(info) => (
570572
info.exit_reason.clone(),
571573
TransactionStatus {
@@ -680,24 +682,27 @@ impl<T: Config> Pallet<T> {
680682
extra_data,
681683
});
682684

683-
Ok(PostDispatchInfo {
684-
actual_weight: {
685-
let mut gas_to_weight = T::GasWeightMapping::gas_to_weight(
686-
sp_std::cmp::max(
687-
used_gas.standard.unique_saturated_into(),
688-
used_gas.effective.unique_saturated_into(),
689-
),
690-
true,
691-
);
692-
if let Some(weight_info) = weight_info {
693-
if let Some(proof_size_usage) = weight_info.proof_size_usage {
694-
*gas_to_weight.proof_size_mut() = proof_size_usage;
685+
Ok((
686+
PostDispatchInfo {
687+
actual_weight: {
688+
let mut gas_to_weight = T::GasWeightMapping::gas_to_weight(
689+
sp_std::cmp::max(
690+
used_gas.standard.unique_saturated_into(),
691+
used_gas.effective.unique_saturated_into(),
692+
),
693+
true,
694+
);
695+
if let Some(weight_info) = weight_info {
696+
if let Some(proof_size_usage) = weight_info.proof_size_usage {
697+
*gas_to_weight.proof_size_mut() = proof_size_usage;
698+
}
695699
}
696-
}
697-
Some(gas_to_weight)
700+
Some(gas_to_weight)
701+
},
702+
pays_fee: Pays::No,
698703
},
699-
pays_fee: Pays::No,
700-
})
704+
info,
705+
))
701706
}
702707

703708
/// Get current block hash
@@ -710,10 +715,7 @@ impl<T: Config> Pallet<T> {
710715
from: H160,
711716
transaction: &Transaction,
712717
config: Option<evm::Config>,
713-
) -> Result<
714-
(Option<H160>, Option<H160>, CallOrCreateInfo),
715-
DispatchErrorWithPostInfo<PostDispatchInfo>,
716-
> {
718+
) -> Result<(Option<H160>, Option<H160>, CallOrCreateInfo), DispatchErrorWithPostInfo> {
717719
let (
718720
input,
719721
value,
@@ -966,7 +968,10 @@ impl<T: Config> Pallet<T> {
966968

967969
pub struct ValidatedTransaction<T>(PhantomData<T>);
968970
impl<T: Config> ValidatedTransactionT for ValidatedTransaction<T> {
969-
fn apply(source: H160, transaction: Transaction) -> DispatchResultWithPostInfo {
971+
fn apply(
972+
source: H160,
973+
transaction: Transaction,
974+
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
970975
Pallet::<T>::apply_validated_transaction(source, transaction)
971976
}
972977
}

primitives/ethereum/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ pub use ethereum::{
2323
TransactionAction, TransactionV2 as Transaction,
2424
};
2525
use ethereum_types::{H160, H256, U256};
26-
use fp_evm::CheckEvmTransactionInput;
26+
use fp_evm::{CallOrCreateInfo, CheckEvmTransactionInput};
27+
use frame_support::dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo};
2728
use scale_codec::{Decode, Encode};
28-
use sp_std::vec::Vec;
29+
use sp_std::{result::Result, vec::Vec};
2930

3031
#[repr(u8)]
3132
#[derive(num_enum::FromPrimitive, num_enum::IntoPrimitive)]
@@ -44,7 +45,7 @@ pub trait ValidatedTransaction {
4445
fn apply(
4546
source: H160,
4647
transaction: Transaction,
47-
) -> frame_support::dispatch::DispatchResultWithPostInfo;
48+
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo>;
4849
}
4950

5051
#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)]

0 commit comments

Comments
 (0)