-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor the host <-> runtime interface machinery #7375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
s0me0ne-unkn0wn
merged 66 commits into
master
from
master_runtime_interface_refactoring
Apr 11, 2025
Merged
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
20fab05
Refactor the host <-> runtime interface machinery
koute e854ff3
Rename the prdoc file to the correct PR number
koute b1346cc
Remove redundant lifetimes
koute 5180738
Fix crate name in prdocs
koute 2745774
Remove more redundant lifetimes
koute d13c67f
Also adjust FRAME benchmarking runtime interface
koute e0fb03b
Update `polkadot-runtime-metrics` crate
koute 3b87116
Remove `sp-std` dependency from `sp-wasm-interface`
koute 1aab744
Add missing imports to `sp-runtime-interface`
koute 64c37e5
Make `sp_wasm_interface::Result` always return a `String` as an error
koute d71e093
Make `sp-runtime-interface` always `#[no_std]`
koute 4cd6caa
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
koute b8aebe1
Switch `runtime-interface` macros to use `substrate_runtime`
koute feeda1a
Fix `check-features-variants.sh` scripts
koute 11dfa9f
More `feature = "std"` cleanups; fix `full-crypto` feature compilation
koute 8a8dcb0
Update `secp256k1` and `secp256k1-sys` to fix WASM compilation
koute 1163801
Fix `sp-io` compilation under non-runtime `no_std`
koute af46473
Build frame examples with `--cfg substrate_runtime` on the CI
koute 0a254f5
Propagate `sp-core/std` -> `futures/std` cargo feature
koute 7ff56da
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
koute 2763e81
Fix `pallet_ui` tests
koute a3dee1f
Merge 'origin/master'; update `crypto_bytes.rs`
koute 022c32c
Disable default features for `sp-externalities` dep in `sp-core`
koute 9a446a8
More `feature = "std"` cleanups to fix `full_crypto` compilation
koute 29c8ddf
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
koute 1e53458
Remove unnecessary `RIType` and `IntoFFIValue` impls
koute c240e1e
Use associated types in return types
koute 6ac3d06
Make `Primitive` safe and private
koute ba683e7
Cleanups
koute 1cb22ca
Rename `PassByCodec` to `PassFatPointerAndDecode`
koute 6e606ad
Rename `PassSliceRefByCodec` -> `PassFatPointerAndDecodeSlice`
koute 6d90a1d
Update doc comment
koute 0001db0
Update the docs about the deprecated marshaling strategies
koute 182a6e8
Remove redundant links in the docs
koute 589690d
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
koute c794600
Update prdoc
koute a6af3b2
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
koute 60b24a4
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 452b09c
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn ec0c09e
Fix feature to imports mapping
s0me0ne-unkn0wn bda291b
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 50f63fc
Fix imports for CI
s0me0ne-unkn0wn f009d87
Fix dependencies
s0me0ne-unkn0wn 4514c2d
Remove stale file
s0me0ne-unkn0wn 60c9e54
Fix manifests
s0me0ne-unkn0wn 48a40c5
Restore prdoc
s0me0ne-unkn0wn eac1daf
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 5a1a94d
Fix manifests
s0me0ne-unkn0wn 51ded0d
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 3ada4d4
Merge branch 'master' into master_runtime_interface_refactoring
s0me0ne-unkn0wn 538bb36
Merge branch 'master' into master_runtime_interface_refactoring
s0me0ne-unkn0wn d246e38
Address some discussions
s0me0ne-unkn0wn 88901b6
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 7a6e86b
Apply suggestions from code review
s0me0ne-unkn0wn 22a3055
Apply suggestion from review
s0me0ne-unkn0wn d797355
Add `substrate_runtime` explaination to prdoc
s0me0ne-unkn0wn ba9bdf7
Merge branch 'master_runtime_interface_refactoring' of github.com:par…
s0me0ne-unkn0wn cd221e0
Address more discussions
s0me0ne-unkn0wn c3ce1d3
Fix bandersnatch key len
s0me0ne-unkn0wn 8c65121
Fix assersion
s0me0ne-unkn0wn 009f897
Fix UI tests, and a new one
s0me0ne-unkn0wn ac5a968
Merge branch 'master' into master_runtime_interface_refactoring
s0me0ne-unkn0wn 3153d8a
Fix UI test (different compiler version in CI)
s0me0ne-unkn0wn c8790a8
Merge branch 'master_runtime_interface_refactoring' of github.com:par…
s0me0ne-unkn0wn e087981
Merge remote-tracking branch 'origin/master' into master_runtime_inte…
s0me0ne-unkn0wn 41a504f
One more fix
s0me0ne-unkn0wn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # yaml-language-server: $schema=https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: Refactor the host <-> runtime interface machinery (the `#[runtime_interface]` macro) and the way host functions are defined | ||
|
|
||
| doc: | ||
| - audience: Node Dev | ||
| description: | | ||
| This PR refactors the way the host functions are defined. | ||
|
|
||
| Previously the way a given type was marshalled through the host <-> runtime boundary was | ||
| hardcoded for every type by the virtue of it implementing the relevant conversion traits. | ||
|
|
||
| This had two major consequences: | ||
| * It was not obvious how a given type is going to be passed just by looking at its type alone, | ||
| masking potentially expensive marshalling strategies. (For example, returning `Option<u32>` | ||
| was done through the SCALE codec and involved extra memory allocations!) | ||
| * It was not possible to use multiple marshalling strategies for a single type, making some | ||
| of the future improvements we'd like to do (e.g. move the runtime memory allocator into the runtime) | ||
| very hard to do. | ||
|
|
||
| So this PR disentangles this mess and makes the marshalling strategies explicit. This makes it | ||
| much more clear how a given type in a given host function is marshalled, and also makes it possible | ||
| to use different marshalling strategies for the same type in different host functions. | ||
|
|
||
| Before this PR you'd define a host function like this: | ||
|
|
||
| ```rust | ||
| #[runtime_interface] | ||
| trait MyInterface { | ||
| fn say_hello_world(name: &str) { | ||
| println!("Hello {name}!"); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| and after this PR you'll define it like this: | ||
|
|
||
| ```rust | ||
| #[runtime_interface] | ||
| trait MyInterface { | ||
| fn say_hello_world(name: PassFatPointerAndRead<&str>) { | ||
| println!("Hello {name}!", name); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| In this case the strategy for passing the `&str` is now explicitly specified (`PassFatPointerAndRead`). | ||
| Note that the *actual* API generated by this macro and the way arguments are accessed is completely unchanged! | ||
| The `#[runtime_interface]` machinery automatically "strips" away the marshalling strategy wrappers, | ||
| so neither the body of the `say_hello_world` function here nor its callers need to be changed. | ||
|
|
||
| Furthermore, to explicitly distinguish between the runtime compilation mode and native mode, | ||
| `#[cfg(substrate_runtime)]` is now used instead of `#[cfg(not(feature = "std"))]`. That allows for fine-tuning | ||
| the compilation behavior without relying solely on the `std` feature. | ||
|
|
||
| crates: | ||
| - name: sp-runtime-interface | ||
| bump: major | ||
| note: Rework of the `#[runtime_interface]` macro and associated types/trait. | ||
| - name: sp-runtime-interface-proc-macro | ||
| bump: major | ||
| note: Rework of the `#[runtime_interface]` macro. | ||
| - name: sp-wasm-interface | ||
| bump: major | ||
| note: The `Pointer` type now implements `Copy` and `Clone` unconditionally. The `Result` now always returns a `String`. | ||
| - name: sp-core | ||
| bump: major | ||
| note: Some types don't implement the traits related to the old `#[runtime_interface]` anymore. A few extra conversion impls. | ||
| - name: sp-io | ||
| bump: major | ||
| note: Requires the new `#[runtime_interface]` macro and associated machinery. Some types don't implement the traits related to the old `#[runtime_interface]` anymore. | ||
| - name: sp-statement-store | ||
| bump: major | ||
| note: Requires the new `#[runtime_interface]` macro and associated machinery. Some types don't implement the traits related to the old `#[runtime_interface]` anymore. | ||
| - name: sp-crypto-ec-utils | ||
| bump: minor | ||
| note: Requires the new `#[runtime_interface]` macro and associated machinery. | ||
| - name: frame-benchmarking | ||
| bump: major | ||
| note: Requires the new `#[runtime_interface]` macro and associated machinery. `Benchmarking::current_time` host call was changed. | ||
| - name: frame-support-procedural | ||
| bump: minor | ||
| note: Needs new `frame-benchmarking` due to the change to `current_time`. | ||
| - name: polkadot-runtime-metrics | ||
| bump: minor | ||
| note: Needs new `frame-benchmarking` due to the change to `current_time`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
substrate/primitives/application-crypto/check-features-variants.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.