mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
core/state: fix hooks to account for setcode on non-empty code
This commit is contained in:
parent
bd36423319
commit
3764d420c2
4 changed files with 18 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -541,9 +542,11 @@ func (s *stateObject) CodeSize() int {
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
|
func (s *stateObject) SetCode(codeHash common.Hash, code []byte) (prev []byte) {
|
||||||
s.db.journal.setCode(s.address)
|
s.db.journal.setCode(s.address)
|
||||||
|
prev = slices.Clone(s.code)
|
||||||
s.setCode(codeHash, code)
|
s.setCode(codeHash, code)
|
||||||
|
return prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
|
func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
|
||||||
|
|
|
||||||
|
|
@ -439,11 +439,12 @@ func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateDB) SetCode(addr common.Address, code []byte) {
|
func (s *StateDB) SetCode(addr common.Address, code []byte) (prev []byte) {
|
||||||
stateObject := s.getOrNewStateObject(addr)
|
stateObject := s.getOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetCode(crypto.Keccak256Hash(code), code)
|
return stateObject.SetCode(crypto.Keccak256Hash(code), code)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) common.Hash {
|
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) common.Hash {
|
||||||
|
|
|
||||||
|
|
@ -182,11 +182,16 @@ func (s *hookedStateDB) SetNonce(address common.Address, nonce uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) SetCode(address common.Address, code []byte) {
|
func (s *hookedStateDB) SetCode(address common.Address, code []byte) []byte {
|
||||||
s.inner.SetCode(address, code)
|
prev := s.inner.SetCode(address, code)
|
||||||
if s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChange != nil {
|
||||||
s.hooks.OnCodeChange(address, types.EmptyCodeHash, nil, crypto.Keccak256Hash(code), code)
|
prevHash := types.EmptyCodeHash
|
||||||
|
if len(prev) != 0 {
|
||||||
|
prevHash = crypto.Keccak256Hash(prev)
|
||||||
|
}
|
||||||
|
s.hooks.OnCodeChange(address, prevHash, prev, crypto.Keccak256Hash(code), code)
|
||||||
}
|
}
|
||||||
|
return prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) SetState(address common.Address, key common.Hash, value common.Hash) common.Hash {
|
func (s *hookedStateDB) SetState(address common.Address, key common.Hash, value common.Hash) common.Hash {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,9 @@ type StateDB interface {
|
||||||
|
|
||||||
GetCodeHash(common.Address) common.Hash
|
GetCodeHash(common.Address) common.Hash
|
||||||
GetCode(common.Address) []byte
|
GetCode(common.Address) []byte
|
||||||
SetCode(common.Address, []byte)
|
|
||||||
|
// SetCode sets the new code for the address, and returns the previous code, if any.
|
||||||
|
SetCode(common.Address, []byte) []byte
|
||||||
GetCodeSize(common.Address) int
|
GetCodeSize(common.Address) int
|
||||||
|
|
||||||
AddRefund(uint64)
|
AddRefund(uint64)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue