Skip to content
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

Utilize Metadata V15 #1041

Merged
merged 67 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b48d2ee
Update frame-metadata to the latest branch
lexnv Jun 29, 2023
dde7411
metadata: Add outer enum types
lexnv Jun 29, 2023
326af9b
metadata: Extend the extrinsic with address,call,sign,extra types
lexnv Jun 29, 2023
db542dc
Codegen test Event, Error and Call for outer enums
lexnv Jun 29, 2023
53e3d93
Revert "Codegen test Event, Error and Call for outer enums"
lexnv Jun 30, 2023
f2d1c92
Update frame-metadata from the latest release
lexnv Jun 30, 2023
d401f21
Update scale-info
lexnv Jul 3, 2023
e0be009
codegen/error: Support v15 message
lexnv Jul 3, 2023
8a9e0cf
metadata: Convert v14 to v15
lexnv Jul 3, 2023
f1332b7
metadata/retain: Adjust to extrinsic type for V15
lexnv Jul 3, 2023
d035bb5
metadata/validation: Adjust hashing for extrinsic types V15
lexnv Jul 3, 2023
06aa5dc
scripts: Fetch V15 and output codegen for full_client only
lexnv Jul 3, 2023
d094a48
subxt/blocks: Use extrinsic types directly
lexnv Jul 3, 2023
60d38a7
testing: Fetch V15 for build script
lexnv Jul 3, 2023
a994c22
artifacts: Generate from latest polkadot version
lexnv Jul 3, 2023
5e8318c
codegen: Fetch legacy with old API for v14 only
lexnv Jul 4, 2023
fa0c044
rpc: Fetch metadata versions
lexnv Jul 4, 2023
5093d22
client: Fetch latest unstable then V15 then V14
lexnv Jul 4, 2023
16562e1
testing: Adjust testing API to latest interface
lexnv Jul 4, 2023
c503732
Merge remote-tracking branch 'origin/master' into lexnv/stable_v15
lexnv Jul 4, 2023
d719e8b
Adjust clippy
lexnv Jul 4, 2023
51beb8b
metadata: Generate the `RuntimeError` type for V14
lexnv Jul 4, 2023
8bd8fdb
Remove testing files
lexnv Jul 5, 2023
0767c3c
testing/staking: Remove controller account from bond
lexnv Jul 5, 2023
1f2c9ba
metadata/validation: Use specific variants for hashing RuntimeCall
lexnv Jul 5, 2023
e970529
XXX: Custom Substrate binary: must revert with next release
lexnv Jul 5, 2023
b18a5a0
XXX: To revert: CI use hardcoded substrate
lexnv Jul 5, 2023
a11308a
codegen: Use v15 outer enum types
lexnv Jul 6, 2023
b5e6a76
metadata: Retain outer enum types
lexnv Jul 6, 2023
f31289e
codegen: Use outer enum types instead of generating them
lexnv Jul 6, 2023
65d2e69
Update artifacts
lexnv Jul 6, 2023
5d33dec
Revert "XXX: Custom Substrate binary: must revert with next release"
lexnv Jul 6, 2023
e0b3f8a
testing: Include env for dummy wat contracts
lexnv Jul 6, 2023
c89203b
Adjsut clippy
lexnv Jul 6, 2023
bee6d87
ci: Use new link for fetching latest substrate binary
lexnv Jul 6, 2023
11bf5ae
tests: Include dummy RuntimeEvent into test metadata
lexnv Jul 6, 2023
dfb879c
ci: Bump light-client timeout tests to 25min
lexnv Jul 6, 2023
08f230a
metadata/validation: Use specific pallets as provided
lexnv Jul 6, 2023
2ca7bca
testing: Rename metadata constant
lexnv Jul 12, 2023
fb8242a
metadata: Use call_ty instead of signature_ty
lexnv Jul 12, 2023
414270a
metadata: Rename retaining variant function
lexnv Jul 12, 2023
73832bb
metadata: Use Option<&[&str]>
lexnv Jul 12, 2023
d86128d
online_client: Fetch V15 metadata explicitely
lexnv Jul 12, 2023
58af952
Merge remote-tracking branch 'origin/master' into lexnv/stable_v15
lexnv Jul 12, 2023
ed786b6
metadata/validation: Include the hash of the outer enum types
lexnv Jul 12, 2023
d8da7fa
metadata: Fix sign typo
lexnv Jul 12, 2023
437a589
artifacts: Update the artifacts
lexnv Jul 12, 2023
a6c57fc
subxt: Remove RootError RootEvent and RootExtrinsic traits
lexnv Jul 12, 2023
ec7f215
Update polkadot.rs
lexnv Jul 12, 2023
9ba48b3
metadata/tests: Ensure outer enum variants are retained
lexnv Jul 12, 2023
8995ad6
scripts: Include multiple pallets for our decoding purposes
lexnv Jul 12, 2023
bc9f66a
subxt: Apply clippy
lexnv Jul 12, 2023
55b7730
artifacts: Update small metadata
lexnv Jul 12, 2023
66a0db0
error: Keep raw bytes for the ModuleError representation
lexnv Jul 12, 2023
a16743a
error: Modify docs to not include links
lexnv Jul 12, 2023
44924fb
subxt/tests: Propagate `RuntimeCall` to outer enums
lexnv Jul 13, 2023
e7f7e51
subxt: Provide proper byte slice for decoding
lexnv Jul 13, 2023
26179a3
Update artifacts
lexnv Jul 13, 2023
09b685c
cli/tests: Adjust expected pallets message
lexnv Jul 13, 2023
525a8c4
metadata: Test conversion from v14 to v15
lexnv Jul 13, 2023
e942f9e
metadata: Fix typo
lexnv Jul 13, 2023
31200a0
Update subxt/src/blocks/extrinsic_types.rs
lexnv Jul 13, 2023
5eee195
Merge remote-tracking branch 'origin/lexnv/stable_v15' into lexnv/sta…
lexnv Jul 13, 2023
089bf56
metadata: Simplify type path for RuntimeError
lexnv Jul 13, 2023
1b77eb1
metadata/validation: Use visited ids per outer enum
lexnv Jul 13, 2023
496e878
error: Remove RawModuleError
lexnv Jul 13, 2023
2d0d30c
Fix new clippy error from updated rust version
lexnv Jul 13, 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
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
env:
CARGO_TERM_COLOR: always
# Use latest substrate for nightly runs:
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:stretch/latest/substrate/substrate
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:bullseye/latest/substrate/substrate

