runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: LGPL-3.0 Imports: 30 Imported by: 3

Documentation

Index

Constants

View Source
const (
	POLKADOT_RUNTIME_c768a7e4c70e     = "polkadot_runtime"
	POLKADOT_RUNTIME_FP_c768a7e4c70e  = "substrate_test_runtime.compact.wasm"
	POLKADOT_RUNTIME_URL_c768a7e4c70e = "" /* 167-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"

	SIMPLE_WASM_FP     = "simple.wasm"
	SIMPLE_RUNTIME_URL = "https://github.com//wasmerio/go-ext-wasm/blob/master/wasmer/test/testdata/examples/simple.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_metadata is the runtime API call Metadata_metadata
	Metadata_metadata = "Metadata_metadata"
	// TaggedTransactionQueueValidateTransaction is the runtime API call TaggedTransactionQueue_validate_transaction
	TaggedTransactionQueueValidateTransaction = "TaggedTransactionQueue_validate_transaction"
	// AuraAPIAuthorities is the runtime API call AuraApi_authorities
	AuraAPIAuthorities = "AuraApi_authorities" // TODO: deprecated with newest runtime, should be 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 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 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 TestAuthorityDataKey, _ = common.HexToBytes("0xe3b47b6c84c0493481f97c5197d2554f")

TestAuthorityDataKey is the location of authority data in the storage trie

Functions

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, func() (*wasm.Imports, error))

GetRuntimeVars returns the testRuntimeFilePath and testRuntimeURL

func RegisterImports

func RegisterImports() (*wasm.Imports, error)

RegisterImports registers the wasm imports for the old version of the substrate test runtime.

Types

type API_Item

type API_Item struct {
	Name []byte
	Ver  int32
}

API_Item struct to hold runtime API Name and Version

type Ctx

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

Ctx struct

type FreeingBumpHeapAllocator

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

FreeingBumpHeapAllocator struct

func NewAllocator

func NewAllocator(mem *wasm.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 wasm.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) Deallocate

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

Deallocate deallocates the memory located at pointer address

type Runtime

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

Runtime struct

func NewRuntime

func NewRuntime(code []byte, s Storage, ks *keystore.Keystore, registerImports func() (*wasm.Imports, error)) (*Runtime, error)

NewRuntime instantiates a runtime from raw wasm bytecode

func NewRuntimeFromFile

func NewRuntimeFromFile(fp string, s Storage, ks *keystore.Keystore, registerImports func() (*wasm.Imports, error)) (*Runtime, error)

NewRuntimeFromFile instantiates a runtime from a .wasm file

func NewTestRuntime

func NewTestRuntime(t *testing.T, targetRuntime string) *Runtime

NewTestRuntime will create a new runtime (polkadot/test)

func NewTestRuntimeWithTrie

func NewTestRuntimeWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie) *Runtime

NewTestRuntimeWithTrie will create a new runtime (polkadot/test) with the supplied trie as the storage

func (*Runtime) ApplyExtrinsic

func (r *Runtime) ApplyExtrinsic(data types.Extrinsic) ([]byte, error)

ApplyExtrinsic calls runtime API function BlockBuilder_apply_extrinsic

func (*Runtime) BabeConfiguration

func (r *Runtime) BabeConfiguration() (*types.BabeConfiguration, error)

BabeConfiguration gets the configuration data for BABE from the runtime

func (*Runtime) Exec

func (r *Runtime) Exec(function string, data []byte) ([]byte, error)

Exec func

func (*Runtime) FinalizeBlock

func (r *Runtime) FinalizeBlock() (*types.Header, error)

FinalizeBlock calls runtime API function BlockBuilder_finalize_block

func (*Runtime) GrandpaAuthorities

func (r *Runtime) GrandpaAuthorities() ([]*types.AuthorityData, error)

GrandpaAuthorities returns the genesis authorities from the runtime TODO: this seems to be out-of-date, the call is now named Grandpa_authorities and takes a block number.

func (*Runtime) InherentExtrinsics

func (r *Runtime) InherentExtrinsics(data []byte) ([]byte, error)

InherentExtrinsics calls runtime API function BlockBuilder_inherent_extrinsics

func (*Runtime) InitializeBlock

func (r *Runtime) InitializeBlock(header *types.Header) error

InitializeBlock calls runtime API function Core_initialize_block

func (*Runtime) Load

func (r *Runtime) Load(location, length int32) []byte

Load load

func (*Runtime) Stop

func (r *Runtime) Stop()

Stop func

func (*Runtime) Store

func (r *Runtime) Store(data []byte, location int32)

Store func

func (*Runtime) ValidateTransaction

func (r *Runtime) ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)

ValidateTransaction runs the extrinsic through runtime function TaggedTransactionQueue_validate_transaction and returns *Validity

type Storage

type Storage interface {
	SetStorage(key []byte, value []byte) error
	GetStorage(key []byte) ([]byte, error)
	StorageRoot() (common.Hash, error)
	SetStorageChild(keyToChild []byte, child *trie.Trie) error
	SetStorageIntoChild(keyToChild, key, value []byte) error
	GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
	ClearStorage(key []byte) error
	Entries() map[string][]byte
	SetBalance(key [32]byte, balance uint64) error
	GetBalance(key [32]byte) (uint64, error)
}

Storage interface

type TestRuntimeStorage

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

TestRuntimeStorage holds trie pointer

func NewTestRuntimeStorage

func NewTestRuntimeStorage(tr *trie.Trie) *TestRuntimeStorage

NewTestRuntimeStorage creates new instance of TestRuntimeStorage

func (TestRuntimeStorage) ClearStorage

func (trs TestRuntimeStorage) ClearStorage(key []byte) error

ClearStorage is a dummy test func

func (TestRuntimeStorage) Entries

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

Entries is a dummy test func

func (TestRuntimeStorage) GetBalance

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

GetBalance gets the balance for an account with the given public key

func (TestRuntimeStorage) GetStorage

func (trs TestRuntimeStorage) GetStorage(key []byte) ([]byte, error)

GetStorage is a dummy test func

func (TestRuntimeStorage) GetStorageFromChild

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

GetStorageFromChild is a dummy test func

func (TestRuntimeStorage) SetBalance

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

SetBalance sets the balance for an account with the given public key

func (TestRuntimeStorage) SetStorage

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

SetStorage is a dummy test func

func (TestRuntimeStorage) SetStorageChild

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

SetStorageChild is a dummy test func

func (TestRuntimeStorage) SetStorageIntoChild

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

SetStorageIntoChild is a dummy test func

func (TestRuntimeStorage) StorageRoot

func (trs TestRuntimeStorage) StorageRoot() (common.Hash, error)

StorageRoot is a dummy test func

func (TestRuntimeStorage) TrieAsString

func (trs TestRuntimeStorage) TrieAsString() string

TrieAsString is a dummy test func

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