Skip to content

Commit 1401337

Browse files
committed
core: Added EVM configuration options
The EVM is now initialised with an additional configured object that allows you to turn on debugging options.
1 parent 342ae7c commit 1401337

30 files changed

Lines changed: 407 additions & 229 deletions

‎cmd/ethtest/main.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"strings"
2727

2828
"github.com/codegangsta/cli"
29-
"github.com/ethereum/go-ethereum/core/vm"
3029
"github.com/ethereum/go-ethereum/logger/glog"
3130
"github.com/ethereum/go-ethereum/tests"
3231
)
@@ -188,7 +187,6 @@ func setupApp(c *cli.Context) {
188187
continueOnError = c.GlobalBool(ContinueOnErrorFlag.Name)
189188
useStdIn := c.GlobalBool(ReadStdInFlag.Name)
190189
skipTests = strings.Split(c.GlobalString(SkipTestsFlag.Name), " ")
191-
vm.Debug = c.GlobalBool(TraceFlag.Name)
192190

193191
if !useStdIn {
194192
runSuite(flagTest, flagFile)

‎cmd/evm/main.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func init() {
106106
}
107107

108108
func run(ctx *cli.Context) {
109-
vm.Debug = ctx.GlobalBool(DebugFlag.Name)
110109
vm.ForceJit = ctx.GlobalBool(ForceJitFlag.Name)
111110
vm.EnableJit = !ctx.GlobalBool(DisableJitFlag.Name)
112111

@@ -119,7 +118,9 @@ func run(ctx *cli.Context) {
119118
receiver := statedb.CreateAccount(common.StringToAddress("receiver"))
120119
receiver.SetCode(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)))
121120

122-
vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(ctx.GlobalString(ValueFlag.Name)))
121+
vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(ctx.GlobalString(ValueFlag.Name)), &vm.Config{
122+
Debug: ctx.GlobalBool(DebugFlag.Name),
123+
})
123124

124125
tstart := time.Now()
125126
ret, e := vmenv.Call(
@@ -176,22 +177,24 @@ type VMEnv struct {
176177
time *big.Int
177178
logs []vm.StructLog
178179

179-
evm *vm.Vm
180+
evm *vm.EVM
180181
}
181182

182-
func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int) *VMEnv {
183+
func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int, cfg *vm.Config) *VMEnv {
183184
params.HomesteadBlock = new(big.Int)
184185
env := &VMEnv{
185186
state: state,
186187
transactor: &transactor,
187188
value: value,
188189
time: big.NewInt(time.Now().Unix()),
189190
}
190-
env.evm = vm.EVM(env)
191+
cfg.Logger.Collector = env
192+
193+
env.evm = vm.New(env, cfg)
191194
return env
192195
}
193196

194-
func (self *VMEnv) Vm() *vm.Vm { return self.evm }
197+
func (self *VMEnv) Vm() vm.Vm { return self.evm }
195198
func (self *VMEnv) Db() vm.Database { return self.state }
196199
func (self *VMEnv) MakeSnapshot() vm.Database { return self.state.Copy() }
197200
func (self *VMEnv) SetSnapshot(db vm.Database) { self.state.Set(db.(*state.StateDB)) }

‎cmd/geth/main.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
321321
utils.WhisperEnabledFlag,
322322
utils.DevModeFlag,
323323
utils.TestNetFlag,
324-
utils.VMDebugFlag,
325324
utils.VMForceJitFlag,
326325
utils.VMJitCacheFlag,
327326
utils.VMEnableJitFlag,

