From 56862cf07f20ab8f35d3db00812a3cb2fc02df87 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 30 Jan 2024 16:36:14 +0100 Subject: [PATCH] emit onNewAccount when reseting account --- core/state/statedb.go | 18 ++++++++++-------- eth/tracers/directory/noop.go | 2 +- eth/tracers/live/printer.go | 2 +- eth/tracers/native/mux.go | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 409dfeca9f..7dc346bf1a 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -61,7 +61,9 @@ type StateLogger interface { OnStorageChange(addr common.Address, slot common.Hash, prev, new common.Hash) OnLog(log *types.Log) // OnNewAccount is called when a new account is created. - OnNewAccount(addr common.Address) + // Reset indicates an account existed at that address + // which will be replaced. + OnNewAccount(addr common.Address, reset bool) } // StateDB structs within the ethereum protocol are used to store anything @@ -665,15 +667,15 @@ func (s *StateDB) getOrNewStateObject(addr common.Address) *stateObject { func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) { prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that! newobj = newObject(s, addr, nil) + if s.logger != nil { + // Precompiled contracts are touched during a call. + // Make sure we avoid emitting a new account event for them. + if _, ok := s.precompiles[addr]; !ok { + s.logger.OnNewAccount(addr, prev != nil) + } + } if prev == nil { s.journal.append(createObjectChange{account: &addr}) - if s.logger != nil { - // Precompiled contracts are touched during a call. - // Make sure we avoid emitting a new account event for them. - if _, ok := s.precompiles[addr]; !ok { - s.logger.OnNewAccount(addr) - } - } } else { // The original account should be marked as destructed and all cached // account and storage data should be cleared as well. Note, it must diff --git a/eth/tracers/directory/noop.go b/eth/tracers/directory/noop.go index 4aeb15ae30..e784b6c846 100644 --- a/eth/tracers/directory/noop.go +++ b/eth/tracers/directory/noop.go @@ -86,7 +86,7 @@ func (*NoopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) { func (*NoopTracer) OnLog(log *types.Log) {} -func (*NoopTracer) OnNewAccount(a common.Address) {} +func (*NoopTracer) OnNewAccount(a common.Address, reset bool) {} // GetResult returns an empty json object. func (t *NoopTracer) GetResult() (json.RawMessage, error) { diff --git a/eth/tracers/live/printer.go b/eth/tracers/live/printer.go index 55da7352e0..fc6e759005 100644 --- a/eth/tracers/live/printer.go +++ b/eth/tracers/live/printer.go @@ -125,7 +125,7 @@ func (p *Printer) OnLog(l *types.Log) { fmt.Printf("OnLog: l=%s\n", buf) } -func (p *Printer) OnNewAccount(a common.Address) { +func (p *Printer) OnNewAccount(a common.Address, reset bool) { fmt.Printf("OnNewAccount: a=%v\n", a) } diff --git a/eth/tracers/native/mux.go b/eth/tracers/native/mux.go index 62657fe8cc..1175cc768a 100644 --- a/eth/tracers/native/mux.go +++ b/eth/tracers/native/mux.go @@ -159,9 +159,9 @@ func (t *muxTracer) OnLog(log *types.Log) { } } -func (t *muxTracer) OnNewAccount(a common.Address) { +func (t *muxTracer) OnNewAccount(a common.Address, reset bool) { for _, t := range t.tracers { - t.OnNewAccount(a) + t.OnNewAccount(a, reset) } }