runtime

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-3.0 Imports: 30 Imported by: 3

Documentation

Index

Constants

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

	// 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.8 test API wasm
	HOST_API_TEST_RUNTIME     = "hostapi_runtime"
	HOST_API_TEST_RUNTIME_FP  = "hostapi_runtime.compact.wasm"
	HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true"
)

nolint

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 (
	// 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 GrandpaAuthoritiesKey, _ = common.HexToBytes("0x3a6772616e6470615f617574686f726974696573")

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

Functions

func BABEAuthoritiesKey added in v0.3.0

func BABEAuthoritiesKey() []byte

BABEAuthoritiesKey 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 GenerateRuntimeWasmFile added in v0.3.0

func GenerateRuntimeWasmFile() ([]string, error)

GenerateRuntimeWasmFile generates all runtime wasm files.

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

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

NewInMemoryDB creates a new in-memory database

func NewValidateTransactionError added in v0.2.0

func NewValidateTransactionError(res []byte) error

NewValidateTransactionError returns an error based on a return value from TaggedTransactionQueueValidateTransaction

func RemoveFiles added in v0.3.0

func RemoveFiles(files []string) error

RemoveFiles removes multiple files.

func SystemAccountPrefix added in v0.3.0

func SystemAccountPrefix() []byte

SystemAccountPrefix is the prefix for all System Account related storage values

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 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.GlobalKeystore
	Validator   bool
	NodeStorage NodeStorage
	Network     BasicNetwork
	Transaction TransactionState
	SigVerifier *SignatureVerifier
	// TransactionStorageChanges is used by ext_storage_start_transaction to keep track of
	// changes made after it's called. The next call to ext_storage_commit_transaction will
	// commit all the changes, or if ext_storage_rollback_transaction is called, the changes
	// will be discarded.
	TransactionStorageChanges []*TransactionStorageChange
}

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

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 Instance added in v0.2.0

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

	Version() (Version, 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)

	// 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 InstanceConfig added in v0.2.0

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

InstanceConfig represents a runtime instance configuration

type LegacyVersionData added in v0.3.0

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

LegacyVersionData is the runtime version info returned by legacy runtimes

func NewLegacyVersionData added in v0.3.0

func NewLegacyVersionData(specName, implName []byte, authoringVersion, specVersion, implVersion uint32, apiItems []*APIItem) *LegacyVersionData

NewLegacyVersionData returns a new LegacyVersionData

func (*LegacyVersionData) APIItems added in v0.3.0

func (v *LegacyVersionData) APIItems() []*APIItem

APIItems returns the API items

func (*LegacyVersionData) AuthoringVersion added in v0.3.0

func (v *LegacyVersionData) AuthoringVersion() uint32

AuthoringVersion returns the authoring version

func (*LegacyVersionData) Decode added in v0.3.0

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

Decode to scale decode []byte to VersionAPI struct

func (*LegacyVersionData) Encode added in v0.3.1

func (v *LegacyVersionData) Encode() ([]byte, error)

Encode returns the SCALE encoding of the Version

func (*LegacyVersionData) ImplName added in v0.3.0

func (v *LegacyVersionData) ImplName() []byte

ImplName returns the implementation name

func (*LegacyVersionData) ImplVersion added in v0.3.0

func (v *LegacyVersionData) ImplVersion() uint32

ImplVersion returns the implementation version

func (*LegacyVersionData) SpecName added in v0.3.0

func (v *LegacyVersionData) SpecName() []byte

SpecName returns the spec name

func (*LegacyVersionData) SpecVersion added in v0.3.0

func (v *LegacyVersionData) SpecVersion() uint32

SpecVersion returns the spec version

func (*LegacyVersionData) TransactionVersion added in v0.3.0

func (v *LegacyVersionData) TransactionVersion() uint32

TransactionVersion returns the transaction version

type Memory added in v0.2.0

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

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

type Signature struct {
	PubKey    []byte
	Sign      []byte
	Msg       []byte
	KeyTypeID crypto.KeyType
}

Signature ...

type SignatureVerifier added in v0.3.0

type SignatureVerifier struct {
	sync.RWMutex
	sync.Once
	sync.WaitGroup
	// contains filtered or unexported fields
}

SignatureVerifier ...

