Files
pezkuwi-subxt/substrate/primitives/runtime-interface
dependabot[bot] ddf5e5c04c Bump the known_good_semver group with 1 update (#1802)
Bumps the known_good_semver group with 1 update:
[syn](https://github.com/dtolnay/syn).

<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/dtolnay/syn/releases">syn's
releases</a>.</em></p>
<blockquote>
<h2>2.0.38</h2>
<ul>
<li>Fix <em>&quot;method 'peek' has an incompatible type for
trait&quot;</em> error when defining <code>bool</code> as a custom
keyword (<a
href="https://redirect.github.com/dtolnay/syn/issues/1518">#1518</a>,
thanks <a
href="https://github.com/Vanille-N"><code>@​Vanille-N</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/dtolnay/syn/commit/43632bfb6c78ee1f952645a268ab1ac4af162977"><code>43632bf</code></a>
Release 2.0.38</li>
<li><a
href="https://github.com/dtolnay/syn/commit/abd2c214b44da64a5e420d72919308300eebc23d"><code>abd2c21</code></a>
Merge pull request <a
href="https://redirect.github.com/dtolnay/syn/issues/1518">#1518</a>
from Vanille-N/master</li>
<li><a
href="https://github.com/dtolnay/syn/commit/6701e6077e15013ef34b15e3ffdae2657e499d83"><code>6701e60</code></a>
Absolute path to <code>bool</code> in
<code>custom_punctuation.rs</code></li>
<li><a
href="https://github.com/dtolnay/syn/commit/7313d242398111423f046386aa0a75548f63d236"><code>7313d24</code></a>
Resolve single_match_else pedantic clippy lint in code generator</li>
<li><a
href="https://github.com/dtolnay/syn/commit/67ab64f3c09e17b23493c7cda498e7edb8830f21"><code>67ab64f</code></a>
Include unexpected token in the test failure message</li>
<li><a
href="https://github.com/dtolnay/syn/commit/137ae33486de3f2652487f8f64436ad1429df496"><code>137ae33</code></a>
Check no remaining token after the first literal</li>
<li><a
href="https://github.com/dtolnay/syn/commit/258e9e8a11d188c1ee1ffb2b069819239999f9ac"><code>258e9e8</code></a>
Ignore single_match_else pedantic clippy lint in test</li>
<li><a
href="https://github.com/dtolnay/syn/commit/92fd50ee8cb52968d9c66fbe6d67638c1f838e26"><code>92fd50e</code></a>
Test docs.rs documentation build in CI</li>
<li>See full diff in <a
href="https://github.com/dtolnay/syn/compare/2.0.37...2.0.38">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=syn&package-manager=cargo&previous-version=2.0.37&new-version=2.0.38)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-06 18:07:01 +02:00
..
2023-08-29 13:39:41 +02:00
2023-08-29 13:39:41 +02:00
2023-08-29 13:39:41 +02:00
2023-09-04 12:02:32 +03:00

Substrate runtime interface

This crate provides types, traits and macros around runtime interfaces. A runtime interface is a fixed interface between a Substrate runtime and a Substrate node. For a native runtime the interface maps to a direct function call of the implementation. For a wasm runtime the interface maps to an external function call. These external functions are exported by the wasm executor and they map to the same implementation as the native calls.

Using a type in a runtime interface

Any type that should be used in a runtime interface as argument or return value needs to implement [RIType]. The associated type FFIType is the type that is used in the FFI function to represent the actual type. For example [T] is represented by an u64. The slice pointer and the length will be mapped to an u64 value. For more information see this table. The FFI function definition is used when calling from the wasm runtime into the node.

Traits are used to convert from a type to the corresponding RIType::FFIType. Depending on where and how a type should be used in a function signature, a combination of the following traits need to be implemented:

  1. Pass as function argument: [wasm::IntoFFIValue] and [host::FromFFIValue]
  2. As function return value: [wasm::FromFFIValue] and [host::IntoFFIValue]
  3. Pass as mutable function argument: [host::IntoPreallocatedFFIValue]

The traits are implemented for most of the common types like [T], Vec<T>, arrays and primitive types.

For custom types, we provide the PassBy trait and strategies that define how a type is passed between the wasm runtime and the node. Each strategy also provides a derive macro to simplify the implementation.

Performance

To not waste any more performance when calling into the node, not all types are SCALE encoded when being passed as arguments between the wasm runtime and the node. For most types that are raw bytes like Vec<u8>, [u8] or [u8; N] we pass them directly, without SCALE encoding them in front of. The implementation of [RIType] each type provides more information on how the data is passed.

Declaring a runtime interface

Declaring a runtime interface is similar to declaring a trait in Rust:

#[sp_runtime_interface::runtime_interface]
trait RuntimeInterface {
    fn some_function(value: &[u8]) -> bool {
        value.iter().all(|v| *v > 125)
    }
}

For more information on declaring a runtime interface, see #[runtime_interface].

FFI type and conversion

The following table documents how values of types are passed between the wasm and the host side and how they are converted into the corresponding type.

Type FFI type Conversion
u8 u8 Identity
u16 u16 Identity
u32 u32 Identity
u64 u64 Identity
i128 u32 v.as_ptr() (pointer to a 16 byte array)
i8 i8 Identity
i16 i16 Identity
i32 i32 Identity
i64 i64 Identity
u128 u32 v.as_ptr() (pointer to a 16 byte array)
bool u8 if v { 1 } else { 0 }
&str u64 v.len() 32bit << 32 | v.as_ptr() 32bit
&[u8] u64 v.len() 32bit << 32 | v.as_ptr() 32bit
Vec<u8> u64 v.len() 32bit << 32 | v.as_ptr() 32bit
Vec<T> where T: Encode u64 let e = v.encode();

e.len() 32bit << 32 | e.as_ptr() 32bit
&[T] where T: Encode u64 let e = v.encode();

e.len() 32bit << 32 | e.as_ptr() 32bit
[u8; N] u32 v.as_ptr()
*const T u32 Identity
Option<T> u64 let e = v.encode();

e.len() 32bit << 32 | e.as_ptr() 32bit
T where T: PassBy<PassBy=Inner> Depends on inner Depends on inner
T where T: PassBy<PassBy=Codec> u64 v.len() 32bit << 32 | v.as_ptr() 32bit

Identity means that the value is converted directly into the corresponding FFI type.

License: Apache-2.0