Skip to content

Commit

Permalink
Feat(standalone): Add debug tracing of remaining gas values (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Feb 16, 2022
1 parent c579fc8 commit 046b4c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions engine-standalone-tracing/src/sputnik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: _,
Expand Down
4 changes: 2 additions & 2 deletions engine-standalone-tracing/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ pub struct TraceLog {
pub depth: Depth,
/// Any errors that may have occurred during execution.
pub error: Option<String>,
/// 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,
Expand Down
5 changes: 5 additions & 0 deletions engine-tests/src/tests/standalone/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ fn check_transaction_trace<P: AsRef<Path>>(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,
Expand Down

0 comments on commit 046b4c9

Please sign in to comment.