runtime

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 29 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// v0.9 substrate runtime
	NODE_RUNTIME     = "node_runtime"
	NODE_RUNTIME_FP  = "node_runtime.compact.wasm"
	NODE_RUNTIME_URL = "https://github.com/noot/substrate/blob/noot/v0.9/target/debug/wbuild/node-runtime/node_runtime.compact.wasm?raw=true" //nolint:lll

	// v0.9.8 substrate runtime
	NODE_RUNTIME_v098     = "node_runtime-v0.9.8"
	NODE_RUNTIME_FP_v098  = "node_runtime-v0.9.8.compact.wasm"
	NODE_RUNTIME_URL_v098 = "https://github.com/noot/substrate/blob/noot/v0.9.8/target/debug/wbuild/node-runtime/node_runtime.compact.wasm?raw=true" //nolint:lll

	// v0.9.10 polkadot runtime
	POLKADOT_RUNTIME_v0910     = "polkadot_runtime-v9100"
	POLKADOT_RUNTIME_FP_v0910  = "polkadot_runtime-v9100.compact.wasm"
	POLKADOT_RUNTIME_URL_v0910 = "https://github.com/paritytech/polkadot/releases/download/v0.9.10/polkadot_runtime-v9100.compact.wasm?raw=true" //nolint:lll

	// v0.9.17 polkadot runtime
	POLKADOT_RUNTIME_v0917     = "polkadot_runtime-v917"
	POLKADOT_RUNTIME_FP_v0917  = "polkadot_runtime-v917.compact.wasm"
	POLKADOT_RUNTIME_URL_v0917 = "" //nolint:lll
	/* 162-byte string literal not displayed */

	// v0.9.25 polkadot runtime
	POLKADOT_RUNTIME_v0925     = "polkadot_runtime-v9250"
	POLKADOT_RUNTIME_FP_v0925  = "polkadot_runtime-v9250.compact.compressed.wasm"
	POLKADOT_RUNTIME_URL_v0925 = "https://github.com/paritytech/polkadot/releases/download/v0.9.25/polkadot_runtime-v9250.compact.compressed.wasm?raw=true" //nolint:lll

	// v0.8 polkadot runtime
	POLKADOT_RUNTIME     = "polkadot_runtime"
	POLKADOT_RUNTIME_FP  = "polkadot_runtime.compact.wasm"
	POLKADOT_RUNTIME_URL = "https://github.com/noot/polkadot/blob/noot/v0.8.25/polkadot_runtime.wasm?raw=true"

	// v0.9 test API wasm
	HOST_API_TEST_RUNTIME     = "hostapi_runtime"
	HOST_API_TEST_RUNTIME_FP  = "hostapi_runtime.compact.wasm"
	HOST_API_TEST_RUNTIME_URL = "" //nolint:lll
	/* 148-byte string literal not displayed */

	// v0.8 substrate runtime with modified name and babe C=(1, 1)
	DEV_RUNTIME     = "dev_runtime"
	DEV_RUNTIME_FP  = "dev_runtime.compact.wasm"
	DEV_RUNTIME_URL = "" //nolint:lll
	/* 153-byte string literal not displayed */

	// v0.9.29 polkadot
	POLKADOT_RUNTIME_v0929     = "polkadot_runtime-v929"
	POLKADOT_RUNTIME_V0929_FP  = "polkadot_runtime-v929.compact.wasm"
	POLKADOT_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." +
		"29/polkadot_runtime-v9290.compact.compressed.wasm?raw=true"

	// v0.9.29 westend
	WESTEND_RUNTIME_v0929     = "westend_runtime-v929"
	WESTEND_RUNTIME_V0929_FP  = "westend_runtime-v929.compact.wasm"
	WESTEND_RUNTIME_V0929_URL = "https://github.com/paritytech/polkadot/releases/download/v0.9." +
		"29/westend_runtime-v9290.compact.compressed.wasm?raw=true"
)
View Source
const (
	// CoreVersion is the runtime API call Core_version
	CoreVersion = "Core_version"
	// CoreInitializeBlock is the runtime API call Core_initialize_block
	CoreInitializeBlock = "Core_initialize_block"
	// CoreExecuteBlock is the runtime API call Core_execute_block
	CoreExecuteBlock = "Core_execute_block"
	// Metadata is the runtime API call Metadata_metadata
	Metadata = "Metadata_metadata"
	// TaggedTransactionQueueValidateTransaction is the runtime API call TaggedTransactionQueue_validate_transaction
	TaggedTransactionQueueValidateTransaction = "TaggedTransactionQueue_validate_transaction"
	// GrandpaAuthorities is the runtime API call GrandpaApi_grandpa_authorities
	GrandpaAuthorities = "GrandpaApi_grandpa_authorities"
	// BabeAPIConfiguration is the runtime API call BabeApi_configuration
	BabeAPIConfiguration = "BabeApi_configuration"
	// BlockBuilderInherentExtrinsics is the runtime API call BlockBuilder_inherent_extrinsics
	BlockBuilderInherentExtrinsics = "BlockBuilder_inherent_extrinsics"
	// BlockBuilderApplyExtrinsic is the runtime API call BlockBuilder_apply_extrinsic
	BlockBuilderApplyExtrinsic = "BlockBuilder_apply_extrinsic"
	// BlockBuilderFinalizeBlock is the runtime API call BlockBuilder_finalize_block
	BlockBuilderFinalizeBlock = "BlockBuilder_finalize_block"
	// DecodeSessionKeys is the runtime API call SessionKeys_decode_session_keys
	DecodeSessionKeys = "SessionKeys_decode_session_keys"
	// TransactionPaymentAPIQueryInfo returns information of a given extrinsic
	TransactionPaymentAPIQueryInfo = "TransactionPaymentApi_query_info"
	// TransactionPaymentCallAPIQueryCallInfo returns call query call info
	TransactionPaymentCallAPIQueryCallInfo = "TransactionPaymentCallApi_query_call_info"
	// TransactionPaymentCallAPIQueryCallFeeDetails returns call query call fee details
	TransactionPaymentCallAPIQueryCallFeeDetails = "TransactionPaymentCallApi_query_call_fee_details"
)
View Source
const DefaultHeapBase = uint32(1469576)

