diff options
author | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-03-27 18:49:38 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:50:26 +0800 |
commit | e715414cae9b4654b4784dfb924880a0787d1d55 (patch) | |
tree | a0772b2a0ef3be4ac03fc608a21ee0b7ccbd167a /accounts | |
parent | 996310cbd484b5ff1ea76068578314d71973770f (diff) | |
download | dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar.gz dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar.bz2 dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar.lz dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar.xz dexon-e715414cae9b4654b4784dfb924880a0787d1d55.tar.zst dexon-e715414cae9b4654b4784dfb924880a0787d1d55.zip |
core: vm: refactor vm config and context
To support multiple VMs, there must be a shared execution environment for each VM,
so this pull request moved some shared component to vm.Context and
implemented the vm.ExecPack to hold the list of VM, list of VM configures,
context and some shared resources.
The adjustment includes:
* Move NoRecursion, Depth, ReadOnly, RandCallIndex, IntPool and CallGasTemp to Context.
* Adjust VM enumeration from byte to uint8, and the VMList from map to
array.
* Register VM constructor in each VM package's init function.
* Initialize all VM instance in NewExecPack.
* Remove EVMImplement, and modify EVM, such that EVM can do the same
functions with EVMImplement.
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/abi/bind/backends/simulated.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index da307663c..6b4943fc0 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.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/filters" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" @@ -69,7 +70,9 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac database := ethdb.NewMemDatabase() genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc} genesis.MustCommit(database) - blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil) + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vmConfig, nil) backend := &SimulatedBackend{ database: database, @@ -282,13 +285,15 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call dexon.CallMsg, // Execute the call. msg := callmsg{call} - evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain, nil) + evmContext := core.NewVMContext(msg, block.Header(), b.blockchain, nil) // Create a new environment which holds all relevant information // about the transaction and calling mechanisms. - vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{}) + vmConfig := [vm.NUMS]interface{}{} + vmConfig[vm.EVM] = evm.Config{} + pack := vm.NewExecPack(evmContext, statedb, b.config, vmConfig) gaspool := new(core.GasPool).AddGas(math.MaxUint64) - return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb() + return core.NewStateTransition(&pack, msg, gaspool).TransitionDb() } // SendTransaction updates the pending block to include the given transaction. |