wazero_runtime

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: LGPL-3.0 Imports: 35 Imported by: 2

Documentation

Index

Constants

View Source
const Name = "wazero"

Name represents the name of the interpreter

Variables

View Source
var DefaultTestLogLvl = log.Info

DefaultTestLogLvl is the log level used for test runtime instances

View Source
var ErrExportFunctionNotFound = errors.New("export function not found")

Functions

func GetRuntimeVersion

func GetRuntimeVersion(code []byte) (version runtime.Version, err error)

GetRuntimeVersion finds the runtime version by initiating a temporary runtime instance using the WASM code provided, and querying it.

func NewKillStorageResult

func NewKillStorageResult(deleted uint32, allDeleted bool) scale.VaryingDataType

NewDigestItem returns a new VaryingDataType to represent a DigestItem

Types

type Config

type Config struct {
	Storage     runtime.Storage
	Keystore    *keystore.GlobalKeystore
	LogLvl      log.Level
	Role        common.NetworkRole
	NodeStorage runtime.NodeStorage
	Network     runtime.BasicNetwork
	Transaction runtime.TransactionState
	CodeHash    common.Hash
}

Config is the configuration used to create a Wasmer runtime instance.

type Instance

type Instance struct {
	Runtime wazero.Runtime
	Module  api.Module
	Context *runtime.Context

	sync.Mutex
	// contains filtered or unexported fields
}

Instance backed by wazero.Runtime

func NewInstance

func NewInstance(code []byte, cfg Config) (instance *Instance, err error)

NewInstance instantiates a runtime from raw wasm bytecode

func NewInstanceFromFile

func NewInstanceFromFile(fp string, cfg Config) (*Instance, error)

NewInstanceFromFile instantiates a runtime from a .wasm file

func NewInstanceFromTrie

func NewInstanceFromTrie(t *trie.Trie, cfg Config) (*Instance, error)

NewInstanceFromTrie returns a new runtime instance with the code provided in the given trie

func NewRuntimeFromGenesis

func NewRuntimeFromGenesis(cfg Config) (instance *Instance, err error)

NewRuntimeFromGenesis creates a runtime instance from the genesis data

func NewTestInstance

func NewTestInstance(t *testing.T, targetRuntime string) *Instance

NewTestInstance will create a new runtime instance using the given target runtime

func NewTestInstanceWithTrie

func NewTestInstanceWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie) *Instance

NewTestInstanceWithTrie returns an instance based on the target runtime string specified, which can be a file path or a constant from the constants defined in `lib/runtime/constants.go`. The instance uses the trie given as argument for its storage.

func (*Instance) ApplyExtrinsic

func (in *Instance) ApplyExtrinsic(data types.Extrinsic) ([]byte, error)

ApplyExtrinsic calls runtime API function BlockBuilder_apply_extrinsic

func (*Instance) BabeConfiguration

func (in *Instance) BabeConfiguration() (*types.BabeConfiguration, error)

BabeConfiguration gets the configuration data for BABE from the runtime

func (*Instance) BabeGenerateKeyOwnershipProof

func (in *Instance) BabeGenerateKeyOwnershipProof(slot uint64, authorityID [32]byte) (
	types.OpaqueKeyOwnershipProof, error)

BabeGenerateKeyOwnershipProof returns the babe key ownership proof from the runtime.

func (*Instance) BabeSubmitReportEquivocationUnsignedExtrinsic

func (in *Instance) BabeSubmitReportEquivocationUnsignedExtrinsic(
	equivocationProof types.BabeEquivocationProof, keyOwnershipProof types.OpaqueKeyOwnershipProof,
) error

BabeSubmitReportEquivocationUnsignedExtrinsic reports equivocation report to the runtime.

func (*Instance) CheckInherents

func (*Instance) CheckInherents()