DefaultHeapBase is the default heap base value (offset) used when the runtime does not provide one

View Source
const HeadsQty = 22

HeadsQty 22

View Source
const MaxPossibleAllocation = (1 << 24)

MaxPossibleAllocation 2^24 bytes

View Source
const PageSize = 65536

PageSize is 65kb

Variables

View Source
var (
	ErrRuntimeUnknown  = errors.New("runtime is not known")
	ErrHTTPStatusNotOK = errors.New("HTTP status code received is not OK")
	ErrOpenRuntimeFile = errors.New("cannot open the runtime target file")
)
View Source
var (
	ErrDecodingVersionField = errors.New("decoding version field")
)

Functions

func GetAbsolutePath

func GetAbsolutePath(targetDir string) string

GetAbsolutePath returns the completePath for a given targetDir

func GetRuntime added in v0.7.0

func GetRuntime(ctx context.Context, runtime string) (
	runtimePath string, err error)

GetRuntime returns the runtime file path located in the /tmp/gossamer/runtimes directory (depending on OS and environment). If the file did not exist, the runtime WASM blob is downloaded to that file.

func InitializeRuntimeToTest added in v0.7.0

func InitializeRuntimeToTest(t *testing.T, instance Instance, parentHash common.Hash) *types.Block

InitializeRuntimeToTest sets a new block using the runtime functions to set initial data into the host

func NewInMemoryDB added in v0.3.0

func NewInMemoryDB(t *testing.T) chaindb.Database

NewInMemoryDB creates a new in-memory database

func NewTestExtrinsic added in v0.7.0