func NewSignatureVerifier added in v0.3.0

func NewSignatureVerifier() *SignatureVerifier

NewSignatureVerifier initializes SignatureVerifier which does background verification of signatures. Start() is called to start the verification process. Finish() is called to stop the verification process. Signatures can be added to the batch using Add().

func (*SignatureVerifier) Add added in v0.3.0

func (sv *SignatureVerifier) Add(s *Signature)

Add ...

func (*SignatureVerifier) Finish added in v0.3.0

func (sv *SignatureVerifier) Finish() bool

Finish waits till batch is finished. Returns true if all the signatures are valid, Otherwise returns false.

func (*SignatureVerifier) Invalid added in v0.3.0

func (sv *SignatureVerifier) Invalid()

Invalid ...

func (*SignatureVerifier) IsInvalid added in v0.3.0

func (sv *SignatureVerifier) IsInvalid() bool

IsInvalid ...

func (*SignatureVerifier) IsStarted added in v0.3.0

func (sv *SignatureVerifier) IsStarted() bool

IsStarted ...

func (*SignatureVerifier) Remove added in v0.3.0

func (sv *SignatureVerifier) Remove() *Signature

Remove returns the first signature from the batch. Returns nil if batch is empty.

func (*SignatureVerifier) Reset added in v0.3.0

func (sv *SignatureVerifier) Reset()

Reset reset the signature verifier for reuse.

func (*SignatureVerifier) Start added in v0.3.0

func (sv *SignatureVerifier) Start()

Start signature verification in batch.

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

Storage interface

type StorageChangeOperation added in v0.3.0

type StorageChangeOperation byte

StorageChangeOperation represents a storage change operation

const (
	SetOp         StorageChangeOperation = 0
	ClearOp       StorageChangeOperation = 1
	ClearPrefixOp StorageChangeOperation = 2
	AppendOp      StorageChangeOperation = 3
	DeleteChildOp StorageChangeOperation = 4
)

nolint

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 TransactionState added in v0.2.0

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

TransactionState interface for adding transactions to pool

type TransactionStorageChange added in v0.3.0

type TransactionStorageChange struct {
	Operation  StorageChangeOperation
	Prefix     []byte
	KeyToChild []byte // key to child trie, if applicable
	Key        []byte
	Value      []byte
}

TransactionStorageChange represents a storage change made after ext_storage_start_transaction is called

type Version

type Version interface {
	SpecName() []byte
	ImplName() []byte
	AuthoringVersion() uint32
	SpecVersion() uint32
	ImplVersion() uint32
	APIItems() []*APIItem
	TransactionVersion() uint32
	Encode() ([]byte, error)
}

Version represents the data returned by runtime call core_version

type VersionData added in v0.3.0

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

VersionData is the runtime version info returned by v0.8 runtimes

func NewVersionData added in v0.3.0

func NewVersionData(specName, implName []byte, authoringVersion, specVersion, implVersion uint32, apiItems []*APIItem, transactionVersion uint32) *VersionData

NewVersionData returns a new VersionData

func (*VersionData) APIItems added in v0.3.0

func (v *VersionData) APIItems() []*APIItem

APIItems returns the API items

func (*VersionData) AuthoringVersion added in v0.3.0

func (v *VersionData) AuthoringVersion() uint32

AuthoringVersion returns the authoring version

func (*VersionData) Decode added in v0.3.0

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

Decode to scale decode []byte to VersionAPI struct

func (*VersionData) Encode added in v0.3.1

func (v *VersionData) Encode() ([]byte, error)

Encode returns the SCALE encoding of the Version

func (*VersionData) ImplName added in v0.3.0

func (v *VersionData) ImplName() []byte

ImplName returns the implementation name

func (*VersionData) ImplVersion added in v0.3.0

func (v *VersionData) ImplVersion() uint32

ImplVersion returns the implementation version

func (*VersionData) SpecName added in v0.3.0

func (v *VersionData) SpecName() []byte

SpecName returns the spec name

func (*VersionData) SpecVersion added in v0.3.0

func (v *VersionData) SpecVersion() uint32

SpecVersion returns the spec version

func (*VersionData) TransactionVersion added in v0.3.0

func (v *VersionData) TransactionVersion() uint32

TransactionVersion returns the transaction version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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