From 7309b2bd3aba82a57dd27aa2c0df3a22229f661f Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 11:59:39 +0000 Subject: [PATCH 01/11] Improve tracing logs and fix the transaction indexes in evm traces --- .../evm-tracing/src/formatters/call_tracer.rs | 12 ++++--- .../src/formatters/trace_filter.rs | 12 ++++--- client/rpc/trace/src/lib.rs | 4 ++- runtime/common/src/apis.rs | 31 ++++++++++++++++--- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/client/evm-tracing/src/formatters/call_tracer.rs b/client/evm-tracing/src/formatters/call_tracer.rs index ce9b833a2a..8a041be5cc 100644 --- a/client/evm-tracing/src/formatters/call_tracer.rs +++ b/client/evm-tracing/src/formatters/call_tracer.rs @@ -36,12 +36,16 @@ impl super::ResponseFormatter for Formatter { type Listener = Listener; type Response = Vec; - fn format(mut listener: Listener) -> Option> { - // Remove empty BTreeMaps pushed to `entries`. - // I.e. InvalidNonce or other pallet_evm::runner exits - listener.entries.retain(|x| !x.is_empty()); + fn format(listener: Listener) -> Option> { let mut traces = Vec::new(); for (eth_tx_index, entry) in listener.entries.iter().enumerate() { + if entry.is_empty() { + log::debug!( + target: "tracing", + "Empty trace entry with transaction index {}, skipping...", eth_tx_index + ); + continue; + } let mut result: Vec = entry .into_iter() .map(|(_, it)| { diff --git a/client/evm-tracing/src/formatters/trace_filter.rs b/client/evm-tracing/src/formatters/trace_filter.rs index 27dff285fd..109abf7f64 100644 --- a/client/evm-tracing/src/formatters/trace_filter.rs +++ b/client/evm-tracing/src/formatters/trace_filter.rs @@ -30,12 +30,16 @@ impl super::ResponseFormatter for Formatter { type Listener = Listener; type Response = Vec; - fn format(mut listener: Listener) -> Option> { - // Remove empty BTreeMaps pushed to `entries`. - // I.e. InvalidNonce or other pallet_evm::runner exits - listener.entries.retain(|x| !x.is_empty()); + fn format(listener: Listener) -> Option> { let mut traces = Vec::new(); for (eth_tx_index, entry) in listener.entries.iter().enumerate() { + if entry.is_empty() { + log::debug!( + target: "tracing", + "Empty trace entry with transaction index {}, skipping...", eth_tx_index + ); + continue; + } let mut tx_traces: Vec<_> = entry .into_iter() .map(|(_, trace)| match trace.inner.clone() { diff --git a/client/rpc/trace/src/lib.rs b/client/rpc/trace/src/lib.rs index 79c84f8160..fef940efc6 100644 --- a/client/rpc/trace/src/lib.rs +++ b/client/rpc/trace/src/lib.rs @@ -803,7 +803,7 @@ where substrate_hash, e ) })? - .ok_or_else(|| format!("Subtrate block {} don't exist", substrate_hash))?; + .ok_or_else(|| format!("Substrate block {} don't exist", substrate_hash))?; let height = *block_header.number(); let substrate_parent_hash = *block_header.parent_hash(); @@ -890,6 +890,7 @@ where .map_err(|e| format!("Blockchain error when replaying block {} : {:?}", height, e))? .map_err(|e| { tracing::warn!( + target: "tracing", "Internal runtime error when replaying block {} : {:?}", height, e @@ -935,6 +936,7 @@ where } None => { log::warn!( + target: "tracing", "A trace in block {} does not map to any known ethereum transaction. Trace: {:?}", height, trace, diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 61f8332d3d..39e49d6cde 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -249,16 +249,39 @@ macro_rules! impl_runtime_apis_plus_common { for ext in extrinsics.into_iter() { match &ext.0.function { RuntimeCall::Ethereum(transact { transaction }) => { - if known_transactions.contains(&transaction.hash()) { + let tx_hash = &transaction.hash(); + if known_transactions.contains(&tx_hash) { // Each known extrinsic is a new call stack. EvmTracer::emit_new(); - EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); + EvmTracer::new().trace(|| { + if let Err(err) = Executive::apply_extrinsic(ext) { + log::debug!( + target: "tracing", + "Could not trace eth transaction (hash: {}): {:?}", + &tx_hash, + err + ); + } + }); } else { - let _ = Executive::apply_extrinsic(ext); + if let Err(err) = Executive::apply_extrinsic(ext) { + log::debug!( + target: "tracing", + "Failed to apply eth extrinsic (hash: {}): {:?}", + &tx_hash, + err + ); + } } } _ => { - let _ = Executive::apply_extrinsic(ext); + if let Err(err) = Executive::apply_extrinsic(ext) { + log::debug!( + target: "tracing", + "Failed to apply non-eth extrinsic: {:?}", + err + ); + } } }; } From a58f24ae253b0f89727aacfee5bd5695da86bc0d Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 13:40:26 +0000 Subject: [PATCH 02/11] fix block weight limits in evm tracing runtimes --- runtime/common/src/compilation_checks.rs | 34 ++++++++++++++++++++++++ runtime/common/src/lib.rs | 1 + runtime/moonbase/src/lib.rs | 7 +++++ runtime/moonbeam/src/lib.rs | 7 +++++ runtime/moonriver/src/lib.rs | 7 +++++ 5 files changed, 56 insertions(+) create mode 100644 runtime/common/src/compilation_checks.rs diff --git a/runtime/common/src/compilation_checks.rs b/runtime/common/src/compilation_checks.rs new file mode 100644 index 0000000000..41a084a0c6 --- /dev/null +++ b/runtime/common/src/compilation_checks.rs @@ -0,0 +1,34 @@ +// Copyright 2025 Moonbeam foundation +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +/// Macro to trigger a compile-time error if the `on-chain-release-build` feature is enabled. +/// +/// This ensures that certain code paths are not compiled when the code is built in an +/// on-chain environment, specifically when the `on-chain-release-build` feature is active. +/// This can be useful for enforcing restrictions or preventing undesirable behavior in on-chain +/// builds, ensuring that critical or forbidden code is excluded at compile time. +/// +/// # Usage +/// ```rust +/// moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); +/// ``` +#[macro_export] +macro_rules! fail_to_compile_if_on_chain_build { + () => { + #[cfg(feature = "on-chain-release-build")] + compile_error!("Not allowed in on-chain builds."); + }; +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 38647e2943..bfffaeec51 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -19,6 +19,7 @@ mod apis; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; +pub mod compilation_checks; pub mod deal_with_fees; mod impl_moonbeam_xcm_call; mod impl_moonbeam_xcm_call_tracing; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 82cc15e691..9e26969737 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -222,6 +222,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 4b0a18b035..35162cd91e 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -219,6 +219,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 906fa7fb85..f7d501dda3 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -224,6 +224,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { From ddf6d66ce89ad7667115954d7ac1b90f57cc7c17 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 13:43:58 +0000 Subject: [PATCH 03/11] re-add comment --- client/evm-tracing/Cargo.toml | 1 + client/evm-tracing/src/formatters/call_tracer.rs | 2 ++ client/evm-tracing/src/formatters/trace_filter.rs | 2 ++ 3 files changed, 5 insertions(+) diff --git a/client/evm-tracing/Cargo.toml b/client/evm-tracing/Cargo.toml index a6e3b7ca5e..bba2e6e882 100644 --- a/client/evm-tracing/Cargo.toml +++ b/client/evm-tracing/Cargo.toml @@ -12,6 +12,7 @@ ethereum-types = { workspace = true, features = [ "std" ] } hex = { workspace = true, features = [ "serde" ] } serde = { workspace = true, features = [ "derive", "std" ] } serde_json = { workspace = true, default-features = true } +log = { workspace = true } # Moonbeam evm-tracing-events = { workspace = true, features = [ "std" ] } diff --git a/client/evm-tracing/src/formatters/call_tracer.rs b/client/evm-tracing/src/formatters/call_tracer.rs index 8a041be5cc..a2a42ac475 100644 --- a/client/evm-tracing/src/formatters/call_tracer.rs +++ b/client/evm-tracing/src/formatters/call_tracer.rs @@ -39,6 +39,8 @@ impl super::ResponseFormatter for Formatter { fn format(listener: Listener) -> Option> { let mut traces = Vec::new(); for (eth_tx_index, entry) in listener.entries.iter().enumerate() { + // Skip empty BTreeMaps pushed to `entries`. + // I.e. InvalidNonce or other pallet_evm::runner exits if entry.is_empty() { log::debug!( target: "tracing", diff --git a/client/evm-tracing/src/formatters/trace_filter.rs b/client/evm-tracing/src/formatters/trace_filter.rs index 109abf7f64..f3ae3307f6 100644 --- a/client/evm-tracing/src/formatters/trace_filter.rs +++ b/client/evm-tracing/src/formatters/trace_filter.rs @@ -33,6 +33,8 @@ impl super::ResponseFormatter for Formatter { fn format(listener: Listener) -> Option> { let mut traces = Vec::new(); for (eth_tx_index, entry) in listener.entries.iter().enumerate() { + // Skip empty BTreeMaps pushed to `entries`. + // I.e. InvalidNonce or other pallet_evm::runner exits if entry.is_empty() { log::debug!( target: "tracing", From bd30e1e89bf9d83c588aa5e2529310cd37cc6bdd Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 13:46:07 +0000 Subject: [PATCH 04/11] improve compilation error --- runtime/common/src/compilation_checks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/common/src/compilation_checks.rs b/runtime/common/src/compilation_checks.rs index 41a084a0c6..8e8243ce14 100644 --- a/runtime/common/src/compilation_checks.rs +++ b/runtime/common/src/compilation_checks.rs @@ -29,6 +29,6 @@ macro_rules! fail_to_compile_if_on_chain_build { () => { #[cfg(feature = "on-chain-release-build")] - compile_error!("Not allowed in on-chain builds."); + compile_error!("Not allowed in production builds for on-chain environments."); }; } From e155bc21f6d236bd2af5d2f8c88f64f4789b9b04 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 13:48:16 +0000 Subject: [PATCH 05/11] small improvement --- Cargo.lock | 1 + runtime/common/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d6e58c2ffe..26017be914 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6418,6 +6418,7 @@ dependencies = [ "ethereum-types", "evm-tracing-events", "hex", + "log", "moonbeam-rpc-primitives-debug", "parity-scale-codec", "serde", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index bfffaeec51..41be6b2858 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -19,7 +19,7 @@ mod apis; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -pub mod compilation_checks; +mod compilation_checks; pub mod deal_with_fees; mod impl_moonbeam_xcm_call; mod impl_moonbeam_xcm_call_tracing; From dc64145fc7947d44f0e035d0a9238f36d9ed4e4f Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 19:36:37 +0000 Subject: [PATCH 06/11] test weight limits in tracing --- .../test-trace-filter-weight-limits.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/suites/tracing-tests/test-trace-filter-weight-limits.ts diff --git a/test/suites/tracing-tests/test-trace-filter-weight-limits.ts b/test/suites/tracing-tests/test-trace-filter-weight-limits.ts new file mode 100644 index 0000000000..23cc50c124 --- /dev/null +++ b/test/suites/tracing-tests/test-trace-filter-weight-limits.ts @@ -0,0 +1,76 @@ +import { afterAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; +import { ALITH_ADDRESS, createEthersTransaction } from "@moonwall/util"; +import { sleep } from "../../helpers"; +import { encodeFunctionData } from "viem"; + +describeSuite({ + id: "T18", + title: "Trace filter - Test block weight limits with evm-tracing enabled", + foundationMethods: "dev", + testCases: ({ context, it }) => { + afterAll(async () => { + await sleep(500); // Add sleep to allow for graceful teardown + }); + + it({ + id: "T01", + title: + "The number of unique transaction traces should be the same as the number of transactions included in a block", + test: async function () { + const { abi, contractAddress } = await context.deployContract!("BloatedContract"); + + let nonce = await context.viem().getTransactionCount({ address: ALITH_ADDRESS }); + const tx = []; + for (let i = 0; i < 500; i++) { + tx.push( + await createEthersTransaction(context, { + to: contractAddress, + data: encodeFunctionData({ abi, functionName: "doSomething", args: [] }), + gasLimit: 10_000_000, + nonce: nonce++, + }) + ); + } + + const substrateBlock = await context.createBlock(tx, { allowFailures: false }); + const txHashes = (substrateBlock.result || []) + .filter((result) => result.successful) + .map((result) => result.hash); + + const blockNumber = (await context.polkadotJs().query.ethereum.currentBlock()) + .unwrap() + .header.number.toNumber(); + const blockNumberHex = blockNumber.toString(16); + const ethBlock = await customDevRpcRequest("eth_getBlockByNumber", [blockNumberHex, false]); + + // Confirm that all transactions were included in the ethereum block + expect(ethBlock.transactions.length).to.equal(txHashes.length); + + const traceFilterResponse = await customDevRpcRequest("trace_filter", [ + { + fromBlock: blockNumberHex, + toBlock: blockNumberHex, + }, + ]); + const uniqueTxsInTraces = Object.keys( + traceFilterResponse.reduce( + (prev, cur) => ({ + ...prev, + [cur.transactionHash]: true, + }), + {} + ) + ); + + console.log(` + Ethereum transactions count: ${ethBlock.transactions.length}, + Ethereum traces count: ${traceFilterResponse.length}, + Ethereum unique transactions in traces count: ${uniqueTxsInTraces.length} + `); + + // Assert that all eth transactions were traced + expect(ethBlock.transactions.length).to.equal(uniqueTxsInTraces.length); + }, + }); + }, +}); From 559e15059c60dabcbcf6f676238db18fd7839a2e Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sat, 8 Mar 2025 21:23:52 +0000 Subject: [PATCH 07/11] disable evm-tracing feature when running unit tests --- .github/workflows/build.yml | 2 +- .github/workflows/coverage.yml | 2 +- runtime/common/src/compilation_checks.rs | 34 ------------------------ runtime/common/src/lib.rs | 1 - runtime/moonbase/src/lib.rs | 4 +-- runtime/moonbeam/src/lib.rs | 4 +-- runtime/moonriver/src/lib.rs | 4 +-- 7 files changed, 8 insertions(+), 43 deletions(-) delete mode 100644 runtime/common/src/compilation_checks.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d067b27d4..da315a8c2b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -516,7 +516,7 @@ jobs: # Checks are run after uploading artifacts since they are modified by the tests - name: Unit tests run: | - cargo test --profile testnet --workspace --features=evm-tracing,runtime-benchmarks + cargo test --profile testnet --workspace --features=runtime-benchmarks - name: Run sccache stat for check pre test run: ${SCCACHE_PATH} --show-stats diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f8999293c2..6fe9b9adac 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -133,7 +133,7 @@ jobs: # curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin # echo $PATH - cargo nextest run --release --workspace --features=evm-tracing + cargo nextest run --release --workspace - name: "Run Moonwall Dev Tests" uses: ./.github/workflow-templates/dev-tests with: diff --git a/runtime/common/src/compilation_checks.rs b/runtime/common/src/compilation_checks.rs deleted file mode 100644 index 8e8243ce14..0000000000 --- a/runtime/common/src/compilation_checks.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2025 Moonbeam foundation -// This file is part of Moonbeam. - -// Moonbeam is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Moonbeam is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Moonbeam. If not, see . - -/// Macro to trigger a compile-time error if the `on-chain-release-build` feature is enabled. -/// -/// This ensures that certain code paths are not compiled when the code is built in an -/// on-chain environment, specifically when the `on-chain-release-build` feature is active. -/// This can be useful for enforcing restrictions or preventing undesirable behavior in on-chain -/// builds, ensuring that critical or forbidden code is excluded at compile time. -/// -/// # Usage -/// ```rust -/// moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); -/// ``` -#[macro_export] -macro_rules! fail_to_compile_if_on_chain_build { - () => { - #[cfg(feature = "on-chain-release-build")] - compile_error!("Not allowed in production builds for on-chain environments."); - }; -} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 41be6b2858..38647e2943 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -19,7 +19,6 @@ mod apis; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -mod compilation_checks; pub mod deal_with_fees; mod impl_moonbeam_xcm_call; mod impl_moonbeam_xcm_call_tracing; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 9e26969737..a84ae780ad 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -224,8 +224,8 @@ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { #[cfg(feature = "evm-tracing")] fn get() -> frame_system::limits::BlockWeights { - moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); - frame_system::limits::BlockWeights::simple_max(Weight::MAX) + let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); + frame_system::limits::BlockWeights::simple_max(max_weight) } #[cfg(not(feature = "evm-tracing"))] diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 35162cd91e..c92be992fb 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -221,8 +221,8 @@ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { #[cfg(feature = "evm-tracing")] fn get() -> frame_system::limits::BlockWeights { - moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); - frame_system::limits::BlockWeights::simple_max(Weight::MAX) + let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); + frame_system::limits::BlockWeights::simple_max(max_weight) } #[cfg(not(feature = "evm-tracing"))] diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index f7d501dda3..4e36fac635 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -226,8 +226,8 @@ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { #[cfg(feature = "evm-tracing")] fn get() -> frame_system::limits::BlockWeights { - moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); - frame_system::limits::BlockWeights::simple_max(Weight::MAX) + let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); + frame_system::limits::BlockWeights::simple_max(max_weight) } #[cfg(not(feature = "evm-tracing"))] From cc7d3c658b21f41af0db27ca0891d00a52d6ad04 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sun, 9 Mar 2025 18:25:26 +0000 Subject: [PATCH 08/11] Revert unecessary changes This reverts commit a58f24ae253b0f89727aacfee5bd5695da86bc0d. --- .github/workflows/build.yml | 2 +- .github/workflows/coverage.yml | 2 +- Cargo.lock | 1 - runtime/moonbase/src/lib.rs | 7 ------- runtime/moonbeam/src/lib.rs | 7 ------- runtime/moonriver/src/lib.rs | 7 ------- 6 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da315a8c2b..0d067b27d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -516,7 +516,7 @@ jobs: # Checks are run after uploading artifacts since they are modified by the tests - name: Unit tests run: | - cargo test --profile testnet --workspace --features=runtime-benchmarks + cargo test --profile testnet --workspace --features=evm-tracing,runtime-benchmarks - name: Run sccache stat for check pre test run: ${SCCACHE_PATH} --show-stats diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6fe9b9adac..f8999293c2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -133,7 +133,7 @@ jobs: # curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin # echo $PATH - cargo nextest run --release --workspace + cargo nextest run --release --workspace --features=evm-tracing - name: "Run Moonwall Dev Tests" uses: ./.github/workflow-templates/dev-tests with: diff --git a/Cargo.lock b/Cargo.lock index 26017be914..d6e58c2ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6418,7 +6418,6 @@ dependencies = [ "ethereum-types", "evm-tracing-events", "hex", - "log", "moonbeam-rpc-primitives-debug", "parity-scale-codec", "serde", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index a84ae780ad..82cc15e691 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -222,13 +222,6 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { - #[cfg(feature = "evm-tracing")] - fn get() -> frame_system::limits::BlockWeights { - let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); - frame_system::limits::BlockWeights::simple_max(max_weight) - } - - #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index c92be992fb..4b0a18b035 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -219,13 +219,6 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { - #[cfg(feature = "evm-tracing")] - fn get() -> frame_system::limits::BlockWeights { - let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); - frame_system::limits::BlockWeights::simple_max(max_weight) - } - - #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 4e36fac635..906fa7fb85 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -224,13 +224,6 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { - #[cfg(feature = "evm-tracing")] - fn get() -> frame_system::limits::BlockWeights { - let max_weight = Weight::MAX.set_proof_size(relay_chain::MAX_POV_SIZE as u64); - frame_system::limits::BlockWeights::simple_max(max_weight) - } - - #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { From bca04e16c56c97f2cf82d47bbba4c17c03d30f51 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sun, 9 Mar 2025 18:28:51 +0000 Subject: [PATCH 09/11] update lock file --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index d6e58c2ffe..26017be914 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6418,6 +6418,7 @@ dependencies = [ "ethereum-types", "evm-tracing-events", "hex", + "log", "moonbeam-rpc-primitives-debug", "parity-scale-codec", "serde", From 2b9360b19db814db0499e98d4fa631da7334d603 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sun, 9 Mar 2025 18:39:09 +0000 Subject: [PATCH 10/11] Add minimal fix --- runtime/common/src/apis.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 39e49d6cde..0bb4287a5b 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -249,6 +249,14 @@ macro_rules! impl_runtime_apis_plus_common { for ext in extrinsics.into_iter() { match &ext.0.function { RuntimeCall::Ethereum(transact { transaction }) => { + + // Reset the previously consumed weight when tracing multiple transactions. + // This is necessary because EVM tracing introduces additional + // (ref_time) overhead, which differs from the production runtime behavior. + // Without resetting the block weight, the extra tracing overhead could + // leading to some transactions to incorrectly fail during tracing. + frame_system::BlockWeight::::kill(); + let tx_hash = &transaction.hash(); if known_transactions.contains(&tx_hash) { // Each known extrinsic is a new call stack. From 409444fa81093eb688a61f46c02910af8e1b86f9 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Sun, 9 Mar 2025 19:16:25 +0000 Subject: [PATCH 11/11] Also reset block weights when tracing a specific transaction --- runtime/common/src/apis.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index 0bb4287a5b..ed33b7afa9 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -173,6 +173,14 @@ macro_rules! impl_runtime_apis_plus_common { for ext in extrinsics.into_iter() { let _ = match &ext.0.function { RuntimeCall::Ethereum(transact { transaction }) => { + + // Reset the previously consumed weight when tracing ethereum transactions. + // This is necessary because EVM tracing introduces additional + // (ref_time) overhead, which differs from the production runtime behavior. + // Without resetting the block weight, the extra tracing overhead could + // leading to some transactions to incorrectly fail during tracing. + frame_system::BlockWeight::::kill(); + if transaction == traced_transaction { EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); return Ok(());