Documentation
¶
Index ¶
- Constants
- Variables
- func BABEAuthoritiesKey() []byte
- func BABERandomnessKey() []byte
- func Int64ToPointerAndSize(in int64) (ptr, length int32)
- func NewValidateTransactionError(res []byte) error
- func PointerAndSizeToInt64(ptr, size int32) int64
- func SystemAccountPrefix() []byte
- type APIItem
- type BasicNetwork
- type BasicStorage
- type Context
- type FreeingBumpHeapAllocator
- type Instance
- type InstanceConfig
- type LegacyVersionData
- func (lvd *LegacyVersionData) APIItems() []APIItem
- func (lvd *LegacyVersionData) AuthoringVersion() uint32
- func (lvd *LegacyVersionData) Decode(in []byte) error
- func (lvd *LegacyVersionData) Encode() ([]byte, error)
- func (lvd *LegacyVersionData) ImplName() []byte
- func (lvd *LegacyVersionData) ImplVersion() uint32
- func (lvd *LegacyVersionData) SpecName() []byte
- func (lvd *LegacyVersionData) SpecVersion() uint32
- func (lvd *LegacyVersionData) TransactionVersion() uint32
- type Memory
- type NodeStorage
- type NodeStorageType
- type Storage
- type TransactionState
- type Version
- type VersionData
- func (vd *VersionData) APIItems() []APIItem
- func (vd *VersionData) AuthoringVersion() uint32
- func (vd *VersionData) Decode(in []byte) error
- func (vd *VersionData) Encode() ([]byte, error)
- func (vd *VersionData) ImplName() []byte
- func (vd *VersionData) ImplVersion() uint32
- func (vd *VersionData) SpecName() []byte
- func (vd *VersionData) SpecVersion() uint32
- func (vd *VersionData) TransactionVersion() uint32
Constants ¶
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.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 */ )
const DefaultHeapBase = uint32(1469576)
DefaultHeapBase is the default heap base value (offset) used when the runtime does not provide one
const HeadsQty = 22
HeadsQty 22
const MaxPossibleAllocation = (1 << 24)
MaxPossibleAllocation 2^24 bytes
const PageSize = 65536
PageSize is 65kb
Variables ¶
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" // 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" )
var BABEPrefix, _ = common.Twox128Hash([]byte("Babe"))
BABEPrefix is the prefix for all BABE related storage values
var ErrCannotValidateTx = errors.New("could not validate transaction")
ErrCannotValidateTx is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails
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]
var ErrNilStorage = errors.New("runtime context storage is nil")
ErrNilStorage is returned when the runtime context storage isn't set
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]
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 ¶
func BABEAuthoritiesKey() []byte
BABEAuthoritiesKey is the location of the BABE authorities in the storage trie for NODE_RUNTIME
func BABERandomnessKey ¶
func BABERandomnessKey() []byte
BABERandomnessKey is the location of the BABE initial randomness in the storage trie for NODE_RUNTIME
func Int64ToPointerAndSize ¶
Int64ToPointerAndSize converts an int64 into a int32 pointer and a int32 length
func NewValidateTransactionError ¶
NewValidateTransactionError returns an error based on a return value from TaggedTransactionQueueValidateTransaction
func PointerAndSizeToInt64 ¶
PointerAndSizeToInt64 converts int32 pointer and size to a int64
func SystemAccountPrefix ¶
func SystemAccountPrefix() []byte
SystemAccountPrefix is the prefix for all System Account related storage values
Types ¶
type BasicNetwork ¶
type BasicNetwork interface {
NetworkState() common.NetworkState
}
BasicNetwork interface for functions used by runtime network state function
type BasicStorage ¶
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 Context ¶
type Context struct { Storage Storage Allocator *FreeingBumpHeapAllocator Keystore *keystore.GlobalKeystore Validator bool NodeStorage NodeStorage Network BasicNetwork Transaction TransactionState SigVerifier *crypto.SignatureVerifier OffchainHTTPSet *offchain.HTTPSet }
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 ¶
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 ¶
type Instance interface { UpdateRuntimeCode([]byte) error CheckRuntimeVersion([]byte) (Version, 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() (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) DecodeSessionKeys(enc []byte) ([]byte, error) PaymentQueryInfo(ext []byte) (*types.TransactionPaymentQueryInfo, 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 InstanceConfig ¶
type InstanceConfig struct { Storage Storage Keystore *keystore.GlobalKeystore LogLvl log.Level Role byte NodeStorage NodeStorage Network BasicNetwork Transaction TransactionState CodeHash common.Hash }
InstanceConfig represents a runtime instance configuration
type LegacyVersionData ¶
type LegacyVersionData struct {
// contains filtered or unexported fields
}
LegacyVersionData is the runtime version info returned by legacy runtimes
func NewLegacyVersionData ¶
func NewLegacyVersionData(specName, implName []byte, authoringVersion, specVersion, implVersion uint32, apiItems []APIItem) *LegacyVersionData
NewLegacyVersionData returns a new LegacyVersionData
func (*LegacyVersionData) APIItems ¶
func (lvd *LegacyVersionData) APIItems() []APIItem
APIItems returns the API items
func (*LegacyVersionData) AuthoringVersion ¶
func (lvd *LegacyVersionData) AuthoringVersion() uint32
AuthoringVersion returns the authoring version
func (*LegacyVersionData) Decode ¶
func (lvd *LegacyVersionData) Decode(in []byte) error
Decode to scale decode []byte to VersionAPI struct
func (*LegacyVersionData) Encode ¶
func (lvd *LegacyVersionData) Encode() ([]byte, error)
Encode returns the SCALE encoding of the Version
func (*LegacyVersionData) ImplName ¶
func (lvd *LegacyVersionData) ImplName() []byte
ImplName returns the implementation name
func (*LegacyVersionData) ImplVersion ¶
func (lvd *LegacyVersionData) ImplVersion() uint32
ImplVersion returns the implementation version
func (*LegacyVersionData) SpecName ¶
func (lvd *LegacyVersionData) SpecName() []byte
SpecName returns the spec name
func (*LegacyVersionData) SpecVersion ¶
func (lvd *LegacyVersionData) SpecVersion() uint32
SpecVersion returns the spec version
func (*LegacyVersionData) TransactionVersion ¶
func (lvd *LegacyVersionData) TransactionVersion() uint32
TransactionVersion returns the transaction version
type NodeStorage ¶
type NodeStorage struct { LocalStorage BasicStorage PersistentStorage BasicStorage BaseDB BasicStorage }
NodeStorage struct for storage of runtime offchain worker data
func (*NodeStorage) GetLocal ¶
func (n *NodeStorage) GetLocal(k []byte) ([]byte, error)
GetLocal retrieve a key and value from LOCAL node storage
func (*NodeStorage) GetPersistent ¶
func (n *NodeStorage) GetPersistent(k []byte) ([]byte, error)
GetPersistent retrieve a key and value from PERSISTENT node storage
func (*NodeStorage) SetLocal ¶
func (n *NodeStorage) SetLocal(k, v []byte) error
SetLocal persists a key and value into LOCAL node storage
func (*NodeStorage) SetPersistent ¶
func (n *NodeStorage) SetPersistent(k, v []byte) error
SetPersistent persists a key and value into PERSISTENT node storage
type NodeStorageType ¶
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) 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) error ClearPrefixLimit(prefix []byte, limit uint32) (uint32, bool) BeginStorageTransaction() CommitStorageTransaction() RollbackStorageTransaction() LoadCode() []byte }
Storage interface
type TransactionState ¶
type TransactionState interface {
AddToPool(vt *transaction.ValidTransaction) common.Hash
}
TransactionState interface for adding transactions to pool
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 ¶
type VersionData struct {
// contains filtered or unexported fields
}
VersionData is the runtime version info returned by v0.8 runtimes
func NewVersionData ¶
func NewVersionData(specName, implName []byte, authoringVersion, specVersion, implVersion uint32, apiItems []APIItem, transactionVersion uint32) *VersionData
NewVersionData returns a new VersionData
func (*VersionData) APIItems ¶
func (vd *VersionData) APIItems() []APIItem
APIItems returns the API items
func (*VersionData) AuthoringVersion ¶
func (vd *VersionData) AuthoringVersion() uint32
AuthoringVersion returns the authoring version
func (*VersionData) Decode ¶
func (vd *VersionData) Decode(in []byte) error
Decode to scale decode []byte to VersionAPI struct
func (*VersionData) Encode ¶
func (vd *VersionData) Encode() ([]byte, error)
Encode returns the SCALE encoding of the Version
func (*VersionData) ImplName ¶
func (vd *VersionData) ImplName() []byte
ImplName returns the implementation name
func (*VersionData) ImplVersion ¶
func (vd *VersionData) ImplVersion() uint32
ImplVersion returns the implementation version
func (*VersionData) SpecName ¶
func (vd *VersionData) SpecName() []byte
SpecName returns the spec name
func (*VersionData) SpecVersion ¶
func (vd *VersionData) SpecVersion() uint32
SpecVersion returns the spec version
func (*VersionData) TransactionVersion ¶
func (vd *VersionData) TransactionVersion() uint32
TransactionVersion returns the transaction version