vm

package module
v2.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 30 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

Overview

Package vm is package for vm

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 added in v2.3.2

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) 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 v2.3.3

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

NewWacsiWithGas get Wacsi instance with gas calculation

func ParseCallContractParams added in v2.3.6

func ParseCallContractParams(requestBody []byte) (int32, string, string,
	*serialize.EasyCodec, error)

ParseCallContractParams parse params for callContract func

func PrintTxReadSet

func PrintTxReadSet(txSimContext protocol.TxSimContext)

PrintTxReadSet only for debug

func PrintTxWriteSet

func PrintTxWriteSet(txSimContext protocol.TxSimContext)

PrintTxWriteSet only for debug

func PutTxSimContext added in v2.3.2

func PutTxSimContext(tsc protocol.TxSimContext)

PutTxSimContext is used to put simContext to sync.Pool

Types

type Bool

type Bool int32

Bool is the Type mapped from int to bool

type CallContractContext added in v2.3.0

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 added in v2.3.0

func NewCallContractContext(ctxBitmap uint64) *CallContractContext

NewCallContractContext is used to create a new CallContractContext

func (*CallContractContext) AddLayer added in v2.3.0

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

AddLayer add new call contract layer to ctxBitmap

func (*CallContractContext) ClearLatestLayer added in v2.3.0

func (c *CallContractContext) ClearLatestLayer()

ClearLatestLayer clear the latest call contract layer from bitmap

func (*CallContractContext) GetAllTypes added in v2.3.0

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

GetAllTypes return all types ordered by depth

func (*CallContractContext) GetCtxBitmap added in v2.3.0

func (c *CallContractContext) GetCtxBitmap() uint64

GetCtxBitmap returns ctx bitmap

func (*CallContractContext) GetDepth added in v2.3.0

func (c *CallContractContext) GetDepth() uint64

GetDepth returns current depth

func (*CallContractContext) GetTypeByDepth added in v2.3.0

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

GetTypeByDepth get runtime type by depth

func (*CallContractContext) HasUsed added in v2.3.0

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

HasUsed judge whether a vm has been used

type SimContextIterator added in v2.1.1

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

SimContextIterator iterator structure of simContext

func NewSimContextIterator added in v2.1.1

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

NewSimContextIterator is used to create a new iterator

func (*SimContextIterator) Next added in v2.1.1

func (sci *SimContextIterator) Next() bool

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

func (*SimContextIterator) Release added in v2.1.1

func (sci *SimContextIterator) Release()

Release release the iterator

func (*SimContextIterator) Value added in v2.1.1

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

Value return the value of current iter

type SimContextKeyHistoryIterator added in v2.1.1

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

SimContextKeyHistoryIterator historyIterator structure of simContext

func NewSimContextKeyHistoryIterator added in v2.1.1

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

NewSimContextKeyHistoryIterator is used to create a new historyIterator

func (*SimContextKeyHistoryIterator) Next added in v2.1.1

func (iter *SimContextKeyHistoryIterator) Next() bool

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

func (*SimContextKeyHistoryIterator) Release added in v2.1.1

func (iter *SimContextKeyHistoryIterator) Release()

Release release the iterator

func (*SimContextKeyHistoryIterator) Value added in v2.1.1

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
	// contains filtered or unexported fields
}

VmManagerImpl implements the VmManager interface, manage vm runtime

func (*VmManagerImpl) AfterSchedule added in v2.3.0

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

AfterSchedule do sth. after schedule a block

func (*VmManagerImpl) BeforeSchedule added in v2.3.0

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) 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 added in v2.1.1

func (m *VmManagerImpl) Start() error

Start all vm instance

func (*VmManagerImpl) Stop added in v2.1.1

func (m *VmManagerImpl) Stop() error

Stop all vm instance

type WSetKeyHistoryIterator added in v2.1.1

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

WSetKeyHistoryIterator historyIterator structure of wasi

func NewWSetKeyHistoryIterator added in v2.1.1

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

NewWSetKeyHistoryIterator is used to create a new historyIterator for write set

func (*WSetKeyHistoryIterator) Next added in v2.1.1

func (iter *WSetKeyHistoryIterator) Next() bool

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

func (*WSetKeyHistoryIterator) Release added in v2.1.1

func (iter *WSetKeyHistoryIterator) Release()

Release release the iterator

func (*WSetKeyHistoryIterator) Value added in v2.1.1

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 v2.3.3

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

WacsiWithGasImpl implements the Wacsi interface(WebAssembly chainmaker system interface)

func (*WacsiWithGasImpl) BulletProofsOperation added in v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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

KvIterator construct a kv iterator

func (*WacsiWithGasImpl) KvIteratorClose added in v2.3.3

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

KvIteratorClose close iteraotr

func (*WacsiWithGasImpl) KvIteratorHasNext added in v2.3.3

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 v2.3.3

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 v2.3.3

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 v2.3.3

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

LogMessage is used to output debug info

func (*WacsiWithGasImpl) PaillierOperation added in v2.3.3

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 v2.3.3

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 v2.3.3

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

RSClose close sql iterator

func (*WacsiWithGasImpl) RSHasNext added in v2.3.3

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 v2.3.3

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 v2.3.3

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

SuccessResult is used to construct successful result

type WasmerInstancesManager added in v2.3.0

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 added in v2.1.1

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

WsetIterator historyIterator structure of wasi

func NewWsetIterator added in v2.1.1

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

NewWsetIterator is used to create a new iterator for write set

func (*WsetIterator) Next added in v2.1.1

func (wi *WsetIterator) Next() bool

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

func (*WsetIterator) Release added in v2.1.1

func (wi *WsetIterator) Release()

Release release the iterator

func (*WsetIterator) Value added in v2.1.1

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