core/state: simplify codechange journalling

This commit is contained in:
Martin Holst Swende 2024-01-26 15:09:40 +01:00
parent 8d5ceb6cad
commit 137fdb7fe2
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
3 changed files with 13 additions and 15 deletions

View file

@ -20,6 +20,7 @@ import (
"maps"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
)
@ -159,12 +160,8 @@ func (j *journal) JournalBalanceChange(addr common.Address, previous *uint256.In
})
}
func (j *journal) JournalSetCode(address common.Address, prevcode, prevHash []byte) {
j.append(codeChange{
account: &address,
prevhash: prevHash,
prevcode: prevcode,
})
func (j *journal) JournalSetCode(address common.Address) {
j.append(codeChange{account: &address})
}
func (j *journal) JournalNonceChange(address common.Address, prev uint64) {
@ -221,7 +218,6 @@ type (
}
codeChange struct {
account *common.Address
prevcode, prevhash []byte
}
// Changes to other state values.
@ -348,7 +344,7 @@ func (ch nonceChange) copy() journalEntry {
}
func (ch codeChange) revert(s *StateDB) {
s.getStateObject(*ch.account).setCode(common.BytesToHash(ch.prevhash), ch.prevcode)
s.getStateObject(*ch.account).setCode(types.EmptyCodeHash, nil)
}
func (ch codeChange) dirtied() *common.Address {
@ -356,11 +352,7 @@ func (ch codeChange) dirtied() *common.Address {
}
func (ch codeChange) copy() journalEntry {
return codeChange{
account: ch.account,
prevhash: common.CopyBytes(ch.prevhash),
prevcode: common.CopyBytes(ch.prevcode),
}
return codeChange{account: ch.account}
}
func (ch storageChange) revert(s *StateDB) {

View file

@ -574,7 +574,7 @@ func (s *stateObject) CodeSize() int {
}
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
s.db.journal.JournalSetCode(s.address, s.Code(), s.CodeHash())
s.db.journal.JournalSetCode(s.address)
if s.db.logger != nil && s.db.logger.OnCodeChange != nil {
// TODO remove prevcode from this callback
s.db.logger.OnCodeChange(s.address, common.BytesToHash(s.CodeHash()), nil, codeHash, code)

View file

@ -372,6 +372,12 @@ func newTestAction(addr common.Address, r *rand.Rand) testAction {
{
name: "SetCode",
fn: func(a testAction, s *StateDB) {
// SetCode can only be performed in case the addr does
// not already hold code
if c := s.GetCode(addr); len(c) > 0 {
// no-op
return
}
code := make([]byte, 16)
binary.BigEndian.PutUint64(code, uint64(a.args[0]))
binary.BigEndian.PutUint64(code[8:], uint64(a.args[1]))