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 /core/vm/sqlvm | |
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 'core/vm/sqlvm')
-rw-r--r-- | core/vm/sqlvm/sqlvm.go | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/core/vm/sqlvm/sqlvm.go b/core/vm/sqlvm/sqlvm.go index fe2eee42b..26aeeab0b 100644 --- a/core/vm/sqlvm/sqlvm.go +++ b/core/vm/sqlvm/sqlvm.go @@ -8,60 +8,65 @@ import ( "github.com/dexon-foundation/dexon/params" ) +// SQLVM implements the required VM interface. type SQLVM struct { // Context provides auxiliary blockchain related information - vm.Context + *vm.Context // StateDB gives access to the underlying state StateDB vm.StateDB - // Depth is the current call stack - depth int - // chainConfig contains information about the current chain - chainConfig *params.ChainConfig - // chain rules contains the chain rules for the current epoch - chainRules params.Rules // abort is used to abort the SQLVM calling operations // NOTE: must be set atomically abort int32 - // callGasTemp holds the gas available for the current call. This is needed because the - // available gas is calculated in gasCall* according to the 63/64 rule and later - // applied in opCall*. - callGasTemp uint64 } func init() { - vm.Register(vm.SQLVM, &SQLVM{}) + vm.Register(vm.SQLVM, NewSQLVM) } +// NewSQLVM is the SQLVM constructor. +func NewSQLVM(context *vm.Context, stateDB vm.StateDB, chainConfig *params.ChainConfig, vmConfig interface{}) vm.VM { + return &SQLVM{Context: context, StateDB: stateDB} +} + +// Create creates SQL contract. func (sqlvm *SQLVM) Create(caller vm.ContractRef, code []byte, gas uint64, value *big.Int, - in vm.Interpreter) ([]byte, common.Address, uint64, error) { + pack *vm.ExecPack) ([]byte, common.Address, uint64, error) { // todo (jm) need to implemnt return nil, common.Address{}, gas, nil } +// Create2 mock interface. func (sqlvm *SQLVM) Create2(caller vm.ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int, - in vm.Interpreter) ([]byte, common.Address, uint64, error) { + pack *vm.ExecPack) ([]byte, common.Address, uint64, error) { // todo (jm) need to implemnt return nil, common.Address{}, gas, nil } + +// Call is the entry to call SQLVM contract. func (sqlvm *SQLVM) Call(caller vm.ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int, - in vm.Interpreter) ([]byte, uint64, error) { + pack *vm.ExecPack) ([]byte, uint64, error) { // todo (jm) need to implemnt return nil, gas, nil } + +// CallCode mock interface. func (sqlvm *SQLVM) CallCode(caller vm.ContractRef, addr common.Address, input []byte, gas uint64, - value *big.Int, in vm.Interpreter) ([]byte, uint64, error) { + value *big.Int, pack *vm.ExecPack) ([]byte, uint64, error) { // todo (jm) need to implemnt return nil, gas, nil } +// DelegateCall mock interface. func (sqlvm *SQLVM) DelegateCall(caller vm.ContractRef, addr common.Address, input []byte, gas uint64, - in vm.Interpreter) ([]byte, uint64, error) { + pack *vm.ExecPack) ([]byte, uint64, error) { // todo (jm) need to implemnt return nil, gas, nil } + +// StaticCall is the entry for read-only call on SQL contract. func (sqlvm *SQLVM) StaticCall(caller vm.ContractRef, addr common.Address, input []byte, gas uint64, - in vm.Interpreter) ([]byte, uint64, error) { + pack *vm.ExecPack) ([]byte, uint64, error) { // todo (jm) need to implemnt return nil, gas, nil } |