mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
fix: set trace results root trace's gas used to execution results gas (#4506)
This commit is contained in:
@@ -136,6 +136,7 @@ impl ParityTraceBuilder {
|
||||
res: ExecutionResult,
|
||||
trace_types: &HashSet<TraceType>,
|
||||
) -> TraceResults {
|
||||
let gas_used = res.gas_used();
|
||||
let output = match res {
|
||||
ExecutionResult::Success { output, .. } => output.into_data(),
|
||||
ExecutionResult::Revert { output, .. } => output,
|
||||
@@ -144,12 +145,18 @@ impl ParityTraceBuilder {
|
||||
|
||||
let (trace, vm_trace, state_diff) = self.into_trace_type_traces(trace_types);
|
||||
|
||||
TraceResults {
|
||||
let mut trace = TraceResults {
|
||||
output: output.into(),
|
||||
trace: trace.unwrap_or_default(),
|
||||
vm_trace,
|
||||
state_diff,
|
||||
}
|
||||
};
|
||||
|
||||
// we're setting the gas used of the root trace explicitly to the gas used of the execution
|
||||
// result
|
||||
trace.set_root_trace_gas_used(gas_used);
|
||||
|
||||
trace
|
||||
}
|
||||
|
||||
/// Consumes the inspector and returns the trace results according to the configured trace
|
||||
|
||||
@@ -39,6 +39,21 @@ pub struct TraceResults {
|
||||
pub vm_trace: Option<VmTrace>,
|
||||
}
|
||||
|
||||
// === impl TraceResults ===
|
||||
|
||||
impl TraceResults {
|
||||
/// Sets the gas used of the root trace.
|
||||
///
|
||||
/// The root trace's gasUsed should mirror the actual gas used by the transaction.
|
||||
///
|
||||
/// This allows setting int manually by consuming the execution result's gas for example.
|
||||
pub fn set_root_trace_gas_used(&mut self, gas_used: u64) {
|
||||
if let Some(r) = self.trace.first_mut().and_then(|t| t.result.as_mut()) {
|
||||
r.set_gas_used(gas_used)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A `FullTrace` with an additional transaction hash
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -240,13 +255,37 @@ pub struct CreateOutput {
|
||||
pub address: Address,
|
||||
}
|
||||
|
||||
/// Represents the output of a trace.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum TraceOutput {
|
||||
/// Output of a regular call transaction.
|
||||
Call(CallOutput),
|
||||
/// Output of a CREATE transaction.
|
||||
Create(CreateOutput),
|
||||
}
|
||||
|
||||
// === impl TraceOutput ===
|
||||
|
||||
impl TraceOutput {
|
||||
/// Returns the gas used by this trace.
|
||||
pub fn gas_used(&self) -> U64 {
|
||||
match self {
|
||||
TraceOutput::Call(call) => call.gas_used,
|
||||
TraceOutput::Create(create) => create.gas_used,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the gas used by this trace.
|
||||
pub fn set_gas_used(&mut self, gas_used: u64) {
|
||||
match self {
|
||||
TraceOutput::Call(call) => call.gas_used = U64::from(gas_used),
|
||||
TraceOutput::Create(create) => create.gas_used = U64::from(gas_used),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A parity style trace of a transaction.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TransactionTrace {
|
||||
|
||||
@@ -268,7 +268,8 @@ where
|
||||
.await
|
||||
}
|
||||
|
||||
/// Executes all transactions of a block and returns a list of callback results.
|
||||
/// Executes all transactions of a block and returns a list of callback results invoked for each
|
||||
/// transaction in the block.
|
||||
///
|
||||
/// This
|
||||
/// 1. fetches all transactions of the block
|
||||
|
||||
Reference in New Issue
Block a user