mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
fix: use refunds for root call (#3594)
This commit is contained in:
@ -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();
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user