jobs:
tests:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ concurrency:
env:
CARGO_TERM_COLOR: always
# TODO: Currently pointing at latest substrate; is there a suitable binary we can pin to here?
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:stretch/latest/substrate/substrate
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:bullseye/latest/substrate/substrate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time it'd prolly be good to get the CI fixes in a separate PR too so we can merge them more easily, but I think this will be able to merge shortly anyway hopefully now :)


jobs:
build:
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
nonwasm_light_client_tests:
name: "Test Light Client"
runs-on: ubuntu-latest-16-cores
timeout-minutes: 15
timeout-minutes: 25
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down
33 changes: 22 additions & 11 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ console_error_panic_hook = "0.1.7"
darling = "0.20.0"
derivative = "2.2.0"
either = "1.8.1"
frame-metadata = { version = "15.1.0", features = ["v14", "v15-unstable", "std"] }
frame-metadata = { version = "16.0.0", default-features = false, features = ["current", "std"] }
futures = { version = "0.3.27", default-features = false, features = ["std"] }
getrandom = { version = "0.2", default-features = false }
hex = "0.4.3"
Expand All @@ -58,7 +58,7 @@ proc-macro-error = "1.0.4"
proc-macro2 = "1.0.63"
quote = "1.0.29"
regex = "1.8.4"
scale-info = "2.8.0"
scale-info = "2.9.0"
scale-value = "0.10.0"
scale-bits = "0.3"
scale-decode = "0.7.0"
Expand Down
Binary file modified artifacts/polkadot_metadata_full.scale
Binary file not shown.
Binary file modified artifacts/polkadot_metadata_small.scale
Binary file not shown.
Binary file modified artifacts/polkadot_metadata_tiny.scale
Binary file not shown.
78 changes: 13 additions & 65 deletions codegen/src/api/mod.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see the codegen simplifications here :)

Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,12 @@ impl RuntimeGenerator {
) -> Result<TokenStream2, CodegenError> {
let item_mod_attrs = item_mod.attrs.clone();
let item_mod_ir = ir::ItemMod::try_from(item_mod)?;
let default_derives = derives.default_derives();

let type_gen = TypeGenerator::new(
self.metadata.types(),
"runtime_types",
type_substitutes,
derives.clone(),
derives,
crate_path.clone(),
should_gen_docs,
);
Expand Down Expand Up @@ -382,46 +381,6 @@ impl RuntimeGenerator {
})
.collect::<Result<Vec<_>, CodegenError>>()?;

let outer_event_variants = self.metadata.pallets().filter_map(|p| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wooo, even more red than last time :D

let variant_name = format_ident!("{}", p.name());
let mod_name = format_ident!("{}", p.name().to_string().to_snake_case());
let index = proc_macro2::Literal::u8_unsuffixed(p.index());

p.event_ty_id().map(|_| {
quote! {
#[codec(index = #index)]
#variant_name(#mod_name::Event),
}
})
});

let outer_event = quote! {
#default_derives
pub enum Event {
#( #outer_event_variants )*
}
};

