vm

package module
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 36 Imported by: 4

README

Vm is a module for managing all vms(vm-wasmer, vm-evm, vm-gasm and vm-wxvm). It provides the interface for running contracts.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotManageContract = fmt.Errorf("method is not init_contract or upgrade")

ErrorNotManageContract means the method is not init_contract or upgrade

Functions

func GetTxSimContext

func GetTxSimContext(vmManager protocol.VmManager, snapshot protocol.Snapshot, tx *common.Transaction,
	blockVersion uint32, logger protocol.Logger) protocol.TxSimContext

GetTxSimContext is used to get simContext from sync.Pool

func NewTxSimContext

func NewTxSimContext(vmManager protocol.VmManager, snapshot protocol.Snapshot, tx *common.Transaction,
	blockVersion uint32, logger protocol.Logger) protocol.TxSimContext

NewTxSimContext is used to create a new simContext for a transaction

func NewVmManager

func NewVmManager(
	instanceManagers map[commonPb.RuntimeType]protocol.VmInstancesManager,
	wxvmCodePathPrefix string,
	accessControl protocol.AccessControlProvider,
	chainNodesInfoProvider protocol.ChainNodesInfoProvider,
	chainConf protocol.ChainConf,
	log protocol.Logger,
	consensusStateWrapper protocol.ConsensusStateWrapper) protocol.VmManager

NewVmManager get vm runtime manager

func NewWacsi

func NewWacsi(logger protocol.Logger, verifySql protocol.SqlVerifier) protocol.Wacsi

NewWacsi get wacsi instance

func NewWacsiWithGas added in v3.0.1

func NewWacsiWithGas(logger protocol.Logger, verifySql protocol.SqlVerifier) protocol.WacsiWithGas

NewWacsiWithGas get Wacsi instance with gas calculation

func PrintTxReadSet

func PrintTxReadSet(txSimContext protocol.TxSimContext)

PrintTxReadSet only for debug

func PrintTxWriteSet

func PrintTxWriteSet(txSimContext protocol.TxSimContext)

PrintTxWriteSet only for debug

func PutTxSimContext

func PutTxSimContext(tsc protocol.TxSimContext)

PutTxSimContext is used to put simContext to sync.Pool

func RegisterVmProvider added in v3.0.1

func RegisterVmProvider(t string, f Provider)

RegisterVmProvider register vm provider

Types

type Bool

type Bool int32

Bool is the Type mapped from int to bool

type CallContractContext

type CallContractContext struct {
	// contains filtered or unexported fields
}

CallContractContext maintains a bitmap of call contract info, the bitmap can easily and quickly update and query call contract context such as type and depth. exg: value: 0011-00100010-0000000000000000000000000000000000000000 0110 0010 0110 meaning: 3times - use wasmer and dockergo - dockergo -> wasmer -> dockergo

func NewCallContractContext

func NewCallContractContext(ctxBitmap uint64) *CallContractContext

NewCallContractContext is used to create a new CallContractContext

func (*CallContractContext) AddLayer

func (c *CallContractContext) AddLayer(runtimeType common.RuntimeType)

AddLayer add new call contract layer to ctxBitmap

func (*CallContractContext) ClearLatestLayer

func (c *CallContractContext) ClearLatestLayer()

ClearLatestLayer clear the latest call contract layer from bitmap

func (*CallContractContext) GetAllTypes

func (c *CallContractContext) GetAllTypes() []common.RuntimeType

GetAllTypes return all types ordered by depth

func (*CallContractContext) GetCtxBitmap

func (c *CallContractContext) GetCtxBitmap() uint64

GetCtxBitmap returns ctx bitmap

func (*CallContractContext) GetDepth

func (c *CallContractContext) GetDepth() uint64

GetDepth returns current depth

func (*CallContractContext) GetTypeByDepth

func (c *CallContractContext) GetTypeByDepth(depth uint64) (common.RuntimeType, error)

GetTypeByDepth get runtime type by depth

func (*CallContractContext) HasUsed

func (c *CallContractContext) HasUsed(runtimeType common.RuntimeType) bool

HasUsed judge whether a vm has been used

type Provider added in v3.0.1

type Provider func(chainId string, config map[string]interface{}) (protocol.VmInstancesManager, error)

