aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/runtime')
-rw-r--r--core/vm/runtime/env.go16
-rw-r--r--core/vm/runtime/runtime.go29
-rw-r--r--core/vm/runtime/runtime_test.go15
3 files changed, 15 insertions, 45 deletions
diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go
index 77519df81..ce64d7117 100644
--- a/core/vm/runtime/env.go
+++ b/core/vm/runtime/env.go
@@ -41,11 +41,13 @@ type Env struct {
logs []vm.StructLog
getHashFn func(uint64) common.Hash
+
+ evm *vm.EVM
}
// NewEnv returns a new vm.Environment
func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
- return &Env{
+ env := &Env{
state: state,
origin: cfg.Origin,
coinbase: cfg.Coinbase,
@@ -54,6 +56,17 @@ func NewEnv(cfg *Config, state *state.StateDB) vm.Environment {
difficulty: cfg.Difficulty,
gasLimit: cfg.GasLimit,
}
+ env.evm = vm.New(env, &vm.Config{
+ Debug: cfg.Debug,
+ EnableJit: !cfg.DisableJit,
+ ForceJit: !cfg.DisableJit,
+
+ Logger: vm.LogConfig{
+ Collector: env,
+ },
+ })
+
+ return env
}
func (self *Env) StructLogs() []vm.StructLog {
@@ -64,6 +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) Origin() common.Address { return self.origin }
func (self *Env) BlockNumber() *big.Int { return self.number }
func (self *Env) Coinbase() common.Address { return self.coinbase }
diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go
index 3e6057142..f88a20170 100644
--- a/core/vm/runtime/runtime.go
+++ b/core/vm/runtime/runtime.go
@@ -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
}
diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go
index e5183052f..88c76c731 100644
--- a/core/vm/runtime/runtime_test.go
+++ b/core/vm/runtime/runtime_test.go
@@ -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"}]`