aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-01 22:30:29 +0800
committerobscuren <geffobscura@gmail.com>2015-02-01 22:30:29 +0800
commit8ccde784f9035c0a7a8f234994538c817c5b9de7 (patch)
tree6fc252d3372510abda8fd16297caca481b5beeae
parentd52878c744fd7acce727feb41c2d4296e56826d3 (diff)
downloadgo-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar.gz
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar.bz2
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar.lz
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar.xz
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.tar.zst
go-tangerine-8ccde784f9035c0a7a8f234994538c817c5b9de7.zip
Added (disabled) Jit validation
-rw-r--r--core/execution.go3
-rw-r--r--core/state_transition.go25
-rw-r--r--core/vm_env.go4
-rw-r--r--eth/backend.go3
-rw-r--r--vm/common.go12
5 files changed, 43 insertions, 4 deletions
diff --git a/core/execution.go b/core/execution.go
index cad4e84aa..5e0cbd37e 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -33,8 +33,7 @@ func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, erro
func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret []byte, err error) {
env := self.env
- evm := vm.New(env)
-
+ evm := vm.NewVm(env)
if env.Depth() == vm.MaxCallDepth {
caller.ReturnGas(self.Gas, self.price)
diff --git a/core/state_transition.go b/core/state_transition.go
index 8b0ca2ac4..00d9d486a 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/vm"
)
+const tryJit = false
+
/*
* The State transitioning model
*
@@ -184,6 +186,7 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
return
}
+ stateCopy := self.env.State().Copy()
vmenv := self.env
var ref vm.ContextRef
if MessageCreatesContract(msg) {
@@ -196,8 +199,30 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
ref.SetCode(ret)
}
}
+
+ if vmenv, ok := vmenv.(*VMEnv); ok && tryJit {
+ statelogger.Infof("CREATE: re-running using JIT (PH=%x)\n", stateCopy.Root()[:4])
+ // re-run using the JIT (validation for the JIT)
+ goodState := vmenv.State().Copy()
+ vmenv.state = stateCopy
+ vmenv.SetVmType(vm.JitVmTy)
+ vmenv.Create(sender, contract.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+ statelogger.Infof("DONE PH=%x STD_H=%x JIT_H=%x\n", stateCopy.Root()[:4], goodState.Root()[:4], vmenv.State().Root()[:4])
+ self.state.Set(goodState)
+ }
} else {
ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+
+ if vmenv, ok := vmenv.(*VMEnv); ok && tryJit {
+ statelogger.Infof("CALL: re-running using JIT (PH=%x)\n", stateCopy.Root()[:4])
+ // re-run using the JIT (validation for the JIT)
+ goodState := vmenv.State().Copy()
+ vmenv.state = stateCopy
+ vmenv.SetVmType(vm.JitVmTy)
+ vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+ statelogger.Infof("DONE PH=%x STD_H=%x JIT_H=%x\n", stateCopy.Root()[:4], goodState.Root()[:4], vmenv.State().Root()[:4])
+ self.state.Set(goodState)
+ }
}
if err != nil {
diff --git a/core/vm_env.go b/core/vm_env.go
index 624a63333..c7491bcdc 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -14,6 +14,7 @@ type VMEnv struct {
msg Message
depth int
chain *ChainManager
+ typ vm.Type
}
func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, block *types.Block) *VMEnv {
@@ -22,6 +23,7 @@ func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, block *types
state: state,
block: block,
msg: msg,
+ typ: vm.StdVmTy,
}
}
@@ -35,6 +37,8 @@ func (self *VMEnv) Value() *big.Int { return self.msg.Value() }
func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
+func (self *VMEnv) VmType() vm.Type { return self.typ }
+func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t }
func (self *VMEnv) GetHash(n uint64) []byte {
if block := self.chain.GetBlockByNumber(n); block != nil {
return block.Hash()
diff --git a/eth/backend.go b/eth/backend.go
index b7b5c5f85..a8db3ab20 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -141,14 +141,13 @@ func New(config *Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
- fmt.Println(nat)
eth.net = &p2p.Server{
Identity: clientId,
MaxPeers: config.MaxPeers,
Protocols: protocols,
Blacklist: eth.blacklist,
- NAT: p2p.UPNP(),
+ NAT: nat,
NoDial: !config.Dial,
}
diff --git a/vm/common.go b/vm/common.go
index ff187001f..45a7187a9 100644
--- a/vm/common.go
+++ b/vm/common.go
@@ -18,6 +18,18 @@ const (
MaxVmTy
)
+func NewVm(env Environment) VirtualMachine {
+ switch env.VmType() {
+ case JitVmTy:
+ return NewJitVm(env)
+ default:
+ vmlogger.Infoln("unsupported vm type %d", env.VmType())
+ fallthrough
+ case StdVmTy:
+ return New(env)
+ }
+}
+
var (
GasStep = big.NewInt(1)
GasSha = big.NewInt(10)