Reverted some changes that are not required anymore with the new tracing interface

The new tracing interface avoids an import cycle we have before around `core`, `core/vm` and `core/state`. So I can revert some of the changes needed previously.
This commit is contained in:
Matthieu Vachon 2024-03-15 17:16:44 -04:00
parent 45cb5cd202
commit 7ea867c727
4 changed files with 17 additions and 19 deletions

View file

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/state/snapshot"
"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/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
@ -701,7 +702,7 @@ func (s *StateDB) CreateAccount(addr common.Address) {
// Copy creates a deep, independent copy of the state. // Copy creates a deep, independent copy of the state.
// Snapshots of the copied state cannot be applied to the copy. // Snapshots of the copied state cannot be applied to the copy.
func (s *StateDB) Copy() interface{} { func (s *StateDB) Copy() vm.StateDB {
// Copy all the basic fields, initialize the memory ones // Copy all the basic fields, initialize the memory ones
state := &StateDB{ state := &StateDB{
db: s.db, db: s.db,
@ -1409,6 +1410,8 @@ func (s *StateDB) convertAccountSet(set map[common.Address]*types.StateAccount)
return ret return ret
} }
func (s *StateDB) SetEVM(evm *vm.EVM) {}
// copySet returns a deep-copied set. // copySet returns a deep-copied set.
func copySet[k comparable](set map[k][]byte) map[k][]byte { func copySet[k comparable](set map[k][]byte) map[k][]byte {
copied := make(map[k][]byte, len(set)) copied := make(map[k][]byte, len(set))

View file

@ -174,24 +174,24 @@ func TestCopy(t *testing.T) {
orig.Finalise(false) orig.Finalise(false)
// Copy the state // Copy the state
copy := orig.Copy().(*StateDB) copy := orig.Copy()
// Copy the copy state // Copy the copy state
ccopy := copy.Copy().(*StateDB) ccopy := copy.Copy()
// modify all in memory // modify all in memory
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i})) origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
copyObj := copy.GetOrNewStateObject(common.BytesToAddress([]byte{i})) copyObj := copy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
ccopyObj := ccopy.GetOrNewStateObject(common.BytesToAddress([]byte{i})) ccopyObj := ccopy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
origObj.AddBalance(big.NewInt(2*int64(i)), tracing.BalanceChangeUnspecified) origObj.AddBalance(big.NewInt(2*int64(i)), tracing.BalanceChangeUnspecified)
copyObj.AddBalance(big.NewInt(3*int64(i)), tracing.BalanceChangeUnspecified) copyObj.AddBalance(big.NewInt(3*int64(i)), tracing.BalanceChangeUnspecified)
ccopyObj.AddBalance(big.NewInt(4*int64(i)), tracing.BalanceChangeUnspecified) ccopyObj.AddBalance(big.NewInt(4*int64(i)), tracing.BalanceChangeUnspecified)
orig.updateStateObject(origObj) orig.updateStateObject(origObj)
copy.updateStateObject(copyObj) copy.(*StateDB).updateStateObject(copyObj)
ccopy.updateStateObject(copyObj) ccopy.(*StateDB).updateStateObject(copyObj)
} }
// Finalise the changes on all concurrently // Finalise the changes on all concurrently
@ -203,15 +203,15 @@ func TestCopy(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(3) wg.Add(3)
go finalise(&wg, orig) go finalise(&wg, orig)
go finalise(&wg, copy) go finalise(&wg, copy.(*StateDB))
go finalise(&wg, ccopy) go finalise(&wg, ccopy.(*StateDB))
wg.Wait() wg.Wait()
// Verify that the three states have been updated independently // Verify that the three states have been updated independently
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i})) origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
copyObj := copy.GetOrNewStateObject(common.BytesToAddress([]byte{i})) copyObj := copy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
ccopyObj := ccopy.GetOrNewStateObject(common.BytesToAddress([]byte{i})) ccopyObj := ccopy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
if want := big.NewInt(3 * int64(i)); origObj.Balance().Cmp(want) != 0 { if want := big.NewInt(3 * int64(i)); origObj.Balance().Cmp(want) != 0 {
t.Errorf("orig obj %d: balance mismatch: have %v, want %v", i, origObj.Balance(), want) t.Errorf("orig obj %d: balance mismatch: have %v, want %v", i, origObj.Balance(), want)

View file

@ -88,15 +88,12 @@ type StateDB interface {
Finalise(deleteEmptyObjects bool) Finalise(deleteEmptyObjects bool)
Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error)
SetTxContext(thash common.Hash, ti int) SetTxContext(thash common.Hash, ti int)
Copy() interface{} Copy() StateDB
IntermediateRoot(deleteEmptyObjects bool) common.Hash IntermediateRoot(deleteEmptyObjects bool) common.Hash
GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log
TxIndex() int TxIndex() int
Preimages() map[common.Hash][]byte Preimages() map[common.Hash][]byte
SetLogger(logger *tracing.Hooks) SetLogger(logger *tracing.Hooks)
}
type EVMAssignable interface {
SetEVM(evm *EVM) SetEVM(evm *EVM)
} }

View file

@ -209,13 +209,11 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
msgContext = core.NewEVMTxContext(call) msgContext = core.NewEVMTxContext(call)
evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil) evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil)
dirtyState = opts.State.Copy().(vm.StateDB) dirtyState = opts.State.Copy()
evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true}) evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true})
) )
dirtyState.SetEVM(evm)
if assignable, ok := dirtyState.(vm.EVMAssignable); ok {
assignable.SetEVM(evm)
}
// Monitor the outer context and interrupt the EVM upon cancellation. To avoid // Monitor the outer context and interrupt the EVM upon cancellation. To avoid
// a dangling goroutine until the outer estimation finishes, create an internal // a dangling goroutine until the outer estimation finishes, create an internal
// context for the lifetime of this method call. // context for the lifetime of this method call.