func NewTestExtrinsic(t *testing.T, rt Instance, genHash, blockHash common.Hash,
	nonce uint64, call string, args ...interface{}) string

NewTestExtrinsic builds a new extrinsic using centrifuge pkg

func UnmarshalTransactionValidity added in v0.7.0

func UnmarshalTransactionValidity(res []byte) (*transaction.Validity, error)

UnmarshalTransactionValidity takes the result of the validateTransaction runtime call and unmarshalls it TODO use custom result issue #2780

Types

type APIItem added in v0.3.0

type APIItem struct {
	Name [8]byte
	Ver  uint32
}

APIItem struct to hold runtime API Name and Version

type AncientBirthBlock added in v0.7.0

type AncientBirthBlock struct{}

AncientBirthBlock The transaction birth block is ancient

func (AncientBirthBlock) Error added in v0.7.0

func (AncientBirthBlock) Error() string

Error returns the error message associated with the AncientBirthBlock

func (AncientBirthBlock) Index added in v0.7.0

func (AncientBirthBlock) Index() uint

Index returns the VDT index

type BadMandatory added in v0.7.0

type BadMandatory struct{}

BadMandatory An extrinsic with a Mandatory dispatch resulted in Error

func (BadMandatory) Error added in v0.7.0

func (BadMandatory) Error() string

Error returns the error message associated with the BadMandatory

func (BadMandatory) Index added in v0.7.0

func (BadMandatory) Index() uint

Index returns the VDT index

type BadProof added in v0.7.0

type BadProof struct{}

BadProof General error to do with the transaction’s proofs (e.g. signature)

func (BadProof) Error added in v0.7.0

func (BadProof) Error() string

Error returns the error message associated with the BadProof

func (BadProof) Index added in v0.7.0

func (BadProof) Index() uint

Index returns the VDT index

type BasicNetwork added in v0.2.0

type BasicNetwork interface {
	NetworkState() common.NetworkState
}

BasicNetwork interface for functions used by runtime network state function

type BasicStorage added in v0.2.0

type BasicStorage interface {
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Del(key []byte) error
}

BasicStorage interface for functions used by runtime offchain workers

type Call added in v0.7.0

type Call struct{}

Call The call of the transaction is not expected

func (Call) Error added in v0.7.0

func (Call) Error() string

Error returns the error message associated with the Call

func (Call) Index added in v0.7.0

func (Call) Index() uint

Index returns the VDT index

type Context added in v0.2.0

type Context struct {
	Storage         Storage
	Allocator       *FreeingBumpHeapAllocator
	Keystore        *keystore.GlobalKeystore
	Validator       bool
	NodeStorage     NodeStorage
	Network         BasicNetwork
	Transaction     TransactionState
	SigVerifier     *crypto.SignatureVerifier
	OffchainHTTPSet *offchain.HTTPSet
	Version         Version
}

Context is the context for the wasm interpreter's imported functions

type ExhaustsResources added in v0.7.0

type ExhaustsResources struct{}

ExhaustsResources The transaction would exhaust the resources of current block

func (ExhaustsResources) Error added in v0.7.0

func (ExhaustsResources) Error() string

Error returns the error message associated with the ExhaustsResources

func (ExhaustsResources) Index added in v0.7.0

func (ExhaustsResources) Index() uint

Index returns the VDT index

type FreeingBumpHeapAllocator

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

FreeingBumpHeapAllocator struct

func NewAllocator

func NewAllocator(mem Memory, ptrOffset uint32) *FreeingBumpHeapAllocator

NewAllocator Creates a new allocation heap which follows a freeing-bump strategy. The maximum size which can be allocated at once is 16 MiB.

Arguments

  • `mem` - A runtime.Memory to the available memory which is used as the heap.
  • `ptrOffset` - The pointers returned by `Allocate()` start from this offset on. The pointer offset needs to be aligned to a multiple of 8, hence a padding might be added to align `ptrOffset` properly.

* returns a pointer to an initilized FreeingBumpHeapAllocator