Provider provides a function to generate vm instance manager

func GetVmProvider added in v3.0.1

func GetVmProvider(t string) Provider

GetVmProvider get vm provider

type SimContextIterator

type SimContextIterator struct {
	// contains filtered or unexported fields
}

SimContextIterator iterator structure of simContext

func NewSimContextIterator

func NewSimContextIterator(simContext protocol.TxSimContext, wsetIter,
	dbIter protocol.StateIterator) *SimContextIterator

NewSimContextIterator is used to create a new iterator

func (*SimContextIterator) Next

func (sci *SimContextIterator) Next() bool

Next move the iter to next and return is there value in next iter

func (*SimContextIterator) Release

func (sci *SimContextIterator) Release()

Release release the iterator

func (*SimContextIterator) Value

func (sci *SimContextIterator) Value() (*store.KV, error)

Value return the value of current iter

type SimContextKeyHistoryIterator

type SimContextKeyHistoryIterator struct {
	// contains filtered or unexported fields
}

SimContextKeyHistoryIterator historyIterator structure of simContext

func NewSimContextKeyHistoryIterator

func NewSimContextKeyHistoryIterator(simContext protocol.TxSimContext, wSetIter,
	dbIter protocol.KeyHistoryIterator,
	key []byte) *SimContextKeyHistoryIterator

NewSimContextKeyHistoryIterator is used to create a new historyIterator

func (*SimContextKeyHistoryIterator) Next

func (iter *SimContextKeyHistoryIterator) Next() bool

Next move the iter to next and return is there value in next iter

func (*SimContextKeyHistoryIterator) Release

func (iter *SimContextKeyHistoryIterator) Release()

Release release the iterator

func (*SimContextKeyHistoryIterator) Value

Value return the value of current iter

type VmManagerImpl

type VmManagerImpl struct {
	InstanceManagers map[commonPb.RuntimeType]protocol.VmInstancesManager

	WxvmCodePath           string
	SnapshotManager        protocol.SnapshotManager
	AccessControl          protocol.AccessControlProvider
	ChainNodesInfoProvider protocol.ChainNodesInfoProvider
	ChainId                string
	Log                    protocol.Logger
	ChainConf              protocol.ChainConf // chain config
	ConsensusStateWrapper  protocol.ConsensusStateWrapper
	// contains filtered or unexported fields
}

VmManagerImpl implements the VmManager interface, manage vm runtime

func (*VmManagerImpl) AfterSchedule

func (m *VmManagerImpl) AfterSchedule(blockFingerprint string, blockHeight uint64)

AfterSchedule do sth. after schedule a block

func (*VmManagerImpl) BeforeSchedule

func (m *VmManagerImpl) BeforeSchedule(blockFingerprint string, blockHeight uint64)

BeforeSchedule do sth. before schedule a block

func (*VmManagerImpl) GetAccessControl

func (m *VmManagerImpl) GetAccessControl() protocol.AccessControlProvider

GetAccessControl get accessControl manages policies and principles

func (*VmManagerImpl) GetChainNodesInfoProvider

func (m *VmManagerImpl) GetChainNodesInfoProvider() protocol.ChainNodesInfoProvider

GetChainNodesInfoProvider get ChainNodesInfoProvider provide base node info list of chain.

func (*VmManagerImpl) GetConsensusStateWrapper

func (m *VmManagerImpl) GetConsensusStateWrapper() protocol.ConsensusStateWrapper

GetConsensusStateWrapper get consensus state wrapper which get consensus state info from

func (*VmManagerImpl) OnMessage added in v3.0.1

func (m *VmManagerImpl) OnMessage(msg *msgbus.Message)

OnMessage obtain chain configuration check all vm runtime readiness if not ready, init and start the instance manager, then add to vm manager InstanceManagers

func (*VmManagerImpl) OnQuit added in v3.0.1

func (m *VmManagerImpl) OnQuit()

OnQuit nothing to do

func (*VmManagerImpl) RunContract

func (m *VmManagerImpl) RunContract(contract *commonPb.Contract, method string, byteCode []byte,
	parameters map[string][]byte, txContext protocol.TxSimContext, gasUsed uint64, refTxType commonPb.TxType) (
	*commonPb.ContractResult, protocol.ExecOrderTxType, commonPb.TxStatusCode)