‎cmd/geth/usage.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ var AppHelpFlagGroups = []flagGroup{
142142
{
143143
Name: "VIRTUAL MACHINE",
144144
Flags: []cli.Flag{
145-
utils.VMDebugFlag,
146145
utils.VMEnableJitFlag,
147146
utils.VMForceJitFlag,
148147
utils.VMJitCacheFlag,

‎cmd/utils/flags.go‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ var (
203203
Value: "",
204204
}
205205

206-
// vm flags
207-
VMDebugFlag = cli.BoolFlag{
208-
Name: "vmdebug",
209-
Usage: "Virtual Machine debug output",
210-
}
211206
VMForceJitFlag = cli.BoolFlag{
212207
Name: "forcejit",
213208
Usage: "Force the JIT VM to take precedence",
@@ -728,9 +723,6 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
728723
if !ctx.GlobalIsSet(WhisperEnabledFlag.Name) {
729724
shhEnable = true
730725
}
731-
if !ctx.GlobalIsSet(VMDebugFlag.Name) {
732-
vm.Debug = true
733-
}
734726
ethConf.PowTest = true
735727
}
736728
// Assemble and return the protocol stack
@@ -771,9 +763,6 @@ func SetupVM(ctx *cli.Context) {
771763
vm.EnableJit = ctx.GlobalBool(VMEnableJitFlag.Name)
772764
vm.ForceJit = ctx.GlobalBool(VMForceJitFlag.Name)
773765
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
774-
if ctx.GlobalIsSet(VMDebugFlag.Name) {
775-
vm.Debug = ctx.GlobalBool(VMDebugFlag.Name)
776-
}
777766
}
778767

779768
// MakeChain creates a chain manager from set command line flags.

‎common/registrar/ethreg/api.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr
179179
}
180180

181181
header := be.bc.CurrentBlock().Header()
182-
vmenv := core.NewEnv(statedb, be.bc, msg, header)
182+
vmenv := core.NewEnv(statedb, be.bc, msg, header, nil)
183183
gp := new(core.GasPool).AddGas(common.MaxBig)
184184
res, gas, err := core.ApplyMessage(vmenv, msg, gp)
185185

‎core/blockchain.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
891891
return i, err
892892
}
893893
// Process block using the parent state as reference point.
894-
receipts, logs, usedGas, err := self.processor.Process(block, statedb)
894+
receipts, logs, usedGas, err := self.processor.Process(block, statedb, nil)
895895
if err != nil {
896896
reportBlock(block, err)
897897
return i, err

‎core/blockchain_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
141141
if err != nil {
142142
return err
143143
}
144-
receipts, _, usedGas, err := blockchain.Processor().Process(block, statedb)
144+
receipts, _, usedGas, err := blockchain.Processor().Process(block, statedb, nil)
145145
if err != nil {
146146
reportBlock(block, err)
147147
return err
@@ -435,7 +435,7 @@ func (bproc) ValidateHeader(*types.Header, *types.Header, bool) error { return n
435435
func (bproc) ValidateState(block, parent *types.Block, state *state.StateDB, receipts types.Receipts, usedGas *big.Int) error {
436436
return nil
437437
}
438-
func (bproc) Process(block *types.Block, statedb *state.StateDB) (types.Receipts, vm.Logs, *big.Int, error) {
438+
func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg *vm.Config) (types.Receipts, vm.Logs, *big.Int, error) {
439439
return nil, nil, nil, nil
440440
}
441441

‎core/chain_makers.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
9191
b.SetCoinbase(common.Address{})
9292
}
9393
b.statedb.StartRecord(tx.Hash(), common.Hash{}, len(b.txs))
94-
receipt, _, _, err := ApplyTransaction(nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed)
94+
receipt, _, _, err := ApplyTransaction(nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed, nil)
9595
if err != nil {
9696
panic(err)
9797
}

‎core/state/state_object.go‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (self Code) String() string {
3838
return string(self) //strings.Join(Disassemble(self), " ")
3939
}
4040

41-
type Storage map[string]common.Hash
41+
type Storage map[common.Hash]common.Hash
4242

4343
func (self Storage) String() (str string) {
4444
for key, value := range self {
@@ -112,45 +112,44 @@ func (c *StateObject) getAddr(addr common.Hash) common.Hash {
112112
return common.BytesToHash(ret)
113113
}
114114

115-
func (c *StateObject) setAddr(addr []byte, value common.Hash) {
115+
func (c *StateObject) setAddr(addr, value common.Hash) {
116116
v, err := rlp.EncodeToBytes(bytes.TrimLeft(value[:], "\x00"))
117117
if err != nil {
118118
// if RLPing failed we better panic and not fail silently. This would be considered a consensus issue
119119
panic(err)
120120
}
121-
c.trie.Update(addr, v)
121+
c.trie.Update(addr[:], v)
122122
}
123123

124124
func (self *StateObject) Storage() Storage {
125125
return self.storage
126126
}
127127

128128
func (self *StateObject) GetState(key common.Hash) common.Hash {
129-
strkey := key.Str()
130-
value, exists := self.storage[strkey]
129+
value, exists := self.storage[key]
131130
if !exists {
132131
value = self.getAddr(key)
133132
if (value != common.Hash{}) {
134-
self.storage[strkey] = value
133+
self.storage[key] = value
135134
}
136135
}
137136

138137
return value
139138
}
140139

141-
func (self *StateObject) SetState(k, value common.Hash) {
142-
self.storage[k.Str()] = value
140+
func (self *StateObject) SetState(key, value common.Hash) {
141+
self.storage[key] = value
143142
self.dirty = true
144143
}
145144

146145
// Update updates the current cached storage to the trie
147146
func (self *StateObject) Update() {
148147
for key, value := range self.storage {
149148
if (value == common.Hash{}) {
150-
self.trie.Delete([]byte(key))
149+
self.trie.Delete(key[:])
151150
continue
152151
}
153-
self.setAddr([]byte(key), value)
152+
self.setAddr(key, value)
154153
}
155154
}
156155

@@ -245,24 +244,22 @@ func (self *StateObject) Value() *big.Int {
245244
panic("Value on StateObject should never be called")
246245
}
247246

248-
func (self *StateObject) EachStorage(cb func(key, value []byte)) {
247+
func (self *StateObject) ForEachStorage(cb func(key, value common.Hash) bool) {
249248
// When iterating over the storage check the cache first
250-
for h, v := range self.storage {
251-
cb([]byte(h), v.Bytes())
249+
for h, value := range self.storage {
250+
cb(h, value)
252251
}
253252

254253
it := self.trie.Iterator()
255254
for it.Next() {
256255
// ignore cached values
257-
key := self.trie.GetKey(it.Key)
258-
if _, ok := self.storage[string(key)]; !ok {
259-
cb(key, it.Value)
256+
key := common.BytesToHash(self.trie.GetKey(it.Key))
257+
if _, ok := self.storage[key]; !ok {
258+
cb(key, common.BytesToHash(it.Value))
260259
}
261260
}
262261
}
263262

264-
// Encoding
265-
266263
type extStateObject struct {
267264
Nonce uint64
268265
Balance *big.Int

0 commit comments

Comments
 (0)