func (*FreeingBumpHeapAllocator) Allocate

func (fbha *FreeingBumpHeapAllocator) Allocate(size uint32) (uint32, error)

Allocate determines if there is space available in WASM heap to grow the heap by 'size'. If there is space

available it grows the heap to fit give 'size'.  The heap grows is chunks of Powers of 2, so the growth becomes
the next highest power of 2 of the requested size.

func (*FreeingBumpHeapAllocator) Clear added in v0.2.0

func (fbha *FreeingBumpHeapAllocator) Clear()

Clear resets the allocator, effectively freeing all allocated memory

func (*FreeingBumpHeapAllocator) Deallocate

func (fbha *FreeingBumpHeapAllocator) Deallocate(pointer uint32) error

Deallocate deallocates the memory located at pointer address

type Future added in v0.7.0

type Future struct{}

Future General error to do with the transaction not yet being valid (e.g. nonce too high)

func (Future) Error added in v0.7.0

func (Future) Error() string

Error returns the error message associated with the Future

func (Future) Index added in v0.7.0

func (Future) Index() uint

Index returns the VDT index

type Instance added in v0.2.0

type Instance interface {
	UpdateRuntimeCode([]byte) error
	Stop()
	NodeStorage() NodeStorage
	NetworkService() BasicNetwork
	Keystore() *keystore.GlobalKeystore
	Validator() bool
	Exec(function string, data []byte) ([]byte, error)
	SetContextStorage(s Storage) // used to set the TrieState before a runtime call

	GetCodeHash() common.Hash
	// Version returns the version from the runtime.
	// This should return the cached version and be cheap to execute.
	Version() (version Version)
	Metadata() ([]byte, error)
	BabeConfiguration() (*types.BabeConfiguration, error)
	GrandpaAuthorities() ([]types.Authority, error)
	ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)
	InitializeBlock(header *types.Header) error
	InherentExtrinsics(data []byte) ([]byte, error)
	ApplyExtrinsic(data types.Extrinsic) ([]byte, error)
	FinalizeBlock() (*types.Header, error)
	ExecuteBlock(block *types.Block) ([]byte, error)
	DecodeSessionKeys(enc []byte) ([]byte, error)
	PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)

	CheckInherents() // TODO: use this in block verification process (#1873)

	// parameters and return values for these are undefined in the spec
	RandomSeed()
	OffchainWorker()
	GenerateSessionKeys()
}

Instance is the interface a v0.8 runtime instance must implement

type InvalidCustom added in v0.7.0

type InvalidCustom uint8

InvalidCustom Any other custom invalid validity that is not covered

func (InvalidCustom) Error added in v0.7.0

func (i InvalidCustom) Error() string

Error returns the error message associated with the InvalidCustom

func (InvalidCustom) Index added in v0.7.0

func (InvalidCustom) Index() uint

Index returns the VDT index

type InvalidTransaction added in v0.7.0

type InvalidTransaction scale.VaryingDataType

InvalidTransaction is a child VDT of TransactionValidityError

func NewInvalidTransaction added in v0.7.0

func NewInvalidTransaction() InvalidTransaction

NewInvalidTransaction is constructor for InvalidTransaction

func (InvalidTransaction) Error added in v0.7.0

func (i InvalidTransaction) Error() string

Error returns the error message associated with the InvalidTransaction

func (InvalidTransaction) Index added in v0.7.0

func (InvalidTransaction) Index() uint

Index returns the VDT index

func (*InvalidTransaction) Set added in v0.7.0

Set will set a VaryingDataTypeValue using the underlying VaryingDataType

func (*InvalidTransaction) Value added in v0.7.0

func (i *InvalidTransaction) Value() (val scale.VaryingDataTypeValue, err error)

Value will return the value from the underying VaryingDataType

type MandatoryDispatch added in v0.7.0

type MandatoryDispatch struct{}

MandatoryDispatch A transaction with a mandatory dispatch