RunContract run native or user contract according ContractName in contractId, and call the specified function

func (*VmManagerImpl) Start

func (m *VmManagerImpl) Start() error

Start all vm instance

func (*VmManagerImpl) Stop

func (m *VmManagerImpl) Stop() error

Stop all vm instance

type WSetKeyHistoryIterator

type WSetKeyHistoryIterator struct {
	// contains filtered or unexported fields
}

WSetKeyHistoryIterator historyIterator structure of wasi

func NewWSetKeyHistoryIterator

func NewWSetKeyHistoryIterator(wSets map[string]interface{}) *WSetKeyHistoryIterator

NewWSetKeyHistoryIterator is used to create a new historyIterator for write set

func (*WSetKeyHistoryIterator) Next

func (iter *WSetKeyHistoryIterator) Next() bool

Next move the iter to next and return is there value in next iter

func (*WSetKeyHistoryIterator) Release

func (iter *WSetKeyHistoryIterator) Release()

Release release the iterator

func (*WSetKeyHistoryIterator) Value

Value get next element

type WacsiImpl

type WacsiImpl struct {
	// contains filtered or unexported fields
}

WacsiImpl implements the Wacsi interface(WebAssembly chainmaker system interface)

func (*WacsiImpl) BulletProofsOperation

func (*WacsiImpl) BulletProofsOperation(requestBody []byte, memory []byte, data []byte, isLen bool) ([]byte, error)

BulletProofsOperation is used to handle bulletproofs operations

func (*WacsiImpl) CallContract

func (w *WacsiImpl) CallContract(
	caller *common.Contract,
	requestBody []byte,
	txSimContext protocol.TxSimContext,
	memory []byte,
	data []byte,
	gasUsed uint64,
	isLen bool,
) (*common.ContractResult, uint64, protocol.ExecOrderTxType, error)

CallContract implement syscall for call contract, it is for gasm and wasmer

func (*WacsiImpl) DeleteState

func (w *WacsiImpl) DeleteState(requestBody []byte, contractName string, txSimContext protocol.TxSimContext) error

DeleteState is used to delete state from simContext cache

func (*WacsiImpl) EmitEvent

func (w *WacsiImpl) EmitEvent(requestBody []byte, txSimContext protocol.TxSimContext, contractId *common.Contract,
	log protocol.Logger) (*common.ContractEvent, error)

EmitEvent emit event to chain

func (*WacsiImpl) ErrorResult

func (w *WacsiImpl) ErrorResult(contractResult *common.ContractResult, data []byte) int32

ErrorResult is used to construct failed result

func (*WacsiImpl) ExecuteDDL

func (w *WacsiImpl) ExecuteDDL(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, method string) error

ExecuteDDL execute DDL statement

func (*WacsiImpl) ExecuteQuery

func (w *WacsiImpl) ExecuteQuery(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, chainId string) error

ExecuteQuery execute query operation

func (*WacsiImpl) ExecuteQueryOne

func (w *WacsiImpl) ExecuteQueryOne(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, data []byte, chainId string, isLen bool) ([]byte, error)

ExecuteQueryOne query a record

func (*WacsiImpl) ExecuteUpdate

func (w *WacsiImpl) ExecuteUpdate(requestBody []byte, contractName string, method string,
	txSimContext protocol.TxSimContext, memory []byte, chainId string) error

ExecuteUpdate execute udpate

func (*WacsiImpl) GetState

func (w *WacsiImpl) GetState(requestBody []byte, contractName string, txSimContext protocol.TxSimContext, memory []byte,
	data []byte, isLen bool) ([]byte, error)

GetState is used to get state from simContext cache

func (*WacsiImpl) KvIterator

