mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
core/state: remove unneeded trampoline funcs in hookedStateDB
This commit is contained in:
parent
f96f82bd6b
commit
7d31117a9e
1 changed files with 17 additions and 136 deletions
|
|
@ -20,19 +20,16 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/stateless"
|
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"github.com/ethereum/go-ethereum/trie/utils"
|
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
// hookedStateDB represents a statedb which emits calls to tracing-hooks
|
// hookedStateDB represents a statedb which emits calls to tracing-hooks
|
||||||
// on state operations.
|
// on state operations.
|
||||||
type hookedStateDB struct {
|
type hookedStateDB struct {
|
||||||
inner *StateDB
|
*StateDB
|
||||||
hooks *tracing.Hooks
|
hooks *tracing.Hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,124 +42,8 @@ func NewHookedState(stateDb *StateDB, hooks *tracing.Hooks) *hookedStateDB {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) CreateAccount(addr common.Address) {
|
|
||||||
s.inner.CreateAccount(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) CreateContract(addr common.Address) {
|
|
||||||
s.inner.CreateContract(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetBalance(addr common.Address) *uint256.Int {
|
|
||||||
return s.inner.GetBalance(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetNonce(addr common.Address) uint64 {
|
|
||||||
return s.inner.GetNonce(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCodeHash(addr common.Address) common.Hash {
|
|
||||||
return s.inner.GetCodeHash(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCode(addr common.Address) []byte {
|
|
||||||
return s.inner.GetCode(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetCodeSize(addr common.Address) int {
|
|
||||||
return s.inner.GetCodeSize(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AddRefund(u uint64) {
|
|
||||||
s.inner.AddRefund(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) SubRefund(u uint64) {
|
|
||||||
s.inner.SubRefund(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetRefund() uint64 {
|
|
||||||
return s.inner.GetRefund()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetStateAndCommittedState(addr common.Address, hash common.Hash) (common.Hash, common.Hash) {
|
|
||||||
return s.inner.GetStateAndCommittedState(addr, hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
|
|
||||||
return s.inner.GetState(addr, hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetStorageRoot(addr common.Address) common.Hash {
|
|
||||||
return s.inner.GetStorageRoot(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) GetTransientState(addr common.Address, key common.Hash) common.Hash {
|
|
||||||
return s.inner.GetTransientState(addr, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) SetTransientState(addr common.Address, key, value common.Hash) {
|
|
||||||
s.inner.SetTransientState(addr, key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) HasSelfDestructed(addr common.Address) bool {
|
|
||||||
return s.inner.HasSelfDestructed(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) Exist(addr common.Address) bool {
|
|
||||||
return s.inner.Exist(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) Empty(addr common.Address) bool {
|
|
||||||
return s.inner.Empty(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AddressInAccessList(addr common.Address) bool {
|
|
||||||
return s.inner.AddressInAccessList(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool) {
|
|
||||||
return s.inner.SlotInAccessList(addr, slot)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AddAddressToAccessList(addr common.Address) {
|
|
||||||
s.inner.AddAddressToAccessList(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AddSlotToAccessList(addr common.Address, slot common.Hash) {
|
|
||||||
s.inner.AddSlotToAccessList(addr, slot)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) PointCache() *utils.PointCache {
|
|
||||||
return s.inner.PointCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList) {
|
|
||||||
s.inner.Prepare(rules, sender, coinbase, dest, precompiles, txAccesses)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) RevertToSnapshot(i int) {
|
|
||||||
s.inner.RevertToSnapshot(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) Snapshot() int {
|
|
||||||
return s.inner.Snapshot()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AddPreimage(hash common.Hash, bytes []byte) {
|
|
||||||
s.inner.AddPreimage(hash, bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) Witness() *stateless.Witness {
|
|
||||||
return s.inner.Witness()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) AccessEvents() *AccessEvents {
|
|
||||||
return s.inner.AccessEvents()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *hookedStateDB) SubBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
|
func (s *hookedStateDB) SubBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
|
||||||
prev := s.inner.SubBalance(addr, amount, reason)
|
prev := s.StateDB.SubBalance(addr, amount, reason)
|
||||||
if s.hooks.OnBalanceChange != nil && !amount.IsZero() {
|
if s.hooks.OnBalanceChange != nil && !amount.IsZero() {
|
||||||
newBalance := new(uint256.Int).Sub(&prev, amount)
|
newBalance := new(uint256.Int).Sub(&prev, amount)
|
||||||
s.hooks.OnBalanceChange(addr, prev.ToBig(), newBalance.ToBig(), reason)
|
s.hooks.OnBalanceChange(addr, prev.ToBig(), newBalance.ToBig(), reason)
|
||||||
|
|
@ -171,7 +52,7 @@ func (s *hookedStateDB) SubBalance(addr common.Address, amount *uint256.Int, rea
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) AddBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
|
func (s *hookedStateDB) AddBalance(addr common.Address, amount *uint256.Int, reason tracing.BalanceChangeReason) uint256.Int {
|
||||||
prev := s.inner.AddBalance(addr, amount, reason)
|
prev := s.StateDB.AddBalance(addr, amount, reason)
|
||||||
if s.hooks.OnBalanceChange != nil && !amount.IsZero() {
|
if s.hooks.OnBalanceChange != nil && !amount.IsZero() {
|
||||||
newBalance := new(uint256.Int).Add(&prev, amount)
|
newBalance := new(uint256.Int).Add(&prev, amount)
|
||||||
s.hooks.OnBalanceChange(addr, prev.ToBig(), newBalance.ToBig(), reason)
|
s.hooks.OnBalanceChange(addr, prev.ToBig(), newBalance.ToBig(), reason)
|
||||||
|
|
@ -180,8 +61,8 @@ func (s *hookedStateDB) AddBalance(addr common.Address, amount *uint256.Int, rea
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) SetNonce(address common.Address, nonce uint64, reason tracing.NonceChangeReason) {
|
func (s *hookedStateDB) SetNonce(address common.Address, nonce uint64, reason tracing.NonceChangeReason) {
|
||||||
prev := s.inner.GetNonce(address)
|
prev := s.GetNonce(address)
|
||||||
s.inner.SetNonce(address, nonce, reason)
|
s.StateDB.SetNonce(address, nonce, reason)
|
||||||
if s.hooks.OnNonceChangeV2 != nil {
|
if s.hooks.OnNonceChangeV2 != nil {
|
||||||
s.hooks.OnNonceChangeV2(address, prev, nonce, reason)
|
s.hooks.OnNonceChangeV2(address, prev, nonce, reason)
|
||||||
} else if s.hooks.OnNonceChange != nil {
|
} else if s.hooks.OnNonceChange != nil {
|
||||||
|
|
@ -190,7 +71,7 @@ func (s *hookedStateDB) SetNonce(address common.Address, nonce uint64, reason tr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) SetCode(address common.Address, code []byte) []byte {
|
func (s *hookedStateDB) SetCode(address common.Address, code []byte) []byte {
|
||||||
prev := s.inner.SetCode(address, code)
|
prev := s.StateDB.SetCode(address, code)
|
||||||
if s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChange != nil {
|
||||||
prevHash := types.EmptyCodeHash
|
prevHash := types.EmptyCodeHash
|
||||||
if len(prev) != 0 {
|
if len(prev) != 0 {
|
||||||
|
|
@ -202,7 +83,7 @@ func (s *hookedStateDB) SetCode(address common.Address, code []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
prev := s.inner.SetState(address, key, value)
|
prev := s.StateDB.SetState(address, key, value)
|
||||||
if s.hooks.OnStorageChange != nil && prev != value {
|
if s.hooks.OnStorageChange != nil && prev != value {
|
||||||
s.hooks.OnStorageChange(address, key, prev, value)
|
s.hooks.OnStorageChange(address, key, prev, value)
|
||||||
}
|
}
|
||||||
|
|
@ -214,11 +95,11 @@ func (s *hookedStateDB) SelfDestruct(address common.Address) uint256.Int {
|
||||||
var prevCodeHash common.Hash
|
var prevCodeHash common.Hash
|
||||||
|
|
||||||
if s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChange != nil {
|
||||||
prevCode = s.inner.GetCode(address)
|
prevCode = s.GetCode(address)
|
||||||
prevCodeHash = s.inner.GetCodeHash(address)
|
prevCodeHash = s.GetCodeHash(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
prev := s.inner.SelfDestruct(address)
|
prev := s.StateDB.SelfDestruct(address)
|
||||||
|
|
||||||
if s.hooks.OnBalanceChange != nil && !prev.IsZero() {
|
if s.hooks.OnBalanceChange != nil && !prev.IsZero() {
|
||||||
s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
|
s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
|
||||||
|
|
@ -236,11 +117,11 @@ func (s *hookedStateDB) SelfDestruct6780(address common.Address) (uint256.Int, b
|
||||||
var prevCodeHash common.Hash
|
var prevCodeHash common.Hash
|
||||||
|
|
||||||
if s.hooks.OnCodeChange != nil {
|
if s.hooks.OnCodeChange != nil {
|
||||||
prevCodeHash = s.inner.GetCodeHash(address)
|
prevCodeHash = s.GetCodeHash(address)
|
||||||
prevCode = s.inner.GetCode(address)
|
prevCode = s.GetCode(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
prev, changed := s.inner.SelfDestruct6780(address)
|
prev, changed := s.StateDB.SelfDestruct6780(address)
|
||||||
|
|
||||||
if s.hooks.OnBalanceChange != nil && changed && !prev.IsZero() {
|
if s.hooks.OnBalanceChange != nil && changed && !prev.IsZero() {
|
||||||
s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
|
s.hooks.OnBalanceChange(address, prev.ToBig(), new(big.Int), tracing.BalanceDecreaseSelfdestruct)
|
||||||
|
|
@ -255,19 +136,19 @@ func (s *hookedStateDB) SelfDestruct6780(address common.Address) (uint256.Int, b
|
||||||
|
|
||||||
func (s *hookedStateDB) AddLog(log *types.Log) {
|
func (s *hookedStateDB) AddLog(log *types.Log) {
|
||||||
// The inner will modify the log (add fields), so invoke that first
|
// The inner will modify the log (add fields), so invoke that first
|
||||||
s.inner.AddLog(log)
|
s.StateDB.AddLog(log)
|
||||||
if s.hooks.OnLog != nil {
|
if s.hooks.OnLog != nil {
|
||||||
s.hooks.OnLog(log)
|
s.hooks.OnLog(log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {
|
func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
defer s.inner.Finalise(deleteEmptyObjects)
|
defer s.StateDB.Finalise(deleteEmptyObjects)
|
||||||
if s.hooks.OnBalanceChange == nil {
|
if s.hooks.OnBalanceChange == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for addr := range s.inner.journal.dirties {
|
for addr := range s.StateDB.journal.dirties {
|
||||||
obj := s.inner.stateObjects[addr]
|
obj := s.StateDB.stateObjects[addr]
|
||||||
if obj != nil && obj.selfDestructed {
|
if obj != nil && obj.selfDestructed {
|
||||||
// If ether was sent to account post-selfdestruct it is burnt.
|
// If ether was sent to account post-selfdestruct it is burnt.
|
||||||
if bal := obj.Balance(); bal.Sign() != 0 {
|
if bal := obj.Balance(); bal.Sign() != 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue