runtime

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 21 Imported by: 3

Documentation

Index

Constants

View Source
const (
	SUBSTRATE_TEST_RUNTIME     = "substrate_test_runtime"
	SUBSTRATE_TEST_RUNTIME_FP  = "substrate_test_runtime.compact.wasm"
	SUBSTRATE_TEST_RUNTIME_URL = "" /* 167-byte string literal not displayed */

	// v0.6 substrate runtime
	LEGACY_NODE_RUNTIME     = "legacy_node_runtime"
	LEGACY_NODE_RUNTIME_FP  = "legacy_node_runtime.compact.wasm"
	LEGACY_NODE_RUNTIME_URL = "" /* 143-byte string literal not displayed */

	// v0.8 substrate runtime
	NODE_RUNTIME     = "node_runtime"
	NODE_RUNTIME_FP  = "node_runtime.compact.wasm"
	NODE_RUNTIME_URL = "" /* 141-byte string literal not displayed */

	TEST_RUNTIME  = "test_runtime"
	TESTS_FP      = "test_wasm.wasm"
	TEST_WASM_URL = "https://github.com/ChainSafe/gossamer-test-wasm/blob/noot/target/wasm32-unknown-unknown/release/test_wasm.wasm?raw=true"
)

nolint

View Source
const HeadsQty = 22

HeadsQty 22

View Source
const MaxPossibleAllocation = 16777216 // 2^24 bytes

MaxPossibleAllocation 2^24 bytes

Variables

View Source
var (
	// 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"
)
View Source
var BABEPrefix, _ = common.Twox128Hash([]byte("Babe"))

BABEPrefix is the prefix for all BABE related storage values

View Source
var ErrCannotValidateTx = errors.New("could not validate transaction")

ErrCannotValidateTx is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails

View Source
var ErrInvalidTransaction = &json2.Error{Code: 1010, Message: "Invalid Transaction"}

ErrInvalidTransaction is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails with

value of [1, 0, x]
View Source
var ErrNilStorage = errors.New("runtime context storage is nil")

ErrNilStorage is returned when the runtime context storage isn't set

View Source
var ErrUnknownTransaction = &json2.Error{Code: 1011, Message: "Unknown Transaction Validity"}

ErrUnknownTransaction is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails with

value of [1, 1, x]
View Source
var GrandpaAuthorityDataKey, _ = common.HexToBytes("0x3a6772616e6470615f617574686f726974696573")

GrandpaAuthorityDataKey is the location of GRANDPA authority data in the storage trie for LEGACY_NODE_RUNTIME and NODE_RUNTIME

Functions

func BABEAuthorityDataKey added in v0.2.0

func BABEAuthorityDataKey() []byte

BABEAuthorityDataKey is the location of the BABE authorities in the storage trie for NODE_RUNTIME

func BABERandomnessKey added in v0.2.0

func BABERandomnessKey() []byte

BABERandomnessKey is the location of the BABE initial randomness in the storage trie for NODE_RUNTIME

func GetAbsolutePath

func GetAbsolutePath(targetDir string) string

GetAbsolutePath returns the completePath for a given targetDir

func GetRuntimeBlob

func GetRuntimeBlob(testRuntimeFilePath, testRuntimeURL string) (n int64, err error)

GetRuntimeBlob checks if the test wasm @testRuntimeFilePath exists and if not, it fetches it from @testRuntimeURL

func GetRuntimeVars

func GetRuntimeVars(targetRuntime string) (string, string)

GetRuntimeVars returns the testRuntimeFilePath and testRuntimeURL

func NewValidateTransactionError added in v0.2.0

func NewValidateTransactionError(res []byte) error

NewValidateTransactionError returns an error based on a return value from TaggedTransactionQueueValidateTransaction

Types

type API_Item

type API_Item struct {
	Name []byte
	Ver  int32
}

API_Item struct to hold runtime API Name and Version

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)
}

BasicStorage interface for functions used by runtime offchain workers

type Context added in v0.2.0

type Context struct {
	Storage     Storage
	Allocator   *FreeingBumpHeapAllocator
	Keystore    *keystore.GenericKeystore
	Validator   bool
	NodeStorage NodeStorage
	Network     BasicNetwork
	Transaction TransactionState
}

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

type FreeingBumpHeapAllocator