func (w *WacsiImpl) KvIterator(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvIterator construct a kv iterator

func (*WacsiImpl) KvIteratorClose

func (w *WacsiImpl) KvIteratorClose(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvIteratorClose close iteraotr

func (*WacsiImpl) KvIteratorHasNext

func (w *WacsiImpl) KvIteratorHasNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

KvIteratorHasNext is used to determine whether there is another element

func (*WacsiImpl) KvIteratorNext

func (*WacsiImpl) KvIteratorNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte, data []byte,
	contractname string, isLen bool) ([]byte, error)

KvIteratorNext get next element

func (*WacsiImpl) KvPreIterator

func (w *WacsiImpl) KvPreIterator(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvPreIterator construct a kV iterator based on prefix matching

func (*WacsiImpl) PaillierOperation

func (*WacsiImpl) PaillierOperation(requestBody []byte, memory []byte, data []byte, isLen bool) ([]byte, error)

PaillierOperation is used to handle paillier operations

func (*WacsiImpl) PutState

func (w *WacsiImpl) PutState(requestBody []byte, contractName string, txSimContext protocol.TxSimContext) error

PutState is used to put state into simContext cache

func (*WacsiImpl) RSClose

func (w *WacsiImpl) RSClose(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

RSClose close sql iterator

func (*WacsiImpl) RSHasNext

func (w *WacsiImpl) RSHasNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

RSHasNext is used to judge whether there is a next record

func (*WacsiImpl) RSNext

func (w *WacsiImpl) RSNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte, data []byte,
	isLen bool) ([]byte, error)

RSNext get next record

func (*WacsiImpl) SuccessResult

func (w *WacsiImpl) SuccessResult(contractResult *common.ContractResult, data []byte) int32

SuccessResult is used to construct successful result

type WacsiWithGasImpl added in v3.0.1

type WacsiWithGasImpl struct {
	// contains filtered or unexported fields
}

WacsiWithGasImpl implements the Wacsi interface(WebAssembly chainmaker system interface)

func (*WacsiWithGasImpl) BulletProofsOperation added in v3.0.1

func (w *WacsiWithGasImpl) BulletProofsOperation(requestBody []byte,
	txSimContext protocol.TxSimContext, memory []byte, data []byte, isLen bool) ([]byte, error)

BulletProofsOperation is used to handle bulletproofs operations

func (*WacsiWithGasImpl) CallContract added in v3.0.1

func (w *WacsiWithGasImpl) CallContract(
	caller *common.Contract,
	requestBody []byte,
	txSimContext protocol.TxSimContext,
	memory []byte,
	data []byte,
	gasUsed uint64,
	isLen bool,
) (*common.ContractResult, uint64, protocol.ExecOrderTxType, error)

CallContract implement syscall for call contract, it is for gasm and wasmer

func (*WacsiWithGasImpl) DeleteState added in v3.0.1

func (w *WacsiWithGasImpl) DeleteState(
	requestBody []byte, contractName string, txSimContext protocol.TxSimContext) error

DeleteState is used to delete state from simContext cache

func (*WacsiWithGasImpl) EmitEvent added in v3.0.1

func (w *WacsiWithGasImpl) EmitEvent(
	requestBody []byte, txSimContext protocol.TxSimContext, contractId *common.Contract,
	log protocol.Logger) (*common.ContractEvent, error)

EmitEvent emit event to chain

func (*WacsiWithGasImpl) ErrorResult added in v3.0.1

func (w *WacsiWithGasImpl) ErrorResult(
	contractResult *common.ContractResult, txSimContext protocol.TxSimContext, data []byte) int32

ErrorResult is used to construct failed result

func (*WacsiWithGasImpl) ExecuteDDL added in v3.0.1

func (w *WacsiWithGasImpl) ExecuteDDL(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, method string) error

ExecuteDDL execute DDL statement

func (*WacsiWithGasImpl) ExecuteQuery added in v3.0.1

func (w *WacsiWithGasImpl) ExecuteQuery(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, chainId string) error

ExecuteQuery execute query operation

func (*WacsiWithGasImpl) ExecuteQueryOne added in v3.0.1

func (w *WacsiWithGasImpl) ExecuteQueryOne(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte, data []byte, chainId string, isLen bool) ([]byte, error)

ExecuteQueryOne query a record

func (*WacsiWithGasImpl) ExecuteUpdate added in v3.0.1

func (w *WacsiWithGasImpl) ExecuteUpdate(requestBody []byte, contractName string, method string,
	txSimContext protocol.TxSimContext, memory []byte, chainId string) error

ExecuteUpdate execute udpate

func (*WacsiWithGasImpl) GetState added in v3.0.1

func (w *WacsiWithGasImpl) GetState(
	requestBody []byte, contractName string, txSimContext protocol.TxSimContext, memory []byte,
	data []byte, isLen bool) ([]byte, error)

GetState is used to get state from simContext cache

func (*WacsiWithGasImpl) KvIterator added in v3.0.1

func (w *WacsiWithGasImpl) KvIterator(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvIterator construct a kv iterator

func (*WacsiWithGasImpl) KvIteratorClose added in v3.0.1

func (w *WacsiWithGasImpl) KvIteratorClose(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvIteratorClose close iteraotr

func (*WacsiWithGasImpl) KvIteratorHasNext added in v3.0.1

func (w *WacsiWithGasImpl) KvIteratorHasNext(
	requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

KvIteratorHasNext is used to determine whether there is another element

func (*WacsiWithGasImpl) KvIteratorNext added in v3.0.1

func (w *WacsiWithGasImpl) KvIteratorNext(
	requestBody []byte, txSimContext protocol.TxSimContext, memory []byte, data []byte,
	contractname string, isLen bool) ([]byte, error)

KvIteratorNext get next element

func (*WacsiWithGasImpl) KvPreIterator added in v3.0.1

func (w *WacsiWithGasImpl) KvPreIterator(requestBody []byte, contractName string, txSimContext protocol.TxSimContext,
	memory []byte) error

KvPreIterator construct a kV iterator based on prefix matching

func (*WacsiWithGasImpl) LogMessage added in v3.0.1

func (w *WacsiWithGasImpl) LogMessage(message []byte, txSimContext protocol.TxSimContext) int32

LogMessage is used to output debug info

func (*WacsiWithGasImpl) PaillierOperation added in v3.0.1

func (w *WacsiWithGasImpl) PaillierOperation(requestBody []byte,
	txSimContext protocol.TxSimContext, memory []byte, data []byte, isLen bool) ([]byte, error)

PaillierOperation is used to handle paillier operations

func (*WacsiWithGasImpl) PutState added in v3.0.1

func (w *WacsiWithGasImpl) PutState(
	requestBody []byte, contractName string, txSimContext protocol.TxSimContext) error

PutState is used to put state into simContext cache

func (*WacsiWithGasImpl) RSClose added in v3.0.1

func (w *WacsiWithGasImpl) RSClose(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

RSClose close sql iterator

func (*WacsiWithGasImpl) RSHasNext added in v3.0.1

func (w *WacsiWithGasImpl) RSHasNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte) error

RSHasNext is used to judge whether there is a next record

func (*WacsiWithGasImpl) RSNext added in v3.0.1

func (w *WacsiWithGasImpl) RSNext(requestBody []byte, txSimContext protocol.TxSimContext, memory []byte, data []byte,
	isLen bool) ([]byte, error)

RSNext get next record

func (*WacsiWithGasImpl) SuccessResult added in v3.0.1

func (w *WacsiWithGasImpl) SuccessResult(
	contractResult *common.ContractResult, txSimContext protocol.TxSimContext, data []byte) int32

SuccessResult is used to construct successful result

type WasmerInstancesManager

type WasmerInstancesManager interface {
	NewRuntimeInstance(txSimContext protocol.TxSimContext, chainId, method, codePath string, contract *common.Contract,
		byteCode []byte, log protocol.Logger) (protocol.RuntimeInstance, error)

	// addded for wasmer
	CloseRuntimeInstance(contractName string, contractVersion string) error

	// StartVM Start vm
	StartVM() error
	// StopVM Stop vm
	StopVM() error
}

WasmerInstancesManager interface add CloseRuntimeInstance based VmInstancesManager for `wasmer` module

type WsetIterator

type WsetIterator struct {
	// contains filtered or unexported fields
}

WsetIterator historyIterator structure of wasi

func NewWsetIterator

func NewWsetIterator(wsets map[string]interface{}) *WsetIterator

NewWsetIterator is used to create a new iterator for write set

func (*WsetIterator) Next

func (wi *WsetIterator) Next() bool

Next move the iter to next and return is there value in next iter

func (*WsetIterator) Release

func (wi *WsetIterator) Release()

Release release the iterator

func (*WsetIterator) Value

func (wi *WsetIterator) Value() (*store.KV, error)

Value get next element

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL