Added support for FIREHOSE_ETHEREUM_TRACER_LOG_LEVEL=trace_full

Now `trace` alone will not print the opcodes which makes it much harder to track log lines and usually is not that useful.

The `trace_full` is same as `trace` but logs `OpCode`.
This commit is contained in:
Matthieu Vachon 2025-01-08 17:07:31 -05:00
parent 069b0b36ba
commit 12f070888f

View file

@ -41,10 +41,12 @@ import (
// - Info == block start/end + trx start/end // - Info == block start/end + trx start/end
// - Debug == Info + call start/end + error // - Debug == Info + call start/end + error
// - Trace == Debug + state db changes, log, balance, nonce, code, storage, gas // - Trace == Debug + state db changes, log, balance, nonce, code, storage, gas
// - TraceFull == Trace + opcode
var firehoseTracerLogLevel = strings.ToLower(os.Getenv("FIREHOSE_ETHEREUM_TRACER_LOG_LEVEL")) var firehoseTracerLogLevel = strings.ToLower(os.Getenv("FIREHOSE_ETHEREUM_TRACER_LOG_LEVEL"))
var isFirehoseInfoEnabled = firehoseTracerLogLevel == "info" || firehoseTracerLogLevel == "debug" || firehoseTracerLogLevel == "trace" var isFirehoseInfoEnabled = firehoseTracerLogLevel == "info" || firehoseTracerLogLevel == "debug" || firehoseTracerLogLevel == "trace" || firehoseTracerLogLevel == "trace_full"
var isFirehoseDebugEnabled = firehoseTracerLogLevel == "debug" || firehoseTracerLogLevel == "trace" var isFirehoseDebugEnabled = firehoseTracerLogLevel == "debug" || firehoseTracerLogLevel == "trace" || firehoseTracerLogLevel == "trace_full"
var isFirehoseTracerEnabled = firehoseTracerLogLevel == "trace" var isFirehoseTraceEnabled = firehoseTracerLogLevel == "trace" || firehoseTracerLogLevel == "trace_full"
var isFirehoseTraceFullEnabled = firehoseTracerLogLevel == "trace_full"
var emptyCommonAddress = common.Address{} var emptyCommonAddress = common.Address{}
var emptyCommonHash = common.Hash{} var emptyCommonHash = common.Hash{}
@ -815,7 +817,7 @@ func (f *Firehose) OnCallExit(depth int, output []byte, gasUsed uint64, err erro
// OnOpcode implements the EVMLogger interface to trace a single step of VM execution. // OnOpcode implements the EVMLogger interface to trace a single step of VM execution.
func (f *Firehose) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) { func (f *Firehose) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
firehoseTrace("on opcode (op=%s gas=%d cost=%d, err=%s)", vm.OpCode(op), gas, cost, errorView(err)) firehoseTraceFull("on opcode (op=%s gas=%d cost=%d, err=%s)", vm.OpCode(op), gas, cost, errorView(err))
if activeCall := f.callStack.Peek(); activeCall != nil { if activeCall := f.callStack.Peek(); activeCall != nil {
opCode := vm.OpCode(op) opCode := vm.OpCode(op)
@ -902,6 +904,8 @@ var opCodeToGasChangeReasonMap = map[vm.OpCode]pbeth.GasChange_Reason{
// OnOpcodeFault implements the EVMLogger interface to trace an execution fault. // OnOpcodeFault implements the EVMLogger interface to trace an execution fault.
func (f *Firehose) OnOpcodeFault(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) { func (f *Firehose) OnOpcodeFault(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
firehoseTraceFull("on opcode fault (op=%s gas=%d cost=%d, err=%s)", vm.OpCode(op), gas, cost, errorView(err))
if activeCall := f.callStack.Peek(); activeCall != nil { if activeCall := f.callStack.Peek(); activeCall != nil {
f.captureInterpreterStep(activeCall, pc, vm.OpCode(op), gas, cost, scope, nil, depth, err) f.captureInterpreterStep(activeCall, pc, vm.OpCode(op), gas, cost, scope, nil, depth, err)
} }
@ -1872,7 +1876,13 @@ func firehoseDebug(msg string, args ...interface{}) {
} }
func firehoseTrace(msg string, args ...interface{}) { func firehoseTrace(msg string, args ...interface{}) {
if isFirehoseTracerEnabled { if isFirehoseTraceEnabled {
fmt.Fprintf(os.Stderr, "[Firehose] "+msg+"\n", args...)
}
}
func firehoseTraceFull(msg string, args ...interface{}) {
if isFirehoseTraceFullEnabled {
fmt.Fprintf(os.Stderr, "[Firehose] "+msg+"\n", args...) fmt.Fprintf(os.Stderr, "[Firehose] "+msg+"\n", args...)
} }
} }