Skip to content

Commit

Permalink
Fix gas and gasUsed in trace root only for ParityTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzPoLariszZ committed Jul 24, 2024
1 parent 5616b4e commit ab9a6a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
25 changes: 14 additions & 11 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -338,9 +339,10 @@ where
// see <https://github.com/rust-lang/rust/issues/100013>
let db = db.0;

let (res, _) =
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)
Expand Down Expand Up @@ -403,17 +405,17 @@ 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())
}
Expand Down Expand Up @@ -566,9 +568,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());

Expand All @@ -582,9 +585,9 @@ 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(
let frame = inspector.with_transaction_gas_limit(env.tx.gas_limit).into_geth_builder().geth_prestate_traces(
&res,
prestate_config,
db,
Expand Down Expand Up @@ -628,10 +631,10 @@ 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))
}
Expand Down
12 changes: 6 additions & 6 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ where
num.into(),
Some(highest_idx),
TracingInspectorConfig::default_parity(),
move |tx_info, inspector, res, _, _| {
move |tx_info, inspector, _res, _, _| {
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())
// .with_transaction_gas_used(res.gas_used())
.into_parity_builder()
.into_localized_transaction_traces(tx_info);
Ok(Some(traces))
Expand Down Expand Up @@ -368,9 +368,9 @@ where
.spawn_trace_transaction_in_block(
hash,
TracingInspectorConfig::default_parity(),
move |tx_info, inspector, res, _| {
move |tx_info, inspector, _res, _| {
let traces = inspector
.with_transaction_gas_used(res.result.gas_used())
// .with_transaction_gas_used(res.result.gas_used())
.into_parity_builder()
.into_localized_transaction_traces(tx_info);
Ok(traces)
Expand All @@ -387,9 +387,9 @@ where
let traces = self.inner.eth_api.trace_block_with(
block_id,
TracingInspectorConfig::default_parity(),
|tx_info, inspector, res, _, _| {
|tx_info, inspector, _res, _, _| {
let traces = inspector
.with_transaction_gas_used(res.gas_used())
// .with_transaction_gas_used(res.gas_used())
.into_parity_builder()
.into_localized_transaction_traces(tx_info);
Ok(traces)
Expand Down

0 comments on commit ab9a6a0

Please sign in to comment.