func (MandatoryDispatch) Error added in v0.7.0

func (MandatoryDispatch) Error() string

Error returns the error message associated with the MandatoryDispatch

func (MandatoryDispatch) Index added in v0.7.0

func (MandatoryDispatch) Index() uint

Index returns the VDT index

type Memory added in v0.2.0

type Memory interface {
	Data() []byte
	Length() uint32
	Grow(uint32) error
}

Memory is a raw memory interface

type NoUnsignedValidator added in v0.7.0

type NoUnsignedValidator struct{}

NoUnsignedValidator No validator found for the given unsigned transaction

func (NoUnsignedValidator) Error added in v0.7.0

func (NoUnsignedValidator) Error() string

Error returns the error message associated with the NoUnsignedValidator

func (NoUnsignedValidator) Index added in v0.7.0

func (NoUnsignedValidator) Index() uint

Index returns the VDT index

type NodeStorage added in v0.2.0

type NodeStorage struct {
	LocalStorage      BasicStorage
	PersistentStorage BasicStorage
	BaseDB            BasicStorage
}

NodeStorage struct for storage of runtime offchain worker data

func (*NodeStorage) GetLocal added in v0.7.0

func (n *NodeStorage) GetLocal(k []byte) ([]byte, error)

GetLocal retrieve a key and value from LOCAL node storage

func (*NodeStorage) GetPersistent added in v0.7.0

func (n *NodeStorage) GetPersistent(k []byte) ([]byte, error)

GetPersistent retrieve a key and value from PERSISTENT node storage

func (*NodeStorage) SetLocal added in v0.7.0

func (n *NodeStorage) SetLocal(k, v []byte) error

SetLocal persists a key and value into LOCAL node storage

func (*NodeStorage) SetPersistent added in v0.7.0

func (n *NodeStorage) SetPersistent(k, v []byte) error

SetPersistent persists a key and value into PERSISTENT node storage

type NodeStorageType added in v0.2.0

type NodeStorageType byte

NodeStorageType type to identify offchain storage type

const NodeStorageTypeLocal NodeStorageType = 2

NodeStorageTypeLocal flog to identify offchain storage as local (memory)

const NodeStorageTypePersistent NodeStorageType = 1

NodeStorageTypePersistent flag to identify offchain storage as persistent (db)

type Payment added in v0.7.0

type Payment struct{}

Payment General error to do with the inability to pay some fees (e.g. account balance too low)

func (Payment) Error added in v0.7.0

func (Payment) Error() string

Error returns the error message associated with the Payment

func (Payment) Index added in v0.7.0

func (Payment) Index() uint

Index returns the VDT index

type Stale added in v0.7.0

type Stale struct{}

Stale General error to do with the transaction being outdated (e.g. nonce too low)

func (Stale) Error added in v0.7.0

func (Stale) Error() string

Error returns the error message associated with the Stale

func (Stale) Index added in v0.7.0

func (Stale) Index() uint

Index returns the VDT index

type Storage

type Storage interface {
	Set(key []byte, value []byte)
	Get(key []byte) []byte
	Root() (common.Hash, error)
	SetChild(keyToChild []byte, child *trie.Trie) error
	SetChildStorage(keyToChild, key, value []byte) error
	GetChildStorage(keyToChild, key []byte) ([]byte, error)
	Delete(key []byte)
	DeleteChild(keyToChild []byte)
	DeleteChildLimit(keyToChild []byte, limit *[]byte) (uint32, bool, error)
	ClearChildStorage(keyToChild, key []byte) error
	NextKey([]byte) []byte
	ClearPrefixInChild(keyToChild, prefix []byte) error
	GetChildNextKey(keyToChild, key []byte) ([]byte, error)
	GetChild(keyToChild []byte) (*trie.Trie, error)
	ClearPrefix(prefix []byte)
	ClearPrefixLimit(prefix []byte, limit uint32) (uint32, bool)
	BeginStorageTransaction()
	CommitStorageTransaction()
	RollbackStorageTransaction()
	LoadCode() []byte
}

