From 046b4c92197bc6f29e9a70026863878a26d6b844 Mon Sep 17 00:00:00 2001 From: Michael Birch Date: Thu, 9 Dec 2021 21:38:33 +0100 Subject: [PATCH] Feat(standalone): Add debug tracing of remaining gas values (#391) --- engine-standalone-tracing/src/sputnik.rs | 12 ++++++++++-- engine-standalone-tracing/src/types.rs | 4 ++-- engine-tests/src/tests/standalone/tracing.rs | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/engine-standalone-tracing/src/sputnik.rs b/engine-standalone-tracing/src/sputnik.rs index 799b59194..6e17e7437 100644 --- a/engine-standalone-tracing/src/sputnik.rs +++ b/engine-standalone-tracing/src/sputnik.rs @@ -48,14 +48,18 @@ impl evm_gasometer::tracing::EventListener for TransactionTraceBuilder { fn event(&mut self, event: evm_gasometer::tracing::Event) { use evm_gasometer::tracing::Event; match event { - Event::RecordCost { cost, snapshot: _ } => { + Event::RecordCost { cost, snapshot } => { self.current.gas_cost = EthGas::new(cost); + if let Some(snapshot) = snapshot { + self.current.gas = + EthGas::new(snapshot.gas_limit - snapshot.used_gas - snapshot.memory_gas); + } } Event::RecordDynamicCost { gas_cost, memory_gas, gas_refund: _, - snapshot: _, + snapshot, } => { // In SputnikVM memory gas is cumulative (ie this event always shows the total) gas // spent on memory up to this point. But geth traces simply show how much gas each step @@ -68,6 +72,10 @@ impl evm_gasometer::tracing::EventListener for TransactionTraceBuilder { }; self.current_memory_gas = memory_gas; self.current.gas_cost = EthGas::new(gas_cost + memory_cost_diff); + if let Some(snapshot) = snapshot { + self.current.gas = + EthGas::new(snapshot.gas_limit - snapshot.used_gas - snapshot.memory_gas); + } } Event::RecordRefund { refund: _, diff --git a/engine-standalone-tracing/src/types.rs b/engine-standalone-tracing/src/types.rs index 69b885593..adcea350c 100644 --- a/engine-standalone-tracing/src/types.rs +++ b/engine-standalone-tracing/src/types.rs @@ -151,9 +151,9 @@ pub struct TraceLog { pub depth: Depth, /// Any errors that may have occurred during execution. pub error: Option, - /// Gas used to execute the transaction. + /// Remaining (unused) gas. pub gas: EthGas, - /// Gas cost for the transaction. + /// Gas cost for the opcode at this step. pub gas_cost: EthGas, /// The bounded memory. pub memory: LogMemory, diff --git a/engine-tests/src/tests/standalone/tracing.rs b/engine-tests/src/tests/standalone/tracing.rs index f6da0e8ee..f34475363 100644 --- a/engine-tests/src/tests/standalone/tracing.rs +++ b/engine-tests/src/tests/standalone/tracing.rs @@ -209,6 +209,11 @@ fn check_transaction_trace>(trace: TransactionTrace, expected_tra ); assert_eq!(log.depth.into_u32(), step.depth, "Depths should match"); assert_eq!(log.opcode.as_u8(), step.op, "opcodes should match"); + assert_eq!( + log.gas.into_u64(), + step.gas, + "remaining gas values should match" + ); assert_eq!( log.gas_cost.into_u64(), step.gas_cost,