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

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

* lockfile

* fix blocks test; new transaction extension in kitchensink runtime

* Bump scale-typegen to 0.11.1 to cater for Duration prelude type

* fmt

* Fix no-std test building

* Cargo update and bump substrate deps

* Update test and no-std deps

* fmt

* fix test
This commit is contained in:
James Wilson
2025-05-08 14:44:44 +01:00
committed by GitHub
parent 4524590821
commit 9ba89e3ed7
16 changed files with 1674 additions and 1223 deletions
Generated
+1484 -870
View File
File diff suppressed because it is too large Load Diff
+11 -11
View File
@@ -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"
@@ -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 }
@@ -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 }
+2 -6
View File
@@ -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();
+1
View File
@@ -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 }
+1 -2
View File
@@ -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>;
+6 -3
View File
@@ -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];
/// An error emitted if something goes wrong converting [`frame_metadata`]
/// types into [`crate::Metadata`].
#[derive(Debug, PartialEq, Eq, DeriveError)]
@@ -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
View File
@@ -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>;
+7 -8
View File
@@ -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.
@@ -333,6 +333,7 @@ async fn decode_transaction_extensions_from_blocks() {
assert_eq!(tip2, tip2_static);
let expected_transaction_extensions = [
"AuthorizeCall",
"CheckNonZeroSender",
"CheckSpecVersion",
"CheckTxVersion",
@@ -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;
@@ -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");
let holds_addr = node_runtime::storage().balances().holds(bob);
let holds = api
@@ -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(())
}
@@ -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;
@@ -58,3 +65,4 @@ async fn call_view_function_dynamically() -> Result<(), subxt::Error> {
Ok(())
}
*/
+85 -232
View File
@@ -2,16 +2,6 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "aead"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"generic-array",
]
[[package]]
name = "ahash"
version = "0.8.11"
@@ -96,9 +86,9 @@ dependencies = [
[[package]]
name = "blake2b_simd"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780"
checksum = "06e903a20b159e944f91ec8499fe1e55651480c541ea0a584f5d967c49ad9d99"
dependencies = [
"arrayref",
"arrayvec",
@@ -116,9 +106,9 @@ dependencies = [
[[package]]
name = "byte-slice-cast"
version = "1.2.2"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c"
checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d"
[[package]]
name = "byteorder"
@@ -180,42 +170,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"rand_core",
"typenum",
]
[[package]]
name = "curve25519-dalek"
version = "4.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"
dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"digest",
"fiat-crypto",
"rustc_version",
"subtle",
"zeroize",
]
[[package]]
name = "curve25519-dalek-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "darling"
version = "0.20.10"
version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
dependencies = [
"darling_core",
"darling_macro",
@@ -223,9 +185,9 @@ dependencies = [
[[package]]
name = "darling_core"
version = "0.20.10"
version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
dependencies = [
"fnv",
"ident_case",
@@ -237,9 +199,9 @@ dependencies = [
[[package]]
name = "darling_macro"
version = "0.20.10"
version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
dependencies = [
"darling_core",
"quote",
@@ -248,9 +210,9 @@ dependencies = [
[[package]]
name = "derive-where"
version = "1.2.7"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
checksum = "e73f2692d4bd3cac41dca28934a39894200c9fabf49586d77d0e5954af1d7902"
dependencies = [
"proc-macro2",
"quote",
@@ -290,21 +252,15 @@ dependencies = [
[[package]]
name = "either"
version = "1.13.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "equivalent"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fiat-crypto"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "fixed-hash"
@@ -323,9 +279,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "frame-decode"
version = "0.6.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a784e501ed2cec99eb00a1e78e42740fcb05f1aea7bbea90bf46f0a9f255bb"
checksum = "e1276c23a1fb234d9f81b5f71c526437f2a55ab4419f29bfe1196ac4ee2f706c"
dependencies = [
"frame-metadata",
"parity-scale-codec",
@@ -337,9 +293,9 @@ dependencies = [
[[package]]
name = "frame-metadata"
version = "18.0.0"
version = "23.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daaf440c68eb2c3d88e5760fe8c7af3f9fee9181fab6c2f2c4e7cc48dcc40bb8"
checksum = "d8c26fcb0454397c522c05fdad5380c4e622f8a875638af33bff5a320d1fc965"
dependencies = [
"cfg-if",
"parity-scale-codec",
@@ -362,26 +318,6 @@ dependencies = [
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "getrandom_or_panic"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea1015b5a70616b688dc230cfe50c8af89d972cb132d5a622814d29773b10b9"
dependencies = [
"rand_core",
]
[[package]]
name = "hashbrown"
version = "0.14.5"
@@ -394,9 +330,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.15.2"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
[[package]]
name = "heck"
@@ -433,9 +369,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "impl-codec"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941"
checksum = "2d40b9d5e17727407e55028eafc22b2dc68781786e6d7eb8a21103f5058e3a14"
dependencies = [
"parity-scale-codec",
]
@@ -462,19 +398,19 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.7.1"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
dependencies = [
"equivalent",
"hashbrown 0.15.2",
"hashbrown 0.15.3",
]
[[package]]
name = "itoa"
version = "1.0.14"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "keccak"
@@ -497,9 +433,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.169"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libc_alloc"
@@ -513,29 +449,17 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "merlin"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d"
dependencies = [
"byteorder",
"keccak",
"rand_core",
"zeroize",
]
[[package]]
name = "once_cell"
version = "1.20.2"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "parity-scale-codec"
version = "3.7.2"
version = "3.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91c2d9a6a6004e205b7e881856fb1a0f5022d382acc2c01b52185f7b6f65997"
checksum = "c9fde3d0718baf5bc92f577d652001da0f8d54cd03a7974e118d04fc888dc23d"
dependencies = [
"arrayvec",
"bitvec",
@@ -549,9 +473,9 @@ dependencies = [
[[package]]
name = "parity-scale-codec-derive"
version = "3.7.2"
version = "3.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77555fd9d578b6470470463fded832619a5fec5ad6cbc551fe4d7507ce50cd3a"
checksum = "581c837bb6b9541ce7faa9377c20616e4fb7650f6b0f68bc93c827ee504fb7b3"
dependencies = [
"proc-macro-crate",
"proc-macro2",
@@ -574,15 +498,6 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "polkadot-sdk"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb819108697967452fa6d8d96ab4c0d48cbaa423b3156499dcb24f1cf95d6775"
dependencies = [
"sp-crypto-hashing",
]
[[package]]
name = "primitive-types"
version = "0.13.1"
@@ -598,9 +513,9 @@ dependencies = [
[[package]]
name = "proc-macro-crate"
version = "3.2.0"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b"
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
dependencies = [
"toml_edit",
]
@@ -629,18 +544,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.93"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
@@ -651,15 +566,6 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "regex"
version = "1.11.1"
@@ -685,26 +591,17 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "rustversion"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "ryu"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "scale-bits"
@@ -811,9 +708,9 @@ dependencies = [
[[package]]
name = "scale-typegen"
version = "0.10.0"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc3173be608895eb117cf397ab4f31f00e2ed2c7af1c6e0b8f5d51d0a0967053"
checksum = "05c61b6b706a3eaad63b506ab50a1d2319f817ae01cf753adcc3f055f9f0fcd6"
dependencies = [
"proc-macro2",
"quote",
@@ -837,24 +734,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "schnorrkel"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de18f6d8ba0aad7045f5feae07ec29899c1112584a38509a84ad7b04451eaa0"
dependencies = [
"aead",
"arrayref",
"arrayvec",
"curve25519-dalek",
"getrandom_or_panic",
"merlin",
"rand_core",
"sha2",
"subtle",
"zeroize",
]
[[package]]
name = "secrecy"
version = "0.10.3"
@@ -864,26 +743,20 @@ dependencies = [
"zeroize",
]
[[package]]
name = "semver"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03"
[[package]]
name = "serde"
version = "1.0.217"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.217"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
@@ -892,9 +765,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.138"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
@@ -904,9 +777,9 @@ dependencies = [
[[package]]
name = "sha2"
version = "0.10.8"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
@@ -925,9 +798,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.13.2"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
[[package]]
name = "sp-crypto-hashing"
@@ -963,7 +836,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "subxt-codegen"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"heck",
"parity-scale-codec",
@@ -978,7 +851,7 @@ dependencies = [
[[package]]
name = "subxt-core"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"base58",
"blake2",
@@ -990,7 +863,6 @@ dependencies = [
"impl-serde",
"keccak-hash",
"parity-scale-codec",
"polkadot-sdk",
"primitive-types",
"scale-bits",
"scale-decode",
@@ -999,6 +871,7 @@ dependencies = [
"scale-value",
"serde",
"serde_json",
"sp-crypto-hashing",
"subxt-metadata",
"thiserror",
"tracing",
@@ -1018,7 +891,7 @@ dependencies = [
[[package]]
name = "subxt-macro"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"darling",
"parity-scale-codec",
@@ -1026,26 +899,27 @@ dependencies = [
"quote",
"scale-typegen",
"subxt-codegen",
"subxt-metadata",
"subxt-utils-fetchmetadata",
"syn",
]
[[package]]
name = "subxt-metadata"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"frame-decode",
"frame-metadata",
"hashbrown 0.14.5",
"parity-scale-codec",
"polkadot-sdk",
"scale-info",
"sp-crypto-hashing",
"thiserror",
]
[[package]]
name = "subxt-signer"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"bip39",
"cfg-if",
@@ -1053,11 +927,10 @@ dependencies = [
"hmac",
"parity-scale-codec",
"pbkdf2",
"polkadot-sdk",
"regex",
"schnorrkel",
"secrecy",
"sha2",
"sp-crypto-hashing",
"subxt-core",
"thiserror",
"zeroize",
@@ -1065,7 +938,7 @@ dependencies = [
[[package]]
name = "subxt-utils-fetchmetadata"
version = "0.39.0"
version = "0.41.0"
dependencies = [
"hex",
"parity-scale-codec",
@@ -1074,9 +947,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.96"
version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [
"proc-macro2",
"quote",
@@ -1091,18 +964,18 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "thiserror"
version = "2.0.11"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.11"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
@@ -1120,15 +993,15 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.8"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3"
[[package]]
name = "toml_edit"
version = "0.22.22"
version = "0.22.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
dependencies = [
"indexmap",
"toml_datetime",
@@ -1164,9 +1037,9 @@ dependencies = [
[[package]]
name = "typenum"
version = "1.17.0"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
[[package]]
name = "uint"
@@ -1182,9 +1055,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.16"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-xid"
@@ -1198,17 +1071,11 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winnow"
version = "0.6.25"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad699df48212c6cc6eb4435f35500ac6fd3b9913324f938aea302022ce19d310"
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
dependencies = [
"memchr",
]
@@ -1247,17 +1114,3 @@ name = "zeroize"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
-1
View File
@@ -13,7 +13,6 @@ pub extern "C" fn _start(_argc: isize, _argv: *const *const u8) -> isize {
}
#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}
#[panic_handler]
+24 -26
View File
@@ -10,7 +10,6 @@ use substrate_runner::{Error as SubstrateNodeError, SubstrateNode};
static SUBSTRATE_BIN_ENV_VAR: &str = "SUBSTRATE_NODE_PATH";
const V15_METADATA_VERSION: u32 = 15;
const UNSTABLE_METADATA_VERSION: u32 = u32::MAX;
#[tokio::main]
async fn main() {
@@ -43,10 +42,10 @@ async fn run() {
let out_dir_env_var = env::var_os("OUT_DIR");
let out_dir = out_dir_env_var.as_ref().unwrap().to_str().unwrap();
let (stable_metadata_path, unstable_metadata_path) = tokio::join!(
download_and_save_metadata(V15_METADATA_VERSION, port, out_dir, "v15"),
download_and_save_metadata(UNSTABLE_METADATA_VERSION, port, out_dir, "unstable")
);
let stable_metadata_path =
download_and_save_metadata(V15_METADATA_VERSION, port, out_dir, "v15")
.await
.unwrap_or_else(|e| panic!("Cannot download & save v15 metadata: {e}"));
// Write out our expression to generate the runtime API to a file. Ideally, we'd just write this code
// in lib.rs, but we must pass a string literal (and not `concat!(..)`) as an arg to `runtime_metadata_path`,
@@ -59,13 +58,6 @@ async fn run() {
derive_for_all_types = "Eq, PartialEq",
)]
pub mod node_runtime {{}}
/// Generated types for the locally running Substrate node using the unstable metadata.
#[subxt::subxt(
runtime_metadata_path = "{unstable_metadata_path}",
derive_for_all_types = "Eq, PartialEq",
)]
pub mod node_runtime_unstable {{}}
"#
);
let runtime_path = Path::new(&out_dir).join("runtime.rs");
@@ -88,43 +80,49 @@ async fn run() {
// Download metadata from binary. Avoid Subxt dep on `subxt::rpc::types::Bytes`and just impl here.
// This may at least prevent this script from running so often (ie whenever we change Subxt).
// If there's an error, we return a string for it.
async fn download_and_save_metadata(
version: u32,
port: u16,
out_dir: &str,
suffix: &str,
) -> String {
// Download it:
) -> Result<String, String> {
// Encode version
let bytes = version.encode();
let version: String = format!("0x{}", hex::encode(&bytes));
// Connect to the client and request metadata
let raw: String = {
use client::ClientT;
client::build(&format!("ws://localhost:{port}"))
.await
.unwrap_or_else(|e| panic!("Failed to connect to node: {e}"))
.map_err(|e| format!("Failed to connect to node: {e}"))?
.request(
"state_call",
client::rpc_params!["Metadata_metadata_at_version", &version],
)
.await
.unwrap_or_else(|e| panic!("Failed to obtain metadata from node: {e}"))
.map_err(|e| format!("Failed to obtain metadata from node: {e}"))?
};
let raw_bytes = hex::decode(raw.trim_start_matches("0x"))
.unwrap_or_else(|e| panic!("Failed to hex-decode metadata: {e}"));
let bytes: Option<Vec<u8>> = Decode::decode(&mut &raw_bytes[..])
.unwrap_or_else(|e| panic!("Failed to decode metadata bytes: {e}"));
let metadata_bytes = bytes.expect("Metadata version not found");
// Save it to a file:
// Decode the raw metadata
let raw_bytes = hex::decode(raw.trim_start_matches("0x"))
.map_err(|e| format!("Failed to hex-decode metadata: {e}"))?;
let bytes: Option<Vec<u8>> = Decode::decode(&mut &raw_bytes[..])
.map_err(|e| format!("Failed to decode metadata bytes: {e}"))?;
let metadata_bytes = bytes.ok_or_else(|| "Metadata version not found".to_string())?;
// Save metadata to a file
let metadata_path =
Path::new(&out_dir).join(format!("test_node_runtime_metadata_{suffix}.scale"));
fs::write(&metadata_path, metadata_bytes).expect("Couldn't write metadata output");
fs::write(&metadata_path, metadata_bytes)
.map_err(|e| format!("Couldn't write metadata output: {e}"))?;
// Convert path to string because we need this to interpolate into string
// Convert path to string and return
metadata_path
.to_str()
.expect("Path to metadata should be stringifiable")
.to_owned()
.ok_or_else(|| "Path to metadata should be stringifiable".to_string())
.map(|s| s.to_owned())
}
// Use jsonrpsee to obtain metadata from the node.
+28 -30
View File
@@ -90,23 +90,23 @@ async fn fetch_metadata_http(url: Url, version: MetadataVersion) -> Result<Vec<u
async fn fetch_metadata(client: impl ClientT, version: MetadataVersion) -> Result<Vec<u8>, Error> {
const UNSTABLE_METADATA_VERSION: u32 = u32::MAX;
// Fetch available metadata versions. If error, revert to legacy metadata code.
async fn fetch_available_versions(
client: &impl ClientT,
) -> Result<Vec<u32>, Error> {
let res: String = client
.request("state_call", rpc_params!["Metadata_metadata_versions", "0x"])
.await?;
let raw_bytes = hex::decode(res.trim_start_matches("0x"))?;
Decode::decode(&mut &raw_bytes[..]).map_err(Into::into)
}
// Fetch metadata using the "new" state_call interface
async fn fetch_inner(
client: &impl ClientT,
version: MetadataVersion,
supported_versions: Vec<u32>,
) -> Result<Vec<u8>, Error> {
// Look up supported versions:
let supported_versions: Vec<u32> = {
let res: String = client
.request(
"state_call",
rpc_params!["Metadata_metadata_versions", "0x"],
)
.await?;
let raw_bytes = hex::decode(res.trim_start_matches("0x"))?;
Decode::decode(&mut &raw_bytes[..])?
};
// Return the version the user wants if it's supported:
let version = match version {
MetadataVersion::Latest => *supported_versions
@@ -128,7 +128,7 @@ async fn fetch_metadata(client: impl ClientT, version: MetadataVersion) -> Resul
version
} else {
return Err(Error::Other(format!(
"The node does not have version {version} available"
"The node does not have metadata version {version} available"
)));
}
}
@@ -150,7 +150,7 @@ async fn fetch_metadata(client: impl ClientT, version: MetadataVersion) -> Resul
Decode::decode(&mut &metadata_bytes[..])?;
let Some(metadata) = metadata else {
return Err(Error::Other(format!(
"The node does not have version {version} available"
"The node does not have metadata version {version} available"
)));
};
Ok(metadata.0)
@@ -159,19 +159,7 @@ async fn fetch_metadata(client: impl ClientT, version: MetadataVersion) -> Resul
// Fetch metadata using the "old" state_call interface
async fn fetch_inner_legacy(
client: &impl ClientT,
version: MetadataVersion,
) -> Result<Vec<u8>, Error> {
// If the user specifically asks for anything other than version 14 or "latest", error.
if !matches!(
version,
MetadataVersion::Latest | MetadataVersion::Version(14)
) {
return Err(Error::Other(
"The node can only return version 14 metadata using the legacy API but you've asked for something else"
.to_string(),
));
}
// Fetch the metadata.
let metadata_string: String = client
.request("state_call", rpc_params!["Metadata_metadata", "0x"])
@@ -183,9 +171,19 @@ async fn fetch_metadata(client: impl ClientT, version: MetadataVersion) -> Resul
Ok(metadata.0)
}
// Fetch using the new interface, falling back to trying old one if there's an error.
match fetch_inner(&client, version).await {
Ok(s) => Ok(s),
Err(_) => fetch_inner_legacy(&client, version).await,
match fetch_available_versions(&client).await {
Ok(supported_versions) => {
fetch_inner(&client, version, supported_versions).await
},
Err(e) => {
// The "new" interface failed. if the user is asking for V14 or the "latest"
// metadata then try the legacy interface instead. Else, just return the
// reason for failure.
if matches!(version, MetadataVersion::Version(14) | MetadataVersion::Latest) {
fetch_inner_legacy(&client).await
} else {
Err(e)
}
}
}
}
+13 -12
View File
@@ -100,7 +100,7 @@ impl StripMetadata for v16::RuntimeMetadataV16 {
error: None,
view_functions: vec![],
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
};
}
}
@@ -780,26 +780,26 @@ mod test {
ty: frame_metadata::v16::StorageEntryType::Plain(meta_type::<A>()),
default: vec![],
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
}],
}),
event: Some(v16::PalletEventMetadata {
ty: meta_type::<B>(),
deprecation_info: v16::DeprecationInfo::NotDeprecated,
deprecation_info: v16::EnumDeprecationInfo::nothing_deprecated(),
}),
constants: vec![],
associated_types: vec![],
view_functions: vec![],
error: None,
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
},
v16::PalletMetadata {
name: "Second",
index: 1,
calls: Some(v16::PalletCallMetadata {
ty: meta_type::<C>(),
deprecation_info: v16::DeprecationInfo::NotDeprecated,
deprecation_info: v16::EnumDeprecationInfo::nothing_deprecated(),
}),
storage: None,
event: None,
@@ -808,7 +808,7 @@ mod test {
ty: meta_type::<D>(),
value: vec![],
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
}],
associated_types: vec![v16::PalletAssociatedTypeMetadata {
name: "Hasher",
@@ -824,15 +824,16 @@ mod test {
}],
output: meta_type::<G>(),
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
}],
error: None,
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
},
];
let extrinsic = v16::ExtrinsicMetadata {
call_ty: meta_type::<N>(), // same as outer_enums.call_enum_ty
versions: vec![0],
transaction_extensions_by_version: BTreeMap::new(),
transaction_extensions: vec![],
@@ -845,7 +846,7 @@ mod test {
name: "SomeApi",
version: Compact(2),
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
methods: vec![v16::RuntimeApiMethodMetadata {
name: "some_method",
inputs: vec![v16::FunctionParamMetadata {
@@ -854,14 +855,14 @@ mod test {
}],
output: meta_type::<K>(),
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
}],
},
v16::RuntimeApiMetadata {
name: "AnotherApi",
version: Compact(1),
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
methods: vec![v16::RuntimeApiMethodMetadata {
name: "another_method",
inputs: vec![v16::FunctionParamMetadata {
@@ -870,7 +871,7 @@ mod test {
}],
output: meta_type::<M>(),
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
deprecation_info: v16::ItemDeprecationInfo::NotDeprecated,
}],
},
];