Skip to content

Commit 0df132d

Browse files
committed
core/state: fix tracer hook for burn logs
1 parent a8ea631 commit 0df132d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

core/state/statedb.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ type removedAccountWithBalance struct {
745745
balance *uint256.Int
746746
}
747747

748-
// EmitLogsForBurnAccounts emits the eth burn logs for accounts scheduled for
748+
// LogsForBurnAccounts returns the eth burn logs for accounts scheduled for
749749
// removal which still have positive balance. The purpose of this function is
750750
// to handle a corner case of EIP-7708 where a self-destructed account might
751751
// still receive funds between sending/burning its previous balance and actual
@@ -755,7 +755,7 @@ type removedAccountWithBalance struct {
755755
//
756756
// This function should only be invoked at the transaction boundary, specifically
757757
// before the Finalise.
758-
func (s *StateDB) EmitLogsForBurnAccounts() {
758+
func (s *StateDB) LogsForBurnAccounts() []*types.Log {
759759
var list []removedAccountWithBalance
760760
for addr := range s.journal.dirties {
761761
if obj, exist := s.stateObjects[addr]; exist && obj.selfDestructed && !obj.Balance().IsZero() {
@@ -765,14 +765,17 @@ func (s *StateDB) EmitLogsForBurnAccounts() {
765765
})
766766
}
767767
}
768-
if list != nil {
769-
sort.Slice(list, func(i, j int) bool {
770-
return list[i].address.Cmp(list[j].address) < 0
771-
})
768+
if list == nil {
769+
return nil
772770
}
773-
for _, acct := range list {
774-
s.AddLog(types.EthBurnLog(acct.address, acct.balance))
771+
sort.Slice(list, func(i, j int) bool {
772+
return list[i].address.Cmp(list[j].address) < 0
773+
})
774+
logs := make([]*types.Log, len(list))
775+
for i, acct := range list {
776+
logs[i] = types.EthBurnLog(acct.address, acct.balance)
775777
}
778+
return logs
776779
}
777780

778781
// Finalise finalises the state by removing the destructed objects and clears

core/state/statedb_hooked.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ func (s *hookedStateDB) AddLog(log *types.Log) {
229229
}
230230
}
231231

232-
func (s *hookedStateDB) EmitLogsForBurnAccounts() {
233-
s.inner.EmitLogsForBurnAccounts()
232+
func (s *hookedStateDB) LogsForBurnAccounts() []*types.Log {
233+
return s.inner.LogsForBurnAccounts()
234234
}
235235

236236
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {

core/state_transition.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
584584
}
585585
}
586586
if rules.IsAmsterdam {
587-
st.evm.StateDB.EmitLogsForBurnAccounts()
587+
for _, log := range st.evm.StateDB.LogsForBurnAccounts() {
588+
st.evm.StateDB.AddLog(log)
589+
}
588590
}
589591
return &ExecutionResult{
590592
UsedGas: st.gasUsed(),

core/vm/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type StateDB interface {
8787
Snapshot() int
8888

8989
AddLog(*types.Log)
90-
EmitLogsForBurnAccounts()
90+
LogsForBurnAccounts() []*types.Log
9191
AddPreimage(common.Hash, []byte)
9292

9393
Witness() *stateless.Witness

0 commit comments

Comments
 (0)