From 342ae7ce7dfd7a0eab2dd06bfa65199825279f05 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Thu, 21 Jan 2016 15:29:58 +0100 Subject: core, core/vm, tests: changed the initialisation behaviour of the EVM The EVM was previously initialised and created for every CALL, CALLCODE, DELEGATECALL and CREATE. This PR changes this behaviour so that the same EVM can be used through the session and beyond as long as the Environment sticks around. --- core/vm_env.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/vm_env.go') diff --git a/core/vm_env.go b/core/vm_env.go index 7b9a1a0f9..0fab4a090 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -51,10 +51,11 @@ type VMEnv struct { getHashFn func(uint64) common.Hash // structured logging logs []vm.StructLog + evm *vm.Vm } func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header) *VMEnv { - return &VMEnv{ + env := &VMEnv{ chain: chain, state: state, header: header, @@ -62,8 +63,11 @@ func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types. typ: vm.StdVmTy, getHashFn: GetHashFn(header.ParentHash, chain), } + env.evm = vm.EVM(env) + return env } +func (self *VMEnv) Vm() *vm.Vm { return self.evm } func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f } func (self *VMEnv) BlockNumber() *big.Int { return self.header.Number } func (self *VMEnv) Coinbase() common.Address { return self.header.Coinbase } -- cgit v1.2.3 From 14013372aeca2d7f1d8c3a87b7df7c27868314be Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Wed, 3 Feb 2016 23:46:27 +0100 Subject: core: Added EVM configuration options The EVM is now initialised with an additional configured object that allows you to turn on debugging options. --- core/vm_env.go | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'core/vm_env.go') diff --git a/core/vm_env.go b/core/vm_env.go index 0fab4a090..880baa7b0 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -41,33 +41,42 @@ func GetHashFn(ref common.Hash, chain *BlockChain) func(n uint64) common.Hash { } type VMEnv struct { - state *state.StateDB - header *types.Header - msg Message - depth int - chain *BlockChain - typ vm.Type - - getHashFn func(uint64) common.Hash - // structured logging - logs []vm.StructLog - evm *vm.Vm + state *state.StateDB // State to use for executing + evm *vm.EVM // The Ethereum Virtual Machine + depth int // Current execution depth + msg Message // Message appliod + + header *types.Header // Header information + chain *BlockChain // Blockchain handle + logs []vm.StructLog // Logs for the custom structured logger + getHashFn func(uint64) common.Hash // getHashFn callback is used to retrieve block hashes + } -func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header) *VMEnv { +func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header, cfg *vm.Config) *VMEnv { env := &VMEnv{ chain: chain, state: state, header: header, msg: msg, - typ: vm.StdVmTy, getHashFn: GetHashFn(header.ParentHash, chain), } - env.evm = vm.EVM(env) + + // initialise a default config if none present + if cfg == nil { + cfg = new(vm.Config) + } + + // if no log collector is present set self as the collector + if cfg.Logger.Collector == nil { + cfg.Logger.Collector = env + } + + env.evm = vm.New(env, cfg) return env } -func (self *VMEnv) Vm() *vm.Vm { return self.evm } +func (self *VMEnv) Vm() vm.Vm { return self.evm } func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f } func (self *VMEnv) BlockNumber() *big.Int { return self.header.Number } func (self *VMEnv) Coinbase() common.Address { return self.header.Coinbase } @@ -78,8 +87,6 @@ func (self *VMEnv) Value() *big.Int { return self.msg.Value() } func (self *VMEnv) Db() vm.Database { 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) common.Hash { return self.getHashFn(n) } -- cgit v1.2.3