aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorjm <jm.huang@cobinhood.com>2019-01-16 17:32:29 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:03 +0800
commitd3b485a5af768db59bd648175849f961e25bc630 (patch)
treeec43033c9aa438969cea45fb9de19e50a88a5cd8 /eth
parent266068a53cdf9e06acacf982d63653c03133a634 (diff)
downloaddexon-d3b485a5af768db59bd648175849f961e25bc630.tar.gz
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.zst
dexon-d3b485a5af768db59bd648175849f961e25bc630.zip
core: vm: extract stateDB and contract out
Extract stateDB and contract out from core/vm/evm to core/vm, such that other vm type can use the common modules.
Diffstat (limited to 'eth')
-rw-r--r--eth/api_tracer.go35
-rw-r--r--eth/tracers/tracer.go12
-rw-r--r--eth/tracers/tracer_test.go9
-rw-r--r--eth/tracers/tracers_test.go5
4 files changed, 32 insertions, 29 deletions
diff --git a/eth/api_tracer.go b/eth/api_tracer.go
index c3523b8bc..e05bbe0a2 100644
--- a/eth/api_tracer.go
+++ b/eth/api_tracer.go
@@ -34,7 +34,8 @@ import (
"github.com/dexon-foundation/dexon/core/rawdb"
"github.com/dexon-foundation/dexon/core/state"
"github.com/dexon-foundation/dexon/core/types"
- vm "github.com/dexon-foundation/dexon/core/vm/evm"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/core/vm/evm"
"github.com/dexon-foundation/dexon/eth/tracers"
"github.com/dexon-foundation/dexon/internal/ethapi"
"github.com/dexon-foundation/dexon/log"
@@ -56,7 +57,7 @@ const (
// TraceConfig holds extra parameters to trace functions.
type TraceConfig struct {
- *vm.LogConfig
+ *evm.LogConfig
Tracer *string
Timeout *string
Reexec *uint64
@@ -64,7 +65,7 @@ type TraceConfig struct {
// StdTraceConfig holds extra parameters to standard-json trace functions.
type StdTraceConfig struct {
- *vm.LogConfig
+ *evm.LogConfig
Reexec *uint64
TxHash common.Hash
}
@@ -289,7 +290,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
traced += uint64(len(txs))
}
// Generate the next state snapshot fast without tracing
- _, _, _, err := api.eth.blockchain.Processor().Process(block, statedb, vm.Config{})
+ _, _, _, err := api.eth.blockchain.Processor().Process(block, statedb, evm.Config{})
if err != nil {
failed = err
break
@@ -501,7 +502,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
msg, _ := tx.AsMessage(signer)
vmctx := core.NewEVMContext(msg, block.Header(), api.eth.blockchain, nil)
- vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{})
+ vmenv := evm.NewEVM(vmctx, statedb, api.config, evm.Config{})
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil {
failed = err
break
@@ -554,7 +555,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
}
// Retrieve the tracing configurations, or use default values
var (
- logConfig vm.LogConfig
+ logConfig evm.LogConfig
txHash common.Hash
)
if config != nil {
@@ -576,7 +577,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
msg, _ = tx.AsMessage(signer)
vmctx = core.NewEVMContext(msg, block.Header(), api.eth.blockchain, nil)
- vmConf vm.Config
+ vmConf evm.Config
dump *os.File
err error
)
@@ -592,14 +593,14 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
dumps = append(dumps, dump.Name())
// Swap out the noop logger to the standard tracer
- vmConf = vm.Config{
+ vmConf = evm.Config{
Debug: true,
- Tracer: vm.NewJSONLogger(&logConfig, bufio.NewWriter(dump)),
+ Tracer: evm.NewJSONLogger(&logConfig, bufio.NewWriter(dump)),
EnablePreimageRecording: true,
}
}
// Execute the transaction and flush any traces to disk
- vmenv := vm.NewEVM(vmctx, statedb, api.config, vmConf)
+ vmenv := evm.NewEVM(vmctx, statedb, api.config, vmConf)
_, _, _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()))
if dump != nil {
@@ -667,7 +668,7 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (*
if block = api.eth.blockchain.GetBlockByNumber(block.NumberU64() + 1); block == nil {
return nil, fmt.Errorf("block #%d not found", block.NumberU64()+1)
}
- _, _, _, err := api.eth.blockchain.Processor().Process(block, statedb, vm.Config{})
+ _, _, _, err := api.eth.blockchain.Processor().Process(block, statedb, evm.Config{})
if err != nil {
return nil, fmt.Errorf("processing block %d failed: %v", block.NumberU64(), err)
}
@@ -716,7 +717,7 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha
func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) {
// Assemble the structured logger or the JavaScript tracer
var (
- tracer vm.Tracer
+ tracer evm.Tracer
err error
)
switch {
@@ -741,13 +742,13 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
defer cancel()
case config == nil:
- tracer = vm.NewStructLogger(nil)
+ tracer = evm.NewStructLogger(nil)
default:
- tracer = vm.NewStructLogger(config.LogConfig)
+ tracer = evm.NewStructLogger(config.LogConfig)
}
// Run the transaction with tracing enabled.
- vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{Debug: true, Tracer: tracer})
+ vmenv := evm.NewEVM(vmctx, statedb, api.config, evm.Config{Debug: true, Tracer: tracer})
ret, gas, failed, err := core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.Gas()))
if err != nil {
@@ -755,7 +756,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
}
// Depending on the tracer type, format and return the output
switch tracer := tracer.(type) {
- case *vm.StructLogger:
+ case *evm.StructLogger:
return &ethapi.ExecutionResult{
Gas: gas,
Failed: failed,
@@ -797,7 +798,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
return msg, context, statedb, nil
}
// Not yet the searched for transaction, execute on top of the current state
- vmenv := vm.NewEVM(context, statedb, api.config, vm.Config{})
+ vmenv := evm.NewEVM(context, statedb, api.config, evm.Config{})
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
return nil, vm.Context{}, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
}
diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go
index f232df49e..d26cc1fae 100644
--- a/eth/tracers/tracer.go
+++ b/eth/tracers/tracer.go
@@ -178,7 +178,7 @@ func (sw *stackWrapper) pushObject(vm *duktape.Context) {
// dbWrapper provides a JavaScript wrapper around evm.Database.
type dbWrapper struct {
- db evm.StateDB
+ db vm.StateDB
}
// pushObject assembles a JSVM object wrapping a swappable database and pushes it
@@ -233,7 +233,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
// contractWrapper provides a JavaScript wrapper around evm.Contract
type contractWrapper struct {
- contract *evm.Contract
+ contract *vm.Contract
}
// pushObject assembles a JSVM object wrapping a swappable contract and pushes it
@@ -259,7 +259,7 @@ func (cw *contractWrapper) pushObject(vm *duktape.Context) {
// Push the wrapper for contract.Value
vm.PushGoFunction(func(ctx *duktape.Context) int {
- pushBigInt(cw.contract.Value(), ctx)
+ pushBigInt(cw.contract.Value, ctx)
return 1
})
vm.PutPropString(obj, "getValue")
@@ -391,7 +391,7 @@ func New(code string) (*Tracer, error) {
return 1
})
tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int {
- _, ok := evm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))]
+ _, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))]
ctx.PushBoolean(ok)
return 1
})
@@ -533,7 +533,7 @@ func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create b
}
// CaptureState implements the Tracer interface to trace a single step of VM execution.
-func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error {
+func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error {
if jst.err == nil {
// Initialize the context if it wasn't done yet
if !jst.inited {
@@ -572,7 +572,7 @@ func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cos
// CaptureFault implements the Tracer interface to trace an execution fault
// while running an opcode.
-func (jst *Tracer) CaptureFault(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error {
+func (jst *Tracer) CaptureFault(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error {
if jst.err == nil {
// Apart from the error, everything matches the previous invocation
jst.errorValue = new(string)
diff --git a/eth/tracers/tracer_test.go b/eth/tracers/tracer_test.go
index eacc9a591..42343f91a 100644
--- a/eth/tracers/tracer_test.go
+++ b/eth/tracers/tracer_test.go
@@ -26,7 +26,8 @@ import (
"github.com/dexon-foundation/dexon/common"
"github.com/dexon-foundation/dexon/core/state"
- vm "github.com/dexon-foundation/dexon/core/vm/evm"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/core/vm/evm"
"github.com/dexon-foundation/dexon/params"
)
@@ -51,10 +52,10 @@ type dummyStatedb struct {
func (*dummyStatedb) GetRefund() uint64 { return 1337 }
func runTrace(tracer *Tracer) (json.RawMessage, error) {
- env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
+ env := evm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, evm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000)
- contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0}
+ contract.Code = []byte{byte(evm.PUSH1), 0x1, byte(evm.PUSH1), 0x1, 0x0}
_, err := env.Interpreter().Run(contract, []byte{}, false)
if err != nil {
@@ -133,7 +134,7 @@ func TestHaltBetweenSteps(t *testing.T) {
t.Fatal(err)
}
- env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
+ env := evm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, evm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0)
tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)
diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go
index 0b8f75ab3..783c41b7a 100644
--- a/eth/tracers/tracers_test.go
+++ b/eth/tracers/tracers_test.go
@@ -32,7 +32,8 @@ import (
"github.com/dexon-foundation/dexon/common/math"
"github.com/dexon-foundation/dexon/core"
"github.com/dexon-foundation/dexon/core/types"
- vm "github.com/dexon-foundation/dexon/core/vm/evm"
+ "github.com/dexon-foundation/dexon/core/vm"
+ "github.com/dexon-foundation/dexon/core/vm/evm"
"github.com/dexon-foundation/dexon/crypto"
"github.com/dexon-foundation/dexon/ethdb"
"github.com/dexon-foundation/dexon/params"
@@ -248,7 +249,7 @@ func TestCallTracer(t *testing.T) {
if err != nil {
t.Fatalf("failed to create call tracer: %v", err)
}
- evm := vm.NewEVM(context, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
+ evm := evm.NewEVM(context, statedb, test.Genesis.Config, evm.Config{Debug: true, Tracer: tracer})
msg, err := tx.AsMessage(signer)
if err != nil {