forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to issue paritytech#11577 Add support for multiple versions of a Runtime API. The purpose is to have one main version of the API, which is considered stable and multiple unstable (aka staging) ones. How it works =========== Some methods of the API trait can be tagged with `#[api_version(N)]` attribute where N is version number bigger than the main one. Let's call them **staging methods** for brevity. The implementor of the API decides which version to implement. Example (from paritytech#11577 (comment)): ``` decl_runtime_apis! { #{api_version(10)] trait Test { fn something() -> Vec<u8>; #[api_version(11)] fn new_cool_function() -> u32; } } ``` ``` impl_runtime_apis! { #[api_version(11)] impl Test for Runtime { fn something() -> Vec<u8> { vec![1, 2, 3] } fn new_cool_function() -> u32 { 10 } } } ``` Version safety checks (currently not implemented) ================================================= By default in the API trait all staging methods has got default implementation calling `unimplemented!()`. This is a problem because if the developer wants to implement version 11 in the example above and forgets to add `fn new_cool_function()` in `impl_runtime_apis!` the runtime will crash when the function is executed. Ideally a compilation error should be generated in such cases. TODOs ===== Things not working well at the moment: [ ] Version safety check [ ] Integration tests of `primitives/api` are messed up a bit. More specifically `primitives/api/test/tests/decl_and_impl.rs` [ ] Integration test covering the new functionality. [ ] Some duplicated code
- Loading branch information
Showing
16 changed files
with
585 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
/// The ident used for the block generic parameter. | ||
pub const BLOCK_GENERIC_IDENT: &str = "Block"; | ||
|
||
/// Unique identifier used to make the hidden includes unique for this macro. | ||
pub const HIDDEN_INCLUDES_ID: &str = "DECL_RUNTIME_APIS"; | ||
|
||
/// The `core_trait` attribute. | ||
pub const CORE_TRAIT_ATTRIBUTE: &str = "core_trait"; | ||
/// The `api_version` attribute. | ||
/// | ||
/// Is used to set the current version of the trait. | ||
pub const API_VERSION_ATTRIBUTE: &str = "api_version"; | ||
/// The `changed_in` attribute. | ||
/// | ||
/// Is used when the function signature changed between different versions of a trait. | ||
/// This attribute should be placed on the old signature of the function. | ||
pub const CHANGED_IN_ATTRIBUTE: &str = "changed_in"; | ||
/// The `renamed` attribute. | ||
/// | ||
/// Is used when a trait method was renamed. | ||
pub const RENAMED_ATTRIBUTE: &str = "renamed"; | ||
/// All attributes that we support in the declaration of a runtime api trait. | ||
pub const SUPPORTED_ATTRIBUTE_NAMES: &[&str] = | ||
&[CORE_TRAIT_ATTRIBUTE, API_VERSION_ATTRIBUTE, CHANGED_IN_ATTRIBUTE, RENAMED_ATTRIBUTE]; |
This file contains 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.