Skip to content

Commit

Permalink
catch ethereum execution info
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Dec 8, 2023
1 parent f5de33c commit 9e2f1b5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = { workspace = true }
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
environmental = { workspace = true }
ethereum = { workspace = true, features = ["with-codec"] }
ethereum-types = { workspace = true }
evm = { workspace = true, features = ["with-codec"] }
Expand Down Expand Up @@ -44,6 +45,7 @@ fp-self-contained = { workspace = true, features = ["default"] }
[features]
default = ["std"]
std = [
"environmental/std",
"ethereum/std",
"evm/std",
"ethereum-types/std",
Expand Down
32 changes: 32 additions & 0 deletions frame/ethereum/src/catch_exec_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0
// This file is part of Frontier.
//
// Copyright (c) 2020-2022 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use fp_evm::CallOrCreateInfo;

environmental::environmental!(GLOBAL: Option<CallOrCreateInfo>);

// Allow to catch informations of an ethereum execution inside the provided closure.
pub fn catch_exec_info<R, F: FnOnce() -> R>(
execution_info: &mut Option<CallOrCreateInfo>,
f: F,
) -> R {
GLOBAL::using(execution_info, f)
}

pub(super) fn fill_exec_info(execution_info: &CallOrCreateInfo) {
GLOBAL::with(|exec_info| exec_info.replace(execution_info.clone()));
}
5 changes: 5 additions & 0 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
#![allow(clippy::comparison_chain, clippy::large_enum_variant)]
#![warn(unused_crate_dependencies)]

mod catch_exec_info;
#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
mod tests;

pub use catch_exec_info::catch_exec_info;

pub use ethereum::{
AccessListItem, BlockV2 as Block, LegacyTransactionMessage, Log, ReceiptV3 as Receipt,
TransactionAction, TransactionV2 as Transaction,
Expand Down Expand Up @@ -572,6 +575,8 @@ impl<T: Config> Pallet<T> {
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let (to, _, info) = Self::execute(source, &transaction, None)?;

catch_exec_info::fill_exec_info(&info);

let pending = Pending::<T>::get();
let transaction_hash = transaction.hash();
let transaction_index = pending.len() as u32;
Expand Down

0 comments on commit 9e2f1b5

Please sign in to comment.