Skip to content

Support v16 metadata and use it by default if it's available #1999

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
merged 10 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,344 changes: 1,479 additions & 865 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ blake2 = { version = "0.10.6", default-features = false }
clap = { version = "4.5.18", features = ["derive", "cargo"] }
cfg-if = "1.0.0"
criterion = "0.5.1"
codec = { package = "parity-scale-codec", version = "3.6.9", default-features = false }
codec = { package = "parity-scale-codec", version = "3.7.4", default-features = false }
color-eyre = "0.6.3"
console_error_panic_hook = "0.1.7"
darling = "0.20.10"
derive-where = "1.2.7"
either = { version = "1.13.0", default-features = false }
finito = { version = "0.1.0", default-features = false }
frame-decode = { version = "0.7.1", default-features = false }
frame-metadata = { version = "21.0.0", default-features = false, features = ["unstable"] }
frame-decode = { version = "0.8.0", default-features = false }
frame-metadata = { version = "23.0.0", default-features = false, features = ["unstable"] }
futures = { version = "0.3.31", default-features = false, features = ["std"] }
getrandom = { version = "0.2", default-features = false }
hashbrown = "0.14.5"
Expand All @@ -100,7 +100,7 @@ scale-value = { version = "0.18.0", default-features = false }
scale-bits = { version = "0.7.0", default-features = false }
scale-decode = { version = "0.16.0", default-features = false }
scale-encode = { version = "0.10.0", default-features = false }
scale-typegen = "0.11.0"
scale-typegen = "0.11.1"
scale-typegen-description = "0.11.0"
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.128", default-features = false }
Expand Down Expand Up @@ -141,15 +141,15 @@ web-time = { version = "1.1", default-features = false }
tokio-util = "0.7.12"

# Substrate crates:
sc-executor = { version = "0.41.0", default-features = false }
sc-executor-common = { version = "0.36.0", default-features = false }
sc-executor = { version = "0.42.0", default-features = false }
sc-executor-common = { version = "0.38.0", default-features = false }
sp-crypto-hashing = { version = "0.1.0", default-features = false }
sp-core = { version = "35.0.0", default-features = false }
sp-keyring = { version = "40.0.0", default-features = false }
sp-core = { version = "36.1.0", default-features = false }
sp-keyring = { version = "41.0.0", default-features = false }
sp-maybe-compressed-blob = { version = "11.0.0", default-features = false }
sp-io = { version = "39.0.0", default-features = false }
sp-state-machine = { version = "0.44.0", default-features = false }
sp-runtime = { version = "40.0.1", default-features = false }
sp-io = { version = "40.0.1", default-features = false }
sp-state-machine = { version = "0.45.0", default-features = false }
sp-runtime = { version = "41.1.0", default-features = false }

