metadata: Use v15 internally (#912)

* Update frame-metadata to v15.1.0

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Enable V15 unstable metadata in frame-metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Move validation hashing to dedicated file

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use sp-metadata-ir from substrate to work with metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert using sp-metadata-ir in favor of conversion to v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Convert v14 to v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Use v15 for validation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Use v15 for codegen

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata/bench: Use v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust to v15 metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* force CI

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Address feedback

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Use HASH_LEN

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadta: Remove `LatestRuntimeMetadata` type alias

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Remove `metadata_to_latest` to avoid pancis

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-04-20 17:59:28 +03:00
committed by GitHub
parent 2f1b67b384
commit 59d195d4ad
30 changed files with 1087 additions and 920 deletions
+7 -4
View File
@@ -4,12 +4,14 @@
use clap::Parser as ClapParser;
use color_eyre::eyre::{self, WrapErr};
use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed, RuntimeMetadataV14, META_RESERVED};
use frame_metadata::{
v15::RuntimeMetadataV15, RuntimeMetadata, RuntimeMetadataPrefixed, META_RESERVED,
};
use jsonrpsee::client_transport::ws::Uri;
use scale::Decode;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use subxt_metadata::{get_metadata_hash, get_pallet_hash};
use subxt_metadata::{get_metadata_hash, get_pallet_hash, metadata_v14_to_latest};
/// Verify metadata compatibility between substrate nodes.
#[derive(Debug, ClapParser)]
@@ -94,7 +96,7 @@ async fn handle_full_metadata(nodes: &[Uri]) -> color_eyre::Result<()> {
Ok(())
}
async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadataV14> {
async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadataV15> {
let bytes = subxt_codegen::utils::fetch_metadata_bytes(url).await?;
let metadata = <RuntimeMetadataPrefixed as Decode>::decode(&mut &bytes[..])?;
@@ -108,7 +110,8 @@ async fn fetch_runtime_metadata(url: &Uri) -> color_eyre::Result<RuntimeMetadata
}
match metadata.1 {
RuntimeMetadata::V14(v14) => Ok(v14),
RuntimeMetadata::V14(v14) => Ok(metadata_v14_to_latest(v14)),
RuntimeMetadata::V15(v15) => Ok(v15),
_ => Err(eyre::eyre!(
"Node {:?} with unsupported metadata version: {:?}",
url,
+9 -4
View File
@@ -8,7 +8,7 @@ use color_eyre::eyre;
use frame_metadata::{RuntimeMetadata, RuntimeMetadataPrefixed};
use scale::{Decode, Encode};
use std::io::{self, Write};
use subxt_metadata::retain_metadata_pallets;
use subxt_metadata::{metadata_v14_to_latest, retain_metadata_pallets};
/// Download metadata from a substrate node, for use with `subxt` codegen.
#[derive(Debug, ClapParser)]
@@ -20,6 +20,9 @@ pub struct Opts {
format: String,
/// Generate a subset of the metadata that contains only the
/// types needed to represent the provided pallets.
///
/// The returned metadata is updated to the latest available version
/// when using the option.
#[clap(long, use_value_delimiter = true, value_parser)]
pallets: Option<Vec<String>>,
}
@@ -29,8 +32,9 @@ pub async fn run(opts: Opts) -> color_eyre::Result<()> {
let mut metadata = <RuntimeMetadataPrefixed as Decode>::decode(&mut &bytes[..])?;
if let Some(pallets) = opts.pallets {
let metadata_v14 = match &mut metadata.1 {
RuntimeMetadata::V14(metadata_v14) => metadata_v14,
let mut metadata_v15 = match metadata.1 {
RuntimeMetadata::V14(metadata_v14) => metadata_v14_to_latest(metadata_v14),
RuntimeMetadata::V15(metadata_v15) => metadata_v15,
_ => {
return Err(eyre::eyre!(
"Unsupported metadata version {:?}, expected V14.",
@@ -39,9 +43,10 @@ pub async fn run(opts: Opts) -> color_eyre::Result<()> {
}
};
retain_metadata_pallets(metadata_v14, |pallet_name| {
retain_metadata_pallets(&mut metadata_v15, |pallet_name| {
pallets.iter().any(|p| &**p == pallet_name)
});
metadata = metadata_v15.into();
}
match opts.format.as_str() {