mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
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:
parent
45cb5cd202
commit
7ea867c727
4 changed files with 17 additions and 19 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"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/log"
|
||||
"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.
|
||||
// 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
|
||||
state := &StateDB{
|
||||
db: s.db,
|
||||
|
|
@ -1409,6 +1410,8 @@ func (s *StateDB) convertAccountSet(set map[common.Address]*types.StateAccount)
|
|||
return ret
|
||||
}
|
||||
|
||||
func (s *StateDB) SetEVM(evm *vm.EVM) {}
|
||||
|
||||
// copySet returns a deep-copied set.
|
||||
func copySet[k comparable](set map[k][]byte) map[k][]byte {
|
||||
copied := make(map[k][]byte, len(set))
|
||||
|
|
|
|||
|
|
@ -174,24 +174,24 @@ func TestCopy(t *testing.T) {
|
|||
orig.Finalise(false)
|
||||
|
||||
// Copy the state
|
||||
copy := orig.Copy().(*StateDB)
|
||||
copy := orig.Copy()
|
||||
|
||||
// Copy the copy state
|
||||
ccopy := copy.Copy().(*StateDB)
|
||||
ccopy := copy.Copy()
|
||||
|
||||
// modify all in memory
|
||||
for i := byte(0); i < 255; i++ {
|
||||
origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
copyObj := copy.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
ccopyObj := ccopy.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
copyObj := copy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
ccopyObj := ccopy.(*StateDB).GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
|
||||
origObj.AddBalance(big.NewInt(2*int64(i)), tracing.BalanceChangeUnspecified)
|
||||
copyObj.AddBalance(big.NewInt(3*int64(i)), tracing.BalanceChangeUnspecified)
|
||||
ccopyObj.AddBalance(big.NewInt(4*int64(i)), tracing.BalanceChangeUnspecified)
|
||||
|
||||
orig.updateStateObject(origObj)
|
||||
copy.updateStateObject(copyObj)
|
||||
ccopy.updateStateObject(copyObj)
|
||||
copy.(*StateDB).updateStateObject(copyObj)
|
||||
ccopy.(*StateDB).updateStateObject(copyObj)
|
||||
}
|
||||
|
||||
// Finalise the changes on all concurrently
|
||||
|
|
@ -203,15 +203,15 @@ func TestCopy(t *testing.T) {
|
|||
var wg sync.WaitGroup
|
||||
wg.Add(3)
|
||||
go finalise(&wg, orig)
|
||||
go finalise(&wg, copy)
|
||||
go finalise(&wg, ccopy)
|
||||
go finalise(&wg, copy.(*StateDB))
|
||||
go finalise(&wg, ccopy.(*StateDB))
|
||||
wg.Wait()
|
||||
|
||||
// Verify that the three states have been updated independently
|
||||
for i := byte(0); i < 255; i++ {
|
||||
origObj := orig.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
copyObj := copy.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
ccopyObj := ccopy.GetOrNewStateObject(common.BytesToAddress([]byte{i}))
|
||||
copyObj := copy.(*StateDB).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 {
|
||||
t.Errorf("orig obj %d: balance mismatch: have %v, want %v", i, origObj.Balance(), want)
|
||||
|
|
|
|||
|
|
@ -88,15 +88,12 @@ type StateDB interface {
|
|||
Finalise(deleteEmptyObjects bool)
|
||||
Commit(block uint64, deleteEmptyObjects bool) (common.Hash, error)
|
||||
SetTxContext(thash common.Hash, ti int)
|
||||
Copy() interface{}
|
||||
Copy() StateDB
|
||||
IntermediateRoot(deleteEmptyObjects bool) common.Hash
|
||||
GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log
|
||||
TxIndex() int
|
||||
Preimages() map[common.Hash][]byte
|
||||
SetLogger(logger *tracing.Hooks)
|
||||
}
|
||||
|
||||
type EVMAssignable interface {
|
||||
SetEVM(evm *EVM)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,13 +209,11 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
|
|||
msgContext = core.NewEVMTxContext(call)
|
||||
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})
|
||||
)
|
||||
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
|
||||
// a dangling goroutine until the outer estimation finishes, create an internal
|
||||
// context for the lifetime of this method call.
|
||||
|
|
|
|||
Loading…
Reference in a new issue