core/state: apply suggestions from review

This commit is contained in:
Martin Holst Swende 2024-05-14 09:38:22 +02:00
parent 66fc14ad58
commit 2a2c432410
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 7 additions and 4 deletions

View file

@ -19,6 +19,7 @@ package state
import (
"fmt"
"maps"
"slices"
"sort"
"github.com/ethereum/go-ethereum/common"
@ -68,7 +69,7 @@ func newJournal() *journal {
func (j *journal) Reset() {
j.entries = j.entries[:0]
j.validRevisions = j.validRevisions[:0]
j.dirties = make(map[common.Address]int)
clear(j.dirties)
j.nextRevisionId = 0
}
@ -140,8 +141,10 @@ func (j *journal) copy() *journal {
entries = append(entries, j.entries[i].copy())
}
return &journal{
entries: entries,
dirties: maps.Clone(j.dirties),
entries: entries,
dirties: maps.Clone(j.dirties),
validRevisions: slices.Clone(j.validRevisions),
nextRevisionId: j.nextRevisionId,
}
}

View file

@ -500,10 +500,10 @@ func (s *StateDB) SelfDestruct(addr common.Address) {
// Regardless of whether it is already destructed or not, we do have to
// journal the balance-change, if we set it to zero here.
if !stateObject.Balance().IsZero() {
stateObject.SetBalance(new(uint256.Int), tracing.BalanceDecreaseSelfdestruct)
if s.logger != nil && s.logger.OnBalanceChange != nil {
s.logger.OnBalanceChange(addr, stateObject.Balance().ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
}
stateObject.SetBalance(new(uint256.Int), tracing.BalanceDecreaseSelfdestruct)
}
// If it is already marked as self-destructed, we do not need to add it
// for journalling a second time.