Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Metadata V15: Add Runtime API metadata #13302

Merged
merged 84 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a730fe1
impl_runtime_apis: Generate getters for `metadata_at` functions
lexnv Jan 30, 2023
bc1fed4
runtime: Implement new `Metadata` runtime trait
lexnv Jan 30, 2023
46681dd
runtime: Move `metadata_at` functions to construct_runtime macro
lexnv Jan 31, 2023
d03dd7d
contruct_runtime: Use `OpaqueMetadata` from hidden imports
lexnv Jan 31, 2023
441b7ad
Adjust testing
lexnv Jan 31, 2023
555ccfb
frame/tests: Add tests for the new API
lexnv Jan 31, 2023
b43038f
Merge remote-tracking branch 'origin/master' into lexnv/md15_expose_m…
Feb 2, 2023
d19bbcd
primitives/proc-macro: Helper to extract documentation literals
lexnv Feb 2, 2023
d6d2868
primitives/proc-macro: Helper to filter all `cfg` attributes
lexnv Feb 2, 2023
10a2cc5
primitives/proc-macro: Generate documentation getters for metadata
lexnv Feb 2, 2023
a345ece
primitives/proc-macro: Avoid trait collision with snake case methods
lexnv Feb 2, 2023
397eaa0
proc-macro/tests: Check doc getters
lexnv Feb 2, 2023
04b0c38
primitives/proc-macro: Generate metadata for runtime methods
lexnv Feb 2, 2023
a87dd22
primitives/api: Export scale-info and frame-metadata
lexnv Feb 2, 2023
874cf6e
primitives/proc-macro: Generate metadata for runtime traits
lexnv Feb 2, 2023
dad0980
frame/runtime: Expose metadata v15 internally
lexnv Feb 2, 2023
df770ec
test: Use metadata v15 from `lexnv/md_v15_test` branch
lexnv Feb 2, 2023
c33d3ca
primitives/proc-macro: Generate crate access one module up
lexnv Feb 2, 2023
e4782de
frame: Implement `runtime_metadata` for mocks and tests
lexnv Feb 3, 2023
3e9f5d4
primitives/proc-macro: Fix warnings
lexnv Feb 3, 2023
417fb8d
primitives/proc-macro: Add no-docs flag
lexnv Feb 3, 2023
de1352c
frame: Adjust more tests
lexnv Feb 3, 2023
3bf46aa
frame/tests: Check runtime metadata correctness
lexnv Feb 3, 2023
ae85bbe
frame/benchmarking: Adjust benchmarks
lexnv Feb 3, 2023
d37aa22
frame/benchmarks: Adjust more benchmarks
lexnv Feb 3, 2023
0d09ae6
primitives/api: Fix clippy
lexnv Feb 3, 2023
e8969d6
primitives/proc-macro: Generate runtime metadata on the `decl_runtime…
lexnv Feb 7, 2023
6239543
frame: Abuse Deref to resolve `runtime_metadata`
lexnv Feb 6, 2023
6822962
Revert "frame: Implement `runtime_metadata` for mocks and tests"
lexnv Feb 6, 2023
b1c3dd9
primitives/proc-macro: Remove unused imports and function
lexnv Feb 7, 2023
5ddfc55
frame/support: Adjust runtime metadata test
lexnv Feb 7, 2023
6511a2f
primitives/tests: Remove doc getter test
lexnv Feb 7, 2023
aeb125f
frame/support: Enable `no-metadata-docs` feature from `sp-api`
lexnv Feb 7, 2023
cb05db6
primitives/tests: Add `TypeInfo` for test::extrinsic
lexnv Feb 7, 2023
d1d8cbc
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
lexnv Mar 15, 2023
4c8287d
primitives/api: Expose scale-info and frame-metadata
lexnv Mar 16, 2023
e894ab0
Update frame-metadata to include v15
lexnv Mar 16, 2023
a6bfa9a
Fix merge conflicts
lexnv Mar 16, 2023
bd9be6d
frame/metadata_ir: Add IR for runtime API metadata
lexnv Mar 16, 2023
a7a5460
frame/metadata_ir: Convert IR to V15
lexnv Mar 16, 2023
c99200b
primitives/api: Collect IR metadata for runtime API
lexnv Mar 16, 2023
bc801f9
primitives/api: Move `metadata_ir` from frame/support
lexnv Mar 16, 2023
a069503
frame/tests: Adjust testing
lexnv Mar 16, 2023
436a3e2
frame/tests: Adjust `metadata_versions` test
lexnv Mar 16, 2023
24cfec5
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Mar 16, 2023
081fbc0
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Mar 17, 2023
5e841c1
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Mar 20, 2023
e1cd816
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Mar 21, 2023
112ea17
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Mar 21, 2023
24dfc28
primitives/runtime_metadata: Exclude default type parameters from met…
lexnv Mar 21, 2023
3787289
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
b64cfe5
Update primitives/api/src/metadata_ir/types.rs
lexnv Mar 29, 2023
36519ca
Update primitives/api/src/metadata_ir/mod.rs
lexnv Mar 29, 2023
c6c5336
Update primitives/api/proc-macro/src/utils.rs
lexnv Mar 29, 2023
e48afb1
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
4f5ae6d
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
8b1b3cf
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
6ee1a09
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
f0d857a
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
24f8c64
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 29, 2023
fa2a517
primitives: Fix build
lexnv Mar 29, 2023
e6888b9
primitives/metadata-ir: Move IR to dedicated crate
lexnv Mar 29, 2023
4c92435
primitives: Reexport metadata-ir and frame-metadata
lexnv Mar 29, 2023
e496815
frame: Use apis field instead of runtime
lexnv Mar 29, 2023
ca77baa
Better documentation for the `Deref` abstraction
lexnv Mar 29, 2023
cf78a71
ui-tests: Check empty `impl_runtime_apis`
lexnv Mar 30, 2023
5178e38
primitives: Remove unneeded bounds on generic params
lexnv Mar 30, 2023
be55193
primitives: Rename `collect_where_bounds` to `get_argument_type_param`
lexnv Mar 30, 2023
9e1fc77
primitives: Generate crate access per fn call
lexnv Mar 30, 2023
e281bc9
Revert "primitives: Remove unneeded bounds on generic params"
lexnv Mar 30, 2023
c850d2b
metadata-ir: Add no-std
lexnv Mar 30, 2023
df4d33d
primitives: Adjust where bounds
lexnv Mar 30, 2023
a3b5a4c
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
lexnv Mar 30, 2023
beada2c
Change `frame-metadata` branch to "origin/main"
lexnv Mar 30, 2023
bae34a7
Update to `main` from origin
lexnv Mar 30, 2023
0d9aad1
Update frame-metadata to crates.io v15.1
lexnv Mar 30, 2023
2d76e6d
Revert "ui-tests: Check empty `impl_runtime_apis`"
lexnv Mar 30, 2023
3bafb29
Move ui test to primitives/ui
lexnv Mar 30, 2023
27d8044
Update frame/support/test/tests/runtime_metadata.rs
lexnv Mar 30, 2023
f551830
Update primitives/api/proc-macro/src/runtime_metadata.rs
lexnv Mar 30, 2023
b558af5
Test already covered by `empty_impl_runtime_apis_call.stderr`
lexnv Mar 30, 2023
6f7675b
Retriger CI
lexnv Mar 30, 2023
add36ef
Merge remote-tracking branch 'origin/master' into lexnv/md15_runtime_…
Apr 10, 2023
8d582bf
Import `TokenStream` as `TokenStream2`
lexnv Apr 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ members = [
"primitives/keystore",
"primitives/maybe-compressed-blob",
"primitives/merkle-mountain-range",
"primitives/metadata-ir",
"primitives/npos-elections",
"primitives/npos-elections/fuzzer",
"primitives/offchain",
Expand Down
4 changes: 2 additions & 2 deletions frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
serde = { version = "1.0.136", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-metadata = { version = "15.0.0", default-features = false, features = ["v14"] }
frame-metadata = { version = "15.1.0", default-features = false, features = ["v14", "v15-unstable"] }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
Expand Down Expand Up @@ -74,7 +74,7 @@ runtime-benchmarks = []
try-runtime = []
# By default some types have documentation, `no-metadata-docs` allows to reduce the documentation
# in the metadata.
no-metadata-docs = ["frame-support-procedural/no-metadata-docs"]
no-metadata-docs = ["frame-support-procedural/no-metadata-docs", "sp-api/no-metadata-docs"]
# By default some types have documentation, `full-metadata-docs` allows to add documentation to
# more types in the metadata.
full-metadata-docs = ["scale-info/docs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ pub fn expand_runtime_metadata(
quote! {
impl #runtime {
fn metadata_ir() -> #scrate::metadata_ir::MetadataIR {
// Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata.
// The function is implemented by calling `impl_runtime_apis!`.
//
// However, the `construct_runtime!` may be called without calling `impl_runtime_apis!`.
// Rely on the `Deref` trait to differentiate between a runtime that implements
// APIs (by macro impl_runtime_apis!) and a runtime that is simply created (by macro construct_runtime!).
//
// Both `InternalConstructRuntime` and `InternalImplRuntimeApis` expose a `runtime_metadata()` function.
// `InternalConstructRuntime` is implemented by the `construct_runtime!` for Runtime references (`& Runtime`),
// while `InternalImplRuntimeApis` is implemented by the `impl_runtime_apis!` for Runtime (`Runtime`).
//
// Therefore, the `Deref` trait will resolve the `runtime_metadata` from `impl_runtime_apis!`
// when both macros are called; and will resolve an empty `runtime_metadata` when only the `construct_runtime!`
// is called.
//
// `Deref` needs a reference for resolving the function call.
let rt = #runtime;

bkchr marked this conversation as resolved.
Show resolved Hide resolved
#scrate::metadata_ir::MetadataIR {
pallets: #scrate::sp_std::vec![ #(#pallets),* ],
extrinsic: #scrate::metadata_ir::ExtrinsicMetadataIR {
Expand All @@ -95,7 +113,8 @@ pub fn expand_runtime_metadata(
})
.collect(),
},
ty: #scrate::scale_info::meta_type::<#runtime>()
ty: #scrate::scale_info::meta_type::<#runtime>(),
apis: (&rt).runtime_metadata(),
}
}

Expand Down
25 changes: 25 additions & 0 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ fn construct_runtime_final_expansion(
type RuntimeBlock = #block;
}

// Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata.
// The function is implemented by calling `impl_runtime_apis!`.
//
// However, the `construct_runtime!` may be called without calling `impl_runtime_apis!`.
// Rely on the `Deref` trait to differentiate between a runtime that implements
// APIs (by macro impl_runtime_apis!) and a runtime that is simply created (by macro construct_runtime!).
//
// Both `InternalConstructRuntime` and `InternalImplRuntimeApis` expose a `runtime_metadata()` function.
// `InternalConstructRuntime` is implemented by the `construct_runtime!` for Runtime references (`& Runtime`),
// while `InternalImplRuntimeApis` is implemented by the `impl_runtime_apis!` for Runtime (`Runtime`).
//
// Therefore, the `Deref` trait will resolve the `runtime_metadata` from `impl_runtime_apis!`
// when both macros are called; and will resolve an empty `runtime_metadata` when only the `construct_runtime!`
// is called.

#[doc(hidden)]
trait InternalConstructRuntime {
#[inline(always)]
fn runtime_metadata(&self) -> #scrate::sp_std::vec::Vec<#scrate::metadata_ir::RuntimeApiMetadataIR> {
Default::default()
}
}
#[doc(hidden)]
impl InternalConstructRuntime for &#name {}

#outer_event

#outer_origin
Expand Down
2 changes: 1 addition & 1 deletion frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub use paste;
pub use scale_info;
#[cfg(feature = "std")]
pub use serde;
pub use sp_api::metadata_ir;
pub use sp_core::{OpaqueMetadata, Void};
#[doc(hidden)]
pub use sp_core_hashing_proc_macro;
Expand Down Expand Up @@ -80,7 +81,6 @@ pub mod error;
pub mod crypto;
pub mod dispatch_context;
pub mod instances;
pub mod metadata_ir;
pub mod migrations;
pub mod traits;
pub mod weights;
Expand Down
2 changes: 2 additions & 0 deletions frame/support/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
serde = { version = "1.0.136", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" }
sp-arithmetic = { version = "6.0.0", default-features = false, path = "../../../primitives/arithmetic" }
sp-io = { version = "7.0.0", path = "../../../primitives/io", default-features = false }
sp-state-machine = { version = "0.13.0", optional = true, path = "../../../primitives/state-machine" }
Expand Down Expand Up @@ -47,6 +48,7 @@ std = [
"sp-state-machine",
"sp-arithmetic/std",
"sp-version/std",
"sp-api/std",
]
try-runtime = ["frame-support/try-runtime"]
# WARNING:
Expand Down
2 changes: 1 addition & 1 deletion frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ fn metadata_at_version() {

#[test]
fn metadata_versions() {
assert_eq!(vec![LATEST_METADATA_VERSION], Runtime::metadata_versions());
assert_eq!(vec![LATEST_METADATA_VERSION, u32::MAX], Runtime::metadata_versions());
}

#[test]
Expand Down
Loading