From 5025ffdc3ef5bc788ba0ade1962c317423b4ab17 Mon Sep 17 00:00:00 2001 From: chiphamskymavis Date: Mon, 14 Jul 2025 14:45:30 +0700 Subject: [PATCH 1/2] eth/tracers: set logger hooks for stateDB --- eth/tracers/api.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 295851771..7867fc81f 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -1180,6 +1180,9 @@ func (api *API) traceTx( } } + // Set the tracer for the stateDB + statedb.SetLogger(tracer.Hooks) + // Run the transaction with tracing enabled. vmenv := vm.NewEVM(vmctx, txContext, statedb, api.backend.ChainConfig(), vm.Config{Tracer: tracer.Hooks, NoBaseFee: true}) if precompiles != nil { From 47ccab590195b90d168c64bb5b9ad31716ba8dc3 Mon Sep 17 00:00:00 2001 From: chiphamskymavis Date: Mon, 14 Jul 2025 14:41:14 +0700 Subject: [PATCH 2/2] core/state: ensure logger is included in StateDB copy --- core/state/statedb.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 4f9672552..09923fef1 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -252,11 +252,13 @@ func (s *StateDB) AddLog(log *types.Log) { log.TxHash = s.thash log.TxIndex = uint(s.txIndex) log.Index = s.logSize + + s.logs[s.thash] = append(s.logs[s.thash], log) + s.logSize++ + if s.logger != nil && s.logger.OnLog != nil { s.logger.OnLog(log) } - s.logs[s.thash] = append(s.logs[s.thash], log) - s.logSize++ } func (s *StateDB) GetLogs(hash common.Hash, blockHash common.Hash) []*types.Log { @@ -826,8 +828,9 @@ func (s *StateDB) Copy() *StateDB { // to the snapshot tree, we need to copy that as well. Otherwise, any // block mined by ourselves will cause gaps in the tree, and force the // miner to operate trie-backed only. - snaps: s.snaps, - snap: s.snap, + snaps: s.snaps, + snap: s.snap, + logger: s.logger, } // Deep copy cached state objects. for addr, obj := range s.stateObjects {