fix: use refunds for root call (#3594)

This commit is contained in:
Matthias Seitz
2023-07-05 15:47:51 +02:00
committed by GitHub
parent 7d8f0c7f87
commit fc540c60fd
2 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,7 @@ mod utils;
use crate::tracing::{
arena::PushTraceKind,
types::{CallTraceNode, StorageChange},
utils::gas_used,
};
pub use builder::{
geth::{self, GethTraceBuilder},
@ -193,7 +194,7 @@ impl TracingInspector {
/// This expects an existing trace [Self::start_trace_on_call]
fn fill_trace_on_call_end<DB: Database>(
&mut self,
_data: &EVMData<'_, DB>,
data: &EVMData<'_, DB>,
status: InstructionResult,
gas: &Gas,
output: Bytes,
@ -202,7 +203,14 @@ impl TracingInspector {
let trace_idx = self.pop_trace_idx();
let trace = &mut self.traces.arena[trace_idx].trace;
if trace_idx == 0 {
// this is the root call which should get the gas used of the transaction
// refunds are applied after execution, which is when the root call ends
trace.gas_used = gas_used(data.env.cfg.spec_id, gas.spend(), gas.refunded() as u64);
} else {
trace.gas_used = gas.spend();
}
trace.status = status;
trace.success = matches!(status, return_ok!());
trace.output = output.clone();

View File

@ -23,7 +23,6 @@ pub(crate) fn convert_memory(data: &[u8]) -> Vec<String> {
/// Get the gas used, accounting for refunds
#[inline]
#[allow(unused)]
pub(crate) fn gas_used(spec: SpecId, spent: u64, refunded: u64) -> u64 {
let refund_quotient = if SpecId::enabled(spec, SpecId::LONDON) { 5 } else { 2 };
spent - (refunded).min(spent / refund_quotient)