# Subxt workspace crates:
subxt = { version = "0.41.0", path = "subxt", default-features = false }
Expand Down
8 changes: 2 additions & 6 deletions core/src/utils/account_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,11 @@ impl core::str::FromStr for AccountId32 {
mod test {
use super::*;
use sp_core::{self, crypto::Ss58Codec};
use sp_keyring::AccountKeyring;
use sp_keyring::sr25519::Keyring;

#[test]
fn ss58_is_compatible_with_substrate_impl() {
let keyrings = vec![
AccountKeyring::Alice,
AccountKeyring::Bob,
AccountKeyring::Charlie,
];
let keyrings = vec![Keyring::Alice, Keyring::Bob, Keyring::Charlie];

for keyring in keyrings {
let substrate_account = keyring.to_account_id();
Expand Down
1 change: 1 addition & 0 deletions macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ proc-macro-error2 = { workspace = true }
syn = { workspace = true }
quote = { workspace = true }
subxt-codegen = { workspace = true }
subxt-metadata = { workspace = true }
subxt-utils-fetchmetadata = { workspace = true }
scale-typegen = { workspace = true }
sc-executor = { workspace = true, optional = true }
Expand Down
3 changes: 1 addition & 2 deletions macro/src/wasm_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use sc_executor::{WasmExecutionMethod, WasmExecutor};
use sc_executor_common::runtime_blob::RuntimeBlob;
use sp_maybe_compressed_blob::{self, CODE_BLOB_BOMB_LIMIT};
use subxt_codegen::{CodegenError, Metadata};

static SUPPORTED_METADATA_VERSIONS: [u32; 2] = [14, 15];
use subxt_metadata::SUPPORTED_METADATA_VERSIONS;

/// Result type shorthand
pub type WasmMetadataResult<A> = Result<A, CodegenError>;
Expand Down
9 changes: 6 additions & 3 deletions metadata/src/from/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ mod v14;
mod v15;
mod v16;

/// The metadata versions that we support converting into [`crate::Metadata`].
/// These are ordest from highest to lowest, so that the metadata we'd want to
/// pick first is first in the array.
pub const SUPPORTED_METADATA_VERSIONS: [u32; 3] = [16, 15, 14];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this here so that we have only one array of supported versions that's used anywhere we need it


/// An error emitted if something goes wrong converting [`frame_metadata`]
/// types into [`crate::Metadata`].
#[derive(Debug, PartialEq, Eq, DeriveError)]
Expand Down Expand Up @@ -79,9 +84,7 @@ impl TryFrom<frame_metadata::RuntimeMetadataPrefixed> for crate::Metadata {
}
frame_metadata::RuntimeMetadata::V14(m) => m.try_into(),
frame_metadata::RuntimeMetadata::V15(m) => m.try_into(),
frame_metadata::RuntimeMetadata::V16(_opaque) => {
Err(TryFromError::UnsupportedMetadataVersion(16))
}
frame_metadata::RuntimeMetadata::V16(m) => m.try_into(),
}
}
}
1 change: 1 addition & 0 deletions metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use utils::{
type ArcStr = Arc<str>;

pub use from::TryFromError;
pub use from::SUPPORTED_METADATA_VERSIONS;
pub use utils::validation::MetadataHasher;

type CustomMetadataInner = frame_metadata::v15::CustomMetadata<PortableForm>;
Expand Down
15 changes: 7 additions & 8 deletions subxt/src/client/online_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,14 @@ impl<T: Config> OnlineClient<T> {
backend: &dyn Backend<T>,
block_hash: HashFor<T>,
) -> Result<Metadata, Error> {
// This is the latest stable metadata that subxt can utilize.
const V15_METADATA_VERSION: u32 = 15;
// The metadata versions we support in Subxt, from newest to oldest.
use subxt_metadata::SUPPORTED_METADATA_VERSIONS;

// Try to fetch the metadata version.
if let Ok(bytes) = backend
.metadata_at_version(V15_METADATA_VERSION, block_hash)
.await
{
return Ok(bytes);
// Try to fetch each version that we support in order from newest to oldest.
for version in SUPPORTED_METADATA_VERSIONS {
if let Ok(bytes) = backend.metadata_at_version(version, block_hash).await {
return Ok(bytes);
}
}

// If that fails, fetch the metadata V14 using the old API.
Expand Down
1 change: 1 addition & 0 deletions testing/integration-tests/src/full_client/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ async fn decode_transaction_extensions_from_blocks() {
assert_eq!(tip2, tip2_static);

let expected_transaction_extensions = [
"AuthorizeCall",
"CheckNonZeroSender",
"CheckSpecVersion",
"CheckTxVersion",
Expand Down
24 changes: 2 additions & 22 deletions testing/integration-tests/src/full_client/frame/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// see LICENSE for license details.

use crate::{
node_runtime::{self, balances, runtime_types, system},
node_runtime::{self, balances, system},
subxt_test, test_context,
};
use codec::Decode;
Expand Down Expand Up @@ -282,30 +282,10 @@ async fn storage_total_issuance() {

#[subxt_test]
async fn storage_balance_lock() -> Result<(), subxt::Error> {
let bob_signer = dev::bob();
let bob: AccountId32 = dev::bob().public_key().into();
let ctx = test_context().await;
let api = ctx.client();

let tx = node_runtime::tx().staking().bond(
100_000_000_000_000,
runtime_types::pallet_staking::RewardDestination::Stash,
);

let signed_extrinsic = api
.tx()
.create_signed(&tx, &bob_signer, Default::default())
.await?;

signed_extrinsic
.submit_and_watch()
.await
.unwrap()
.wait_for_finalized_success()
.await?
.find_first::<system::events::ExtrinsicSuccess>()?
.expect("No ExtrinsicSuccess Event found");

Comment on lines -290 to -308
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is already a hold now so no need to artifically create one.

let holds_addr = node_runtime::storage().balances().holds(bob);

let holds = api
Expand All @@ -318,7 +298,7 @@ async fn storage_balance_lock() -> Result<(), subxt::Error> {

// There is now a hold on the balance being staked
assert_eq!(holds.len(), 1);
assert_eq!(holds[0].amount, 100_000_000_000_000);
assert_eq!(holds[0].amount, 327_000_000_000_000);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Copyright 2019-2025 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.

// TODO: Re-enable these once V16 is stable in Substrate nightlies,
// and test-runtime is updated to pull in V16 metadata by default.
/*
use crate::{subxt_test, test_context};
use test_runtime::node_runtime_unstable;

Expand Down Expand Up @@ -58,3 +65,4 @@ async fn call_view_function_dynamically() -> Result<(), subxt::Error> {

Ok(())
}
*/
Loading
Loading