Storage interface

type TestRuntimeNetwork added in v0.2.0

type TestRuntimeNetwork struct{}

TestRuntimeNetwork ...

func (*TestRuntimeNetwork) NetworkState added in v0.2.0

func (*TestRuntimeNetwork) NetworkState() common.NetworkState

NetworkState ...

type TransactionState added in v0.2.0

type TransactionState interface {
	AddToPool(vt *transaction.ValidTransaction) common.Hash
}

TransactionState interface for adding transactions to pool

type TransactionValidityError added in v0.7.0

type TransactionValidityError scale.VaryingDataType

TransactionValidityError Information on a transaction's validity and, if valid, on how it relates to other transactions. It is a result of the form: Result<transaction.Validity, TransactionValidityError>

func NewTransactionValidityError added in v0.7.0

func NewTransactionValidityError() *TransactionValidityError

NewTransactionValidityError is constructor for TransactionValidityError

func (TransactionValidityError) Error added in v0.7.0

func (tve TransactionValidityError) Error() string

Error will return the error underlying TransactionValidityError

func (*TransactionValidityError) Set added in v0.7.0

Set will set a VaryingDataTypeValue using the underlying VaryingDataType

func (*TransactionValidityError) Value added in v0.7.0

func (tve *TransactionValidityError) Value() (val scale.VaryingDataTypeValue, err error)

Value will return the value from the underlying VaryingDataType

type UnknownCustom added in v0.7.0

type UnknownCustom uint8

UnknownCustom Any other custom unknown validity that is not covered

func (UnknownCustom) Error added in v0.7.0

func (m UnknownCustom) Error() string

Error returns the error message associated with the UnknownCustom

func (UnknownCustom) Index added in v0.7.0

func (UnknownCustom) Index() uint

Index returns the VDT index

type UnknownTransaction added in v0.7.0

type UnknownTransaction scale.VaryingDataType

UnknownTransaction is the child VDT of TransactionValidityError

func NewUnknownTransaction added in v0.7.0

func NewUnknownTransaction() UnknownTransaction

NewUnknownTransaction is constructor for Unknown

func (UnknownTransaction) Error added in v0.7.0

func (u UnknownTransaction) Error() string

func (UnknownTransaction) Index added in v0.7.0

func (UnknownTransaction) Index() uint

Index returns the VDT index

func (*UnknownTransaction) Set added in v0.7.0

Set will set a VaryingDataTypeValue using the underlying VaryingDataType

func (*UnknownTransaction) Value added in v0.7.0

func (u *UnknownTransaction) Value() (val scale.VaryingDataTypeValue, err error)

Value will return value from the underying VaryingDataType

type ValidityCannotLookup added in v0.7.0

type ValidityCannotLookup struct{}

ValidityCannotLookup Could not look up some information that is required to validate the transaction

func (ValidityCannotLookup) Error added in v0.7.0

func (ValidityCannotLookup) Error() string

Error returns the error message associated with the ValidityCannotLookup

func (ValidityCannotLookup) Index added in v0.7.0

func (ValidityCannotLookup) Index() uint

Index returns the VDT index

type Version

type Version struct {
	SpecName           []byte
	ImplName           []byte
	AuthoringVersion   uint32
	SpecVersion        uint32
	ImplVersion        uint32
	APIItems           []APIItem
	TransactionVersion uint32
	StateVersion       uint32
}

Version is the runtime version info.

func DecodeVersion added in v0.7.0

func DecodeVersion(encoded []byte) (version Version, err error)

DecodeVersion scale decodes the encoded version data. For older version data with missing fields (such as `transaction_version`) the missing field is set to its zero value (such as `0`).

func (Version) TaggedTransactionQueueVersion added in v0.7.0

func (v Version) TaggedTransactionQueueVersion() (txQueueVersion uint32, err error)

TaggedTransactionQueueVersion returns the TaggedTransactionQueue API version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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