let outer_extrinsic_variants = self.metadata.pallets().filter_map(|p| {
let variant_name = format_ident!("{}", p.name());
let mod_name = format_ident!("{}", p.name().to_string().to_snake_case());
let index = proc_macro2::Literal::u8_unsuffixed(p.index());

p.call_ty_id().map(|_| {
quote! {
#[codec(index = #index)]
#variant_name(#mod_name::Call),
}
})
});

let outer_extrinsic = quote! {
#default_derives
pub enum Call {
#( #outer_extrinsic_variants )*
}
};

let root_event_if_arms = self.metadata.pallets().filter_map(|p| {
let variant_name_str = &p.name();
let variant_name = format_ident!("{}", variant_name_str);
Expand Down Expand Up @@ -459,26 +418,6 @@ impl RuntimeGenerator {
})
});

let outer_error_variants = self.metadata.pallets().filter_map(|p| {
let variant_name = format_ident!("{}", p.name());
let mod_name = format_ident!("{}", p.name().to_string().to_snake_case());
let index = proc_macro2::Literal::u8_unsuffixed(p.index());

p.error_ty_id().map(|_| {
quote! {
#[codec(index = #index)]
#variant_name(#mod_name::Error),
}
})
});

let outer_error = quote! {
#default_derives
pub enum Error {
#( #outer_error_variants )*
}
};

let root_error_if_arms = self.metadata.pallets().filter_map(|p| {
let variant_name_str = &p.name();
let variant_name = format_ident!("{}", variant_name_str);
Expand Down Expand Up @@ -526,6 +465,12 @@ impl RuntimeGenerator {
should_gen_docs,
)?;

// Fetch the paths of the outer enums.
// Substrate exposes those under `kitchensink_runtime`, while Polkadot under `polkadot_runtime`.
let call_path = type_gen.resolve_type_path(self.metadata.outer_enums().call_enum_ty());
let event_path = type_gen.resolve_type_path(self.metadata.outer_enums().event_enum_ty());
let error_path = type_gen.resolve_type_path(self.metadata.outer_enums().error_enum_ty());

Ok(quote! {
#( #item_mod_attrs )*
#[allow(dead_code, unused_imports, non_camel_case_types)]
Expand All @@ -551,7 +496,8 @@ impl RuntimeGenerator {
/// The error type returned when there is a runtime issue.
pub type DispatchError = #types_mod_ident::sp_runtime::DispatchError;

#outer_event
/// The outer event enum.
pub type Event = #event_path;

impl #crate_path::events::RootEvent for Event {
lexnv marked this conversation as resolved.
Show resolved Hide resolved
fn root_event(pallet_bytes: &[u8], pallet_name: &str, pallet_ty: u32, metadata: &#crate_path::Metadata) -> Result<Self, #crate_path::Error> {
Expand All @@ -561,7 +507,8 @@ impl RuntimeGenerator {
}
}

#outer_extrinsic
/// The outer extrinsic enum.
pub type Call = #call_path;

impl #crate_path::blocks::RootExtrinsic for Call {
fn root_extrinsic(pallet_bytes: &[u8], pallet_name: &str, pallet_ty: u32, metadata: &#crate_path::Metadata) -> Result<Self, #crate_path::Error> {
Expand All @@ -571,7 +518,8 @@ impl RuntimeGenerator {
}
}

#outer_error
/// The outer error enum representing the DispatchError's Module variant.
pub type Error = #error_path;

impl #crate_path::error::RootError for Error {
fn root_error(pallet_bytes: &[u8], pallet_name: &str, metadata: &#crate_path::Metadata) -> Result<Self, #crate_path::Error> {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum CodegenError {
#[error("Failed IO for {0}, make sure that you are providing the correct file path for metadata: {1}")]
Io(String, std::io::Error),
/// Cannot decode the metadata bytes.
#[error("Could not decode metadata, only V14 metadata is supported: {0}")]
#[error("Could not decode metadata, only V14 and V15 metadata are supported: {0}")]
Decode(#[from] codec::Error),
/// Out of line modules are not supported.
#[error("Out-of-line subxt modules are not supported, make sure you are providing a body to your module: pub mod polkadot {{ ... }}")]
Expand Down
7 changes: 2 additions & 5 deletions codegen/src/utils/fetch_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,9 @@ async fn fetch_metadata(
client: &impl ClientT,
version: MetadataVersion,
) -> Result<Vec<u8>, FetchMetadataError> {
if !matches!(
version,
MetadataVersion::Latest | MetadataVersion::Version(14)
) {
if !matches!(version, MetadataVersion::Version(14)) {
return Err(FetchMetadataError::Other(
"The node can only return version 14 metadata but you've asked for something else"
"The node can only return version 14 metadata using the legacy API but you've asked for something else"
.to_string(),
));
}
Expand Down
Loading
Loading