From 65e932e48de718d7d7d9756b1380383e53453535 Mon Sep 17 00:00:00 2001 From: ubuntu-22 <1501514862@qq.com> Date: Wed, 24 Jul 2024 13:13:46 +0100 Subject: [PATCH 1/5] Fix gas and gasUsed in trace root only for ParityTrace --- crates/rpc/rpc/src/debug.rs | 68 +++++++++++++++++++++---------------- crates/rpc/rpc/src/trace.rs | 24 +++++-------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 847ab6ae5a33..3361872874e0 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -313,8 +313,9 @@ where .inner .eth_api .spawn_with_call_at(call, at, overrides, move |db, env| { - let (res, _) = this.eth_api().inspect(db, env, &mut inspector)?; + let (res, env) = this.eth_api().inspect(db, env, &mut inspector)?; let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) .into_geth_builder() .geth_call_traces(call_config, res.result.gas_used()); Ok(frame.into()) @@ -330,22 +331,23 @@ where TracingInspectorConfig::from_geth_prestate_config(&prestate_config), ); - let frame = - self.inner - .eth_api - .spawn_with_call_at(call, at, overrides, move |db, env| { - // wrapper is hack to get around 'higher-ranked lifetime error', - // see - let db = db.0; - - let (res, _) = - this.eth_api().inspect(&mut *db, env, &mut inspector)?; - let frame = inspector - .into_geth_builder() - .geth_prestate_traces(&res, prestate_config, db)?; - Ok(frame) - }) - .await?; + let frame = self + .inner + .eth_api + .spawn_with_call_at(call, at, overrides, move |db, env| { + // wrapper is hack to get around 'higher-ranked lifetime error', + // see + let db = db.0; + + let (res, env) = + this.eth_api().inspect(&mut *db, env, &mut inspector)?; + let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) + .into_geth_builder() + .geth_prestate_traces(&res, prestate_config, db)?; + Ok(frame) + }) + .await?; return Ok(frame.into()) } GethDebugBuiltInTracerType::NoopTracer => Ok(NoopFrame::default().into()), @@ -403,17 +405,20 @@ where let mut inspector = TracingInspector::new(inspector_config); - let (res, inspector) = self + let (res, env, inspector) = self .inner .eth_api .spawn_with_call_at(call, at, overrides, move |db, env| { - let (res, _) = this.eth_api().inspect(db, env, &mut inspector)?; - Ok((res, inspector)) + let (res, _) = this.eth_api().inspect(db, env.clone(), &mut inspector)?; + Ok((res, env, inspector)) }) .await?; let gas_used = res.result.gas_used(); let return_value = res.result.into_output().unwrap_or_default(); - let frame = inspector.into_geth_builder().geth_traces(gas_used, return_value, config); + let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) + .into_geth_builder() + .geth_traces(gas_used, return_value, config); Ok(frame.into()) } @@ -566,9 +571,10 @@ where TracingInspectorConfig::from_geth_call_config(&call_config), ); - let (res, _) = self.eth_api().inspect(db, env, &mut inspector)?; + let (res, env) = self.eth_api().inspect(db, env, &mut inspector)?; let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) .into_geth_builder() .geth_call_traces(call_config, res.result.gas_used()); @@ -582,13 +588,12 @@ where let mut inspector = TracingInspector::new( TracingInspectorConfig::from_geth_prestate_config(&prestate_config), ); - let (res, _) = self.eth_api().inspect(&mut *db, env, &mut inspector)?; + let (res, env) = self.eth_api().inspect(&mut *db, env, &mut inspector)?; - let frame = inspector.into_geth_builder().geth_prestate_traces( - &res, - prestate_config, - db, - )?; + let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) + .into_geth_builder() + .geth_prestate_traces(&res, prestate_config, db)?; return Ok((frame.into(), res.state)) } @@ -628,10 +633,13 @@ where let mut inspector = TracingInspector::new(inspector_config); - let (res, _) = self.eth_api().inspect(db, env, &mut inspector)?; + let (res, env) = self.eth_api().inspect(db, env, &mut inspector)?; let gas_used = res.result.gas_used(); let return_value = res.result.into_output().unwrap_or_default(); - let frame = inspector.into_geth_builder().geth_traces(gas_used, return_value, config); + let frame = inspector + .with_transaction_gas_limit(env.tx.gas_limit) + .into_geth_builder() + .geth_traces(gas_used, return_value, config); Ok((frame.into(), res.state)) } diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index 57a557634757..0dbd463f82e0 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -302,17 +302,15 @@ where num.into(), Some(highest_idx), TracingInspectorConfig::default_parity(), - move |tx_info, inspector, res, _, _| { + move |tx_info, inspector, _, _, _| { if let Some(idx) = tx_info.index { if !indices.contains(&idx) { // only record traces for relevant transactions return Ok(None) } } - let traces = inspector - .with_transaction_gas_used(res.gas_used()) - .into_parity_builder() - .into_localized_transaction_traces(tx_info); + let traces = + inspector.into_parity_builder().into_localized_transaction_traces(tx_info); Ok(Some(traces)) }, ); @@ -368,11 +366,9 @@ where .spawn_trace_transaction_in_block( hash, TracingInspectorConfig::default_parity(), - move |tx_info, inspector, res, _| { - let traces = inspector - .with_transaction_gas_used(res.result.gas_used()) - .into_parity_builder() - .into_localized_transaction_traces(tx_info); + move |tx_info, inspector, _, _| { + let traces = + inspector.into_parity_builder().into_localized_transaction_traces(tx_info); Ok(traces) }, ) @@ -387,11 +383,9 @@ where let traces = self.inner.eth_api.trace_block_with( block_id, TracingInspectorConfig::default_parity(), - |tx_info, inspector, res, _, _| { - let traces = inspector - .with_transaction_gas_used(res.gas_used()) - .into_parity_builder() - .into_localized_transaction_traces(tx_info); + |tx_info, inspector, _, _, _| { + let traces = + inspector.into_parity_builder().into_localized_transaction_traces(tx_info); Ok(traces) }, ); From d039669d455dcf4482a09998028eca41194f039e Mon Sep 17 00:00:00 2001 From: ubuntu-22 <1501514862@qq.com> Date: Thu, 25 Jul 2024 15:15:33 +0100 Subject: [PATCH 2/5] Remove the redundant clone --- crates/rpc/rpc/src/debug.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 3361872874e0..db7761ecea4f 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -405,18 +405,18 @@ where let mut inspector = TracingInspector::new(inspector_config); - let (res, env, inspector) = self + let (res, tx_gas_limit, inspector) = self .inner .eth_api .spawn_with_call_at(call, at, overrides, move |db, env| { - let (res, _) = this.eth_api().inspect(db, env.clone(), &mut inspector)?; - Ok((res, env, inspector)) + let (res, _) = this.eth_api().inspect(db, env, &mut inspector)?; + Ok((res, env.tx.gas_limit, inspector)) }) .await?; let gas_used = res.result.gas_used(); let return_value = res.result.into_output().unwrap_or_default(); let frame = inspector - .with_transaction_gas_limit(env.tx.gas_limit) + .with_transaction_gas_limit(tx_gas_limit) .into_geth_builder() .geth_traces(gas_used, return_value, config); From c82e1483e63e00c3243d3e3e48fdd0767d9f3f24 Mon Sep 17 00:00:00 2001 From: ubuntu-22 <1501514862@qq.com> Date: Thu, 25 Jul 2024 16:29:41 +0100 Subject: [PATCH 3/5] Update the revm-inspectors version --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f24d2979270..384648091ad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8883,9 +8883,9 @@ dependencies = [ [[package]] name = "revm-inspectors" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af2dc001e37ac3b061dc9087876aea91e28756c188a97cd99416d23a5562ca73" +checksum = "5296ccad8d7ccbeb6c5a037a57bfe1ff27e81d8c4efbd3ae7df0a554eb1a818a" dependencies = [ "alloy-primitives", "alloy-rpc-types", diff --git a/Cargo.toml b/Cargo.toml index b0fe01afdce2..b5a022fc1686 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -386,7 +386,7 @@ revm = { version = "12.1.0", features = [ revm-primitives = { version = "7.1.0", features = [ "std", ], default-features = false } -revm-inspectors = "0.5" +revm-inspectors = "0.5.4" # eth alloy-chains = "0.1.18" From 26a301efb61e4bc4461e16f3a95e4d44937675fd Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 25 Jul 2024 17:40:14 +0200 Subject: [PATCH 4/5] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b5a022fc1686..b0fe01afdce2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -386,7 +386,7 @@ revm = { version = "12.1.0", features = [ revm-primitives = { version = "7.1.0", features = [ "std", ], default-features = false } -revm-inspectors = "0.5.4" +revm-inspectors = "0.5" # eth alloy-chains = "0.1.18" From f9e13f00c69a666d2689436795834f77beda3bef Mon Sep 17 00:00:00 2001 From: ubuntu-22 <1501514862@qq.com> Date: Thu, 25 Jul 2024 17:45:49 +0100 Subject: [PATCH 5/5] Correct the copy of tx_gas_limit --- crates/rpc/rpc/src/debug.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index db7761ecea4f..76ae2847ed96 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -409,8 +409,9 @@ where .inner .eth_api .spawn_with_call_at(call, at, overrides, move |db, env| { + let tx_gas_limit = env.tx.gas_limit; let (res, _) = this.eth_api().inspect(db, env, &mut inspector)?; - Ok((res, env.tx.gas_limit, inspector)) + Ok((res, tx_gas_limit, inspector)) }) .await?; let gas_used = res.result.gas_used();