Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(standalone): Add debug tracing of remaining gas values #391

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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