core: Added EVM configuration options
The EVM is now initialised with an additional configured object that allows you to turn on debugging options.
This commit is contained in:
committed by
Jeffrey Wilcke
parent
342ae7ce7d
commit
14013372ae
@ -42,7 +42,7 @@ type Env struct {
|
||||
|
||||
getHashFn func(uint64) common.Hash
|
||||
|
||||
evm *vm.Vm
|
||||
evm *vm.EVM
|
||||
}
|
||||
|
||||
// NewEnv returns a new vm.Environment
|
||||
@ -56,7 +56,15 @@ func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
|
||||
difficulty: cfg.Difficulty,
|
||||
gasLimit: cfg.GasLimit,
|
||||
}
|
||||
env.evm = vm.EVM(env)
|
||||
env.evm = vm.New(env, &vm.Config{
|
||||
Debug: cfg.Debug,
|
||||
EnableJit: !cfg.DisableJit,
|
||||
ForceJit: !cfg.DisableJit,
|
||||
|
||||
Logger: vm.LogConfig{
|
||||
Collector: env,
|
||||
},
|
||||
})
|
||||
|
||||
return env
|
||||
}
|
||||
@ -69,7 +77,7 @@ func (self *Env) AddStructLog(log vm.StructLog) {
|
||||
self.logs = append(self.logs, log)
|
||||
}
|
||||
|
||||
func (self *Env) Vm() *vm.Vm { return self.evm }
|
||||
func (self *Env) Vm() vm.Vm { return self.evm }
|
||||
func (self *Env) Origin() common.Address { return self.origin }
|
||||
func (self *Env) BlockNumber() *big.Int { return self.number }
|
||||
func (self *Env) Coinbase() common.Address { return self.coinbase }
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
)
|
||||
@ -84,17 +83,6 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
||||
}
|
||||
setDefaults(cfg)
|
||||
|
||||
// defer the call to setting back the original values
|
||||
defer func(debug, forceJit, enableJit bool) {
|
||||
vm.Debug = debug
|
||||
vm.ForceJit = forceJit
|
||||
vm.EnableJit = enableJit
|
||||
}(vm.Debug, vm.ForceJit, vm.EnableJit)
|
||||
|
||||
vm.ForceJit = !cfg.DisableJit
|
||||
vm.EnableJit = !cfg.DisableJit
|
||||
vm.Debug = cfg.Debug
|
||||
|
||||
if cfg.State == nil {
|
||||
db, _ := ethdb.NewMemDatabase()
|
||||
cfg.State, _ = state.New(common.Hash{}, db)
|
||||
@ -117,9 +105,6 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
||||
cfg.Value,
|
||||
)
|
||||
|
||||
if cfg.Debug {
|
||||
vm.StdErrFormat(vmenv.StructLogs())
|
||||
}
|
||||
return ret, cfg.State, err
|
||||
}
|
||||
|
||||
@ -131,17 +116,6 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
||||
func Call(address common.Address, input []byte, cfg *Config) ([]byte, error) {
|
||||
setDefaults(cfg)
|
||||
|
||||
// defer the call to setting back the original values
|
||||
defer func(debug, forceJit, enableJit bool) {
|
||||
vm.Debug = debug
|
||||
vm.ForceJit = forceJit
|
||||
vm.EnableJit = enableJit
|
||||
}(vm.Debug, vm.ForceJit, vm.EnableJit)
|
||||
|
||||
vm.ForceJit = !cfg.DisableJit
|
||||
vm.EnableJit = !cfg.DisableJit
|
||||
vm.Debug = cfg.Debug
|
||||
|
||||
vmenv := NewEnv(cfg, cfg.State)
|
||||
|
||||
sender := cfg.State.GetOrNewStateObject(cfg.Origin)
|
||||
@ -155,8 +129,5 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, error) {
|
||||
cfg.Value,
|
||||
)
|
||||
|
||||
if cfg.Debug {
|
||||
vm.StdErrFormat(vmenv.StructLogs())
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
@ -117,21 +117,6 @@ func TestCall(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreDefaults(t *testing.T) {
|
||||
Execute(nil, nil, &Config{Debug: true})
|
||||
if vm.ForceJit {
|
||||
t.Error("expected force jit to be disabled")
|
||||
}
|
||||
|
||||
if vm.Debug {
|
||||
t.Error("expected debug to be disabled")
|
||||
}
|
||||
|
||||
if vm.EnableJit {
|
||||
t.Error("expected jit to be disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCall(b *testing.B) {
|
||||
var definition = `[{"constant":true,"inputs":[],"name":"seller","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[],"name":"abort","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"refund","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"buyer","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[],"name":"confirmReceived","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":false,"inputs":[],"name":"confirmPurchase","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[],"name":"Aborted","type":"event"},{"anonymous":false,"inputs":[],"name":"PurchaseConfirmed","type":"event"},{"anonymous":false,"inputs":[],"name":"ItemReceived","type":"event"},{"anonymous":false,"inputs":[],"name":"Refunded","type":"event"}]`
|
||||
|
||||
|
Reference in New Issue
Block a user