CheckInherents checks inherents in the block verification process. TODO: use this in block verification process (#1873)

func (*Instance) DecodeSessionKeys

func (in *Instance) DecodeSessionKeys(enc []byte) ([]byte, error)

DecodeSessionKeys decodes the given public session keys. Returns a list of raw public keys including their key type.

func (*Instance) Exec

func (i *Instance) Exec(function string, data []byte) (result []byte, err error)

func (*Instance) ExecuteBlock

func (in *Instance) ExecuteBlock(block *types.Block) ([]byte, error)

ExecuteBlock calls runtime function Core_execute_block

func (*Instance) FinalizeBlock

func (in *Instance) FinalizeBlock() (*types.Header, error)

FinalizeBlock calls runtime API function BlockBuilder_finalize_block

func (*Instance) GenerateSessionKeys

func (*Instance) GenerateSessionKeys()

func (*Instance) GetCodeHash

func (in *Instance) GetCodeHash() common.Hash

GetCodeHash returns the code of the instance

func (*Instance) GrandpaAuthorities

func (in *Instance) GrandpaAuthorities() ([]types.Authority, error)

GrandpaAuthorities returns the genesis authorities from the runtime

func (*Instance) GrandpaGenerateKeyOwnershipProof

func (in *Instance) GrandpaGenerateKeyOwnershipProof(authSetID uint64, authorityID ed25519.PublicKeyBytes) (
	types.GrandpaOpaqueKeyOwnershipProof, error)

GrandpaGenerateKeyOwnershipProof returns grandpa key ownership proof from the runtime.

func (*Instance) GrandpaSubmitReportEquivocationUnsignedExtrinsic

func (in *Instance) GrandpaSubmitReportEquivocationUnsignedExtrinsic(
	equivocationProof types.GrandpaEquivocationProof, keyOwnershipProof types.GrandpaOpaqueKeyOwnershipProof,
) error

GrandpaSubmitReportEquivocationUnsignedExtrinsic reports an equivocation report to the runtime.

func (*Instance) InherentExtrinsics

func (in *Instance) InherentExtrinsics(data []byte) ([]byte, error)

InherentExtrinsics calls runtime API function BlockBuilder_inherent_extrinsics

func (*Instance) InitializeBlock

func (in *Instance) InitializeBlock(header *types.Header) error

InitializeBlock calls runtime API function Core_initialise_block

func (*Instance) Keystore

func (in *Instance) Keystore() *keystore.GlobalKeystore

Keystore to get reference to runtime keystore

func (*Instance) Metadata

func (in *Instance) Metadata() ([]byte, error)

Metadata calls runtime function Metadata_metadata

func (*Instance) NetworkService

func (in *Instance) NetworkService() runtime.BasicNetwork

NetworkService to get referernce to runtime network service

func (*Instance) NodeStorage

func (in *Instance) NodeStorage() runtime.NodeStorage

NodeStorage to get reference to runtime node service

func (*Instance) OffchainWorker

func (*Instance) OffchainWorker()

func (*Instance) PaymentQueryInfo

func (in *Instance) PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)

PaymentQueryInfo returns information of a given extrinsic

func (*Instance) QueryCallFeeDetails

func (in *Instance) QueryCallFeeDetails(ext []byte) (*types.FeeDetails, error)

QueryCallFeeDetails returns call fee details for given call

func (*Instance) QueryCallInfo

func (in *Instance) QueryCallInfo(ext []byte) (*types.RuntimeDispatchInfo, error)

QueryCallInfo returns information of a given extrinsic

func (*Instance) RandomSeed

func (*Instance) RandomSeed()

func (*Instance) SetContextStorage

func (in *Instance) SetContextStorage(s runtime.Storage)

SetContextStorage sets the runtime's storage.

func (*Instance) Stop

func (in *Instance) Stop()

Stop closes the WASM instance, its imports and clears the context allocator in a thread-safe way.

func (*Instance) ValidateTransaction

func (in *Instance) ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)

ValidateTransaction runs the extrinsic through the runtime function TaggedTransactionQueue_validate_transaction and returns *transaction.Validity. The error can be a VDT of either transaction.InvalidTransaction or transaction.UnknownTransaction, or can represent a normal error i.e. unmarshalling error

func (*Instance) Validator

func (in *Instance) Validator() bool

Validator returns the context's Validator

func (*Instance) Version

func (in *Instance) Version() (runtime.Version, error)

Version returns the instance version. This is cheap to call since the instance version is cached. Note the instance version is set at creation and on code update.

Jump to

Keyboard shortcuts

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