type FreeingBumpHeapAllocator struct {
	TotalSize uint32
	// 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 Instance added in v0.2.0

type Instance interface {
	InstanceAPI
	LegacyRuntimeAPI

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

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

type InstanceAPI added in v0.2.0

type InstanceAPI interface {
	Stop()
	NodeStorage() NodeStorage
	NetworkService() BasicNetwork

	Exec(function string, data []byte) ([]byte, error)
	SetContext(s Storage) // used to set the TrieState before a runtime call
}

InstanceAPI is the interface that any runtime instance must implement

type InstanceConfig added in v0.2.0

type InstanceConfig struct {
	Storage     Storage
	Keystore    *keystore.GenericKeystore
	LogLvl      log.Lvl
	Role        byte
	NodeStorage NodeStorage
	Network     BasicNetwork
	Transaction TransactionState
}

InstanceConfig represents a runtime instance configuration

type LegacyInstance added in v0.2.0

type LegacyInstance interface {
	InstanceAPI
	LegacyRuntimeAPI
}

LegacyInstance is the interface a legacy (v0.6) runtime instance must implement

type LegacyRuntimeAPI added in v0.2.0

type LegacyRuntimeAPI interface {
	Version() (*VersionAPI, error)
	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)
}

LegacyRuntimeAPI is the interface that a legacy runtime instance must implement

type Memory added in v0.2.0

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

Memory is a raw memory interface

type NodeStorage added in v0.2.0

type NodeStorage struct {
	LocalStorage      BasicStorage
	PersistentStorage BasicStorage
}

NodeStorage struct for storage of runtime offchain worker data

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 Storage

type Storage interface {
	Set(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	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) error
	Entries() map[string][]byte
	SetBalance(key [32]byte, balance uint64) error
	GetBalance(key [32]byte) (uint64, error)
	DeleteChildStorage(key []byte) error
	ClearChildStorage(keyToChild, key []byte) error
	NextKey([]byte) []byte
}

Storage interface

type TestRuntimeNetwork added in v0.2.0

type TestRuntimeNetwork struct {
}

TestRuntimeNetwork ...

func (*TestRuntimeNetwork) NetworkState added in v0.2.0

func (trn *TestRuntimeNetwork) NetworkState() common.NetworkState

NetworkState ...

type TestRuntimeStorage

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

TestRuntimeStorage implements the Storage interface

func NewTestRuntimeStorage

func NewTestRuntimeStorage(t *testing.T, tr *trie.Trie) *TestRuntimeStorage

NewTestRuntimeStorage returns an empty, initialized TestRuntimeStorage

func (*TestRuntimeStorage) ClearChildStorage added in v0.2.0

func (trs *TestRuntimeStorage) ClearChildStorage(keyToChild, key []byte) error

ClearChildStorage ...

func (*TestRuntimeStorage) Delete added in v0.2.0

func (trs *TestRuntimeStorage) Delete(key []byte) error

Delete ...

func (*TestRuntimeStorage) DeleteChildStorage added in v0.2.0

func (trs *TestRuntimeStorage) DeleteChildStorage(key []byte) error

DeleteChildStorage ...

func (*TestRuntimeStorage) Entries

func (trs *TestRuntimeStorage) Entries() map[string][]byte

Entries ...

func (*TestRuntimeStorage) Get added in v0.2.0

func (trs *TestRuntimeStorage) Get(key []byte) ([]byte, error)

Get ...

func (*TestRuntimeStorage) GetBalance

func (trs *TestRuntimeStorage) GetBalance(key [32]byte) (uint64, error)

GetBalance ...

func (*TestRuntimeStorage) GetChildStorage added in v0.2.0

func (trs *TestRuntimeStorage) GetChildStorage(keyToChild, key []byte) ([]byte, error)

GetChildStorage ...

func (*TestRuntimeStorage) NextKey added in v0.2.0

func (trs *TestRuntimeStorage) NextKey(in []byte) []byte

NextKey ...

func (*TestRuntimeStorage) Root added in v0.2.0

func (trs *TestRuntimeStorage) Root() (common.Hash, error)

Root ...

func (*TestRuntimeStorage) Set added in v0.2.0

func (trs *TestRuntimeStorage) Set(key []byte, value []byte) error

Set ...

func (*TestRuntimeStorage) SetBalance

func (trs *TestRuntimeStorage) SetBalance(key [32]byte, balance uint64) error

SetBalance ...

func (*TestRuntimeStorage) SetChild added in v0.2.0

func (trs *TestRuntimeStorage) SetChild(keyToChild []byte, child *trie.Trie) error

SetChild ...

func (*TestRuntimeStorage) SetChildStorage added in v0.2.0

func (trs *TestRuntimeStorage) SetChildStorage(keyToChild, key, value []byte) error

SetChildStorage ...

type TransactionState added in v0.2.0

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

TransactionState interface for adding transactions to pool

type Version

type Version struct {
	Spec_name         []byte
	Impl_name         []byte
	Authoring_version int32
	Spec_version      int32
	Impl_version      int32
}

Version struct

type VersionAPI

type VersionAPI struct {
	RuntimeVersion *Version
	API            []*API_Item
}

VersionAPI struct that holds Runtime Version info and API array

func (*VersionAPI) Decode

func (v *VersionAPI) Decode(in []byte) error

Decode to scale decode []byte to VersionAPI struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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