From 8e98f43b892d6587546bf3cbc17563e0071d4571 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 26 Sep 2024 14:07:23 -0400 Subject: [PATCH 01/45] fix typo --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 85388fd6c..44f69dd22 100644 --- a/build.rs +++ b/build.rs @@ -50,7 +50,7 @@ fn main() { let loc = error.span().start(); let file_path = relative_path.display(); // note that spans can't go across thread boundaries without losing their location - // info so we we serialize here and send a String + // info so we serialize here and send a String tx.send(format!( "cargo:warning={}:{}:{}: {}", file_path, loc.line, loc.column, error, From a4ed75aa3a10c07a32970bfa42be3c49f3611fa3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sat, 28 Sep 2024 02:30:38 -0400 Subject: [PATCH 02/45] code coverage WIP --- Cargo.lock | 14 ++++++++++++++ Cargo.toml | 2 +- support/code-coverage/Cargo.toml | 11 +++++++++++ support/code-coverage/src/lib.rs | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 support/code-coverage/Cargo.toml create mode 100644 support/code-coverage/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b1536c2b5..68a4af195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -926,6 +926,12 @@ dependencies = [ "semver 0.6.0", ] +[[package]] +name = "build-print" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a2128d00b7061b82b72844a351e80acd29e05afc60e9261e2ac90dca9ecc2ac" + [[package]] name = "bumpalo" version = "3.16.0" @@ -9873,6 +9879,14 @@ dependencies = [ "walkdir", ] +[[package]] +name = "subtensor-code-coverage" +version = "0.1.0" +dependencies = [ + "build-print", + "syn 2.0.77", +] + [[package]] name = "subtensor-custom-rpc" version = "0.0.2" diff --git a/Cargo.toml b/Cargo.toml index e2af5f69f..fac14aef1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ members = [ "support/tools", "support/macros", "support/linting", - "support/procedural-fork", + "support/procedural-fork", "support/code-coverage", ] exclude = ["support/procedural-fork"] resolver = "2" diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml new file mode 100644 index 000000000..36db87bf5 --- /dev/null +++ b/support/code-coverage/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "subtensor-code-coverage" +version = "0.1.0" +edition = "2021" + +[dependencies] +build-print = "0.1" +syn.workspace = true + +[lints] +workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs new file mode 100644 index 000000000..b93cf3ffd --- /dev/null +++ b/support/code-coverage/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} From b63f4c422ce99a6a79faa717795779174eea9d82 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 30 Sep 2024 01:00:31 -0400 Subject: [PATCH 03/45] coverage metadata scaffold --- Cargo.lock | 1 + support/code-coverage/Cargo.toml | 1 + support/code-coverage/src/lib.rs | 24 +++++++++++++----------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68a4af195..bd2366754 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9884,6 +9884,7 @@ name = "subtensor-code-coverage" version = "0.1.0" dependencies = [ "build-print", + "proc-macro2", "syn 2.0.77", ] diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index 36db87bf5..c30f796c9 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] build-print = "0.1" syn.workspace = true +proc-macro2.workspace = true [lints] workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index b93cf3ffd..4b1cadedc 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,14 +1,16 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} +use std::{ + collections::HashMap, + path::{Path, PathBuf}, +}; -#[cfg(test)] -mod tests { - use super::*; +use syn::File; - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } +pub struct PalletCoverageInfo { + pub pallet_name: String, + pub path: PathBuf, + pub extrinsics: HashMap, + pub events: HashMap, + pub hooks: HashMap, + pub calls: HashMap, + pub storage: HashMap, } From 377bc6677ff0bf533fa3352b152e8dcf3b265d66 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 30 Sep 2024 01:08:45 -0400 Subject: [PATCH 04/45] set up deps --- Cargo.lock | 2 +- Cargo.toml | 2 ++ support/code-coverage/Cargo.toml | 2 +- support/code-coverage/src/lib.rs | 10 ++++++---- support/linting/Cargo.toml | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd2366754..574faba97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9884,7 +9884,7 @@ name = "subtensor-code-coverage" version = "0.1.0" dependencies = [ "build-print", - "proc-macro2", + "procedural-fork", "syn 2.0.77", ] diff --git a/Cargo.toml b/Cargo.toml index fac14aef1..d03efadab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,6 +157,8 @@ substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1" } frame-metadata = "16" +procedural-fork = { version = "1.10.0-rc3", path = "support/procedural-fork" } + [profile.release] panic = "unwind" diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index c30f796c9..e20864586 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] build-print = "0.1" syn.workspace = true -proc-macro2.workspace = true +procedural-fork.workspace = true [lints] workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 4b1cadedc..3d6dc5e74 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -5,12 +5,14 @@ use std::{ use syn::File; +#[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { pub pallet_name: String, pub path: PathBuf, pub extrinsics: HashMap, - pub events: HashMap, - pub hooks: HashMap, - pub calls: HashMap, - pub storage: HashMap, +} + +pub fn analyze_pallet(file: &File) -> PalletCoverageInfo { + let mut pallet_coverage_info = PalletCoverageInfo::default(); + todo!() } diff --git a/support/linting/Cargo.toml b/support/linting/Cargo.toml index 4378ca9dd..64ce7071b 100644 --- a/support/linting/Cargo.toml +++ b/support/linting/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" syn.workspace = true quote.workspace = true proc-macro2.workspace = true -procedural-fork = { version = "1.10.0-rc3", path = "../procedural-fork" } +procedural-fork.workspace = true [lints] workspace = true From dda202a1e6412975087ac2ab1846657f1c5e0b8e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 30 Sep 2024 01:47:09 -0400 Subject: [PATCH 05/45] basic parsing --- Cargo.lock | 2 ++ support/code-coverage/Cargo.toml | 2 ++ support/code-coverage/src/lib.rs | 35 +++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 574faba97..e41f3538a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9884,7 +9884,9 @@ name = "subtensor-code-coverage" version = "0.1.0" dependencies = [ "build-print", + "proc-macro2", "procedural-fork", + "quote", "syn 2.0.77", ] diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index e20864586..c81294820 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [dependencies] build-print = "0.1" syn.workspace = true +quote.workspace = true +proc-macro2.workspace = true procedural-fork.workspace = true [lints] diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 3d6dc5e74..655179372 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,18 +1,43 @@ +use proc_macro2::TokenStream as TokenStream2; +use procedural_fork::exports::pallet::parse::Def; +use quote::ToTokens; use std::{ collections::HashMap, + fs, path::{Path, PathBuf}, + str::FromStr, }; - -use syn::File; +use syn::{parse2, spanned::Spanned, File, Item}; #[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { - pub pallet_name: String, pub path: PathBuf, pub extrinsics: HashMap, } -pub fn analyze_pallet(file: &File) -> PalletCoverageInfo { - let mut pallet_coverage_info = PalletCoverageInfo::default(); +pub fn analyze_file(path: &Path) -> Vec { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(parsed_tokens) = TokenStream2::from_str(&content) else { + return Vec::new(); + }; + let Ok(file) = syn::parse2::(parsed_tokens) else { + return Vec::new(); + }; + // TODO: use a visitor here instead + for item in &file.items { + let Item::Mod(item_mod) = item else { continue }; + let pallet: Def = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + pallet + } else { + let Ok(pallet) = Def::try_from(item_mod.clone(), true) else { + continue; + }; + pallet + }; + let mut info = PalletCoverageInfo::default(); + info.path = path.to_path_buf(); + } todo!() } From d612fb9eb4b12b05f4be4e97493ae5d7d889d7dc Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 10:46:59 -0400 Subject: [PATCH 06/45] pallet visitor --- support/code-coverage/src/lib.rs | 38 +++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 655179372..cfdc5e458 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -7,7 +7,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, }; -use syn::{parse2, spanned::Spanned, File, Item}; +use syn::{parse2, spanned::Spanned, visit::Visit, File, Item, ItemMod, ItemStruct}; #[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { @@ -15,6 +15,18 @@ pub struct PalletCoverageInfo { pub extrinsics: HashMap, } +pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { + let pallet: Def = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + pallet + } else { + let Ok(pallet) = Def::try_from(item_mod.clone(), true) else { + return None; + }; + pallet + }; + Some(pallet) +} + pub fn analyze_file(path: &Path) -> Vec { let Ok(content) = fs::read_to_string(path) else { return Vec::new(); @@ -28,16 +40,26 @@ pub fn analyze_file(path: &Path) -> Vec { // TODO: use a visitor here instead for item in &file.items { let Item::Mod(item_mod) = item else { continue }; - let pallet: Def = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { - pallet - } else { - let Ok(pallet) = Def::try_from(item_mod.clone(), true) else { - continue; - }; - pallet + let Some(pallet) = try_parse_pallet(&item_mod) else { + continue; }; let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); } todo!() } + +#[derive(Default)] +pub struct PalletVisitor { + pub pallets: Vec<(ItemMod, Def)>, +} + +impl<'ast> Visit<'ast> for PalletVisitor { + fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { + let Some(pallet) = try_parse_pallet(item_mod) else { + syn::visit::visit_item_mod(self, item_mod); + return; + }; + self.pallets.push((item_mod.clone(), pallet)); + } +} From 1c9acbf36812ef5c19595d7ccd9289b08403b6be Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 10:53:36 -0400 Subject: [PATCH 07/45] PalletVisitor :boom: --- support/code-coverage/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index cfdc5e458..9ea33f4c0 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -54,6 +54,19 @@ pub struct PalletVisitor { pub pallets: Vec<(ItemMod, Def)>, } +impl PalletVisitor { + pub fn for_each_pallet(file: &File, mut f: F) + where + F: FnMut(&ItemMod, &Def), + { + let mut visitor = PalletVisitor::default(); + visitor.visit_file(file); + for (item_mod, pallet) in visitor.pallets { + f(&item_mod, &pallet); + } + } +} + impl<'ast> Visit<'ast> for PalletVisitor { fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { let Some(pallet) = try_parse_pallet(item_mod) else { From 3600b67831c1a2f92e52aadf6f3c6c4f13054858 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 10:56:57 -0400 Subject: [PATCH 08/45] tweak mutability --- support/code-coverage/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 9ea33f4c0..d715d5240 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -55,15 +55,16 @@ pub struct PalletVisitor { } impl PalletVisitor { - pub fn for_each_pallet(file: &File, mut f: F) + pub fn for_each_pallet(file: &File, mut f: F) -> Self where F: FnMut(&ItemMod, &Def), { let mut visitor = PalletVisitor::default(); visitor.visit_file(file); - for (item_mod, pallet) in visitor.pallets { - f(&item_mod, &pallet); + for (item_mod, pallet) in &visitor.pallets { + f(item_mod, pallet); } + visitor } } From 898cce8bd8b50a2ad050c4771b5ad968d9a025a8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 13:38:38 -0400 Subject: [PATCH 09/45] almost --- build.rs | 1 - support/code-coverage/src/lib.rs | 16 ++++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index 44f69dd22..7b87fe217 100644 --- a/build.rs +++ b/build.rs @@ -14,7 +14,6 @@ fn main() { println!("cargo:rerun-if-changed=pallets"); println!("cargo:rerun-if-changed=node"); println!("cargo:rerun-if-changed=runtime"); - println!("cargo:rerun-if-changed=lints"); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src"); println!("cargo:rerun-if-changed=support"); diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index d715d5240..4007048e5 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,13 +1,12 @@ use proc_macro2::TokenStream as TokenStream2; use procedural_fork::exports::pallet::parse::Def; -use quote::ToTokens; use std::{ collections::HashMap, fs, path::{Path, PathBuf}, str::FromStr, }; -use syn::{parse2, spanned::Spanned, visit::Visit, File, Item, ItemMod, ItemStruct}; +use syn::{visit::Visit, File, ItemMod}; #[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { @@ -37,16 +36,13 @@ pub fn analyze_file(path: &Path) -> Vec { let Ok(file) = syn::parse2::(parsed_tokens) else { return Vec::new(); }; - // TODO: use a visitor here instead - for item in &file.items { - let Item::Mod(item_mod) = item else { continue }; - let Some(pallet) = try_parse_pallet(&item_mod) else { - continue; - }; + let mut infos = Vec::new(); + PalletVisitor::for_each_pallet(&file, |item_mod, pallet: &Def| { let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); - } - todo!() + infos.push(info); + }); + infos } #[derive(Default)] From b0c6806429034279b51012987f619e1ac1296eba Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 15:49:22 -0400 Subject: [PATCH 10/45] procedural-fork tests properly ignored --- Cargo.lock | 10 ++++++ Cargo.toml | 8 +++-- build.rs | 9 +++++ examples/basic/Cargo.toml | 11 ++++++ examples/basic/src/lib.rs | 4 +++ support/code-coverage/Cargo.toml | 2 +- support/code-coverage/src/lib.rs | 36 +++++++++++-------- support/procedural-fork/Cargo.toml | 1 + support/procedural-fork/src/lib.rs | 29 +++------------ .../procedural-fork/src/pallet/parse/mod.rs | 1 - 10 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 examples/basic/Cargo.toml create mode 100644 examples/basic/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e41f3538a..8e231ae32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -746,6 +746,14 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "basic" +version = "0.1.0" +dependencies = [ + "frame-support", + "frame-system", +] + [[package]] name = "bincode" version = "1.3.3" @@ -9869,11 +9877,13 @@ dependencies = [ name = "subtensor" version = "0.1.0" dependencies = [ + "build-print", "node-subtensor", "node-subtensor-runtime", "proc-macro2", "quote", "rayon", + "subtensor-code-coverage", "subtensor-linting", "syn 2.0.77", "walkdir", diff --git a/Cargo.toml b/Cargo.toml index d03efadab..d2dca3689 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,8 @@ node-subtensor-runtime = { path = "runtime", version = "4.0.0-dev" } [build-dependencies] subtensor-linting = { path = "support/linting", version = "0.1.0" } +subtensor-code-coverage = { path = "support/code-coverage", version = "0.1.0" } +build-print.workspace = true syn.workspace = true quote.workspace = true proc-macro2.workspace = true @@ -33,9 +35,10 @@ members = [ "support/tools", "support/macros", "support/linting", - "support/procedural-fork", "support/code-coverage", + "support/procedural-fork", + "support/code-coverage", + "examples/basic", ] -exclude = ["support/procedural-fork"] resolver = "2" [workspace.lints.clippy] @@ -46,6 +49,7 @@ unwrap-used = "deny" manual_inspect = "allow" [workspace.dependencies] +build-print = "0.1" cargo-husky = { version = "1", default-features = false } clap = "4.5.4" codec = { version = "3.2.2", default-features = false } diff --git a/build.rs b/build.rs index 7b87fe217..ef2f90136 100644 --- a/build.rs +++ b/build.rs @@ -5,6 +5,7 @@ use std::{ str::FromStr, sync::mpsc::channel, }; +use subtensor_code_coverage::analyze_file; use walkdir::WalkDir; use subtensor_linting::*; @@ -24,6 +25,14 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); + rust_files.par_iter().for_each(|path| { + let infos = analyze_file(path); + //build_print::info!("File: {}", path.display()); + for info in infos { + build_print::info!("pallet: {}", info.path.display()); + } + }); + // Channel used to communicate errors back to the main thread from the parallel processing // as we process each Rust file let (tx, rx) = channel(); diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml new file mode 100644 index 000000000..80d319aeb --- /dev/null +++ b/examples/basic/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "basic" +version = "0.1.0" +edition = "2021" + +[dependencies] +frame-system.workspace = true +frame-support.workspace = true + +[lints] +workspace = true diff --git a/examples/basic/src/lib.rs b/examples/basic/src/lib.rs new file mode 100644 index 000000000..c552109be --- /dev/null +++ b/examples/basic/src/lib.rs @@ -0,0 +1,4 @@ +#![doc(hidden)] + +// this crate is simply a stub to get the `procedural-fork` tests to pass since they expect a +// valid `Cargo.toml` at this path with `frame-system` and `frame-support` as dependencies. diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index c81294820..2df598866 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -build-print = "0.1" +build-print.workspace = true syn.workspace = true quote.workspace = true proc-macro2.workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 4007048e5..c972f3814 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,10 +1,11 @@ use proc_macro2::TokenStream as TokenStream2; -use procedural_fork::exports::pallet::parse::Def; +use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use std::{ collections::HashMap, - fs, + fs, panic, path::{Path, PathBuf}, str::FromStr, + sync::Mutex, }; use syn::{visit::Visit, File, ItemMod}; @@ -15,15 +16,21 @@ pub struct PalletCoverageInfo { } pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { - let pallet: Def = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { - pallet - } else { - let Ok(pallet) = Def::try_from(item_mod.clone(), true) else { - return None; - }; - pallet + if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + return Some(pallet); + } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { + return Some(pallet); + } + let err = match Def::try_from(item_mod.clone(), false) { + Err(err) => err, + _ => unreachable!(), }; - Some(pallet) + build_print::warn!( + "A: pallet: {}, {}", + item_mod.ident.to_string(), + err.to_string() + ); + None } pub fn analyze_file(path: &Path) -> Vec { @@ -66,10 +73,9 @@ impl PalletVisitor { impl<'ast> Visit<'ast> for PalletVisitor { fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { - let Some(pallet) = try_parse_pallet(item_mod) else { - syn::visit::visit_item_mod(self, item_mod); - return; - }; - self.pallets.push((item_mod.clone(), pallet)); + if let Some(pallet) = try_parse_pallet(item_mod) { + self.pallets.push((item_mod.clone(), pallet)); + } + syn::visit::visit_item_mod(self, item_mod); } } diff --git a/support/procedural-fork/Cargo.toml b/support/procedural-fork/Cargo.toml index 503c81f1f..e434378bf 100644 --- a/support/procedural-fork/Cargo.toml +++ b/support/procedural-fork/Cargo.toml @@ -19,6 +19,7 @@ frame-support-procedural-tools = { version = "10.0.0" } proc-macro-warning = { version = "1", default-features = false } expander = "2" sp-crypto-hashing = { default-features = false, version = "0.1.0" } +regex = "1" [dev-dependencies] regex = "1" diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs index c7f1472b2..21f63daf5 100644 --- a/support/procedural-fork/src/lib.rs +++ b/support/procedural-fork/src/lib.rs @@ -12,63 +12,45 @@ #![recursion_limit = "512"] #![allow(warnings)] #![allow(clippy::all)] +#![ignore] // ensure procedural-fork tests are not run +#![cfg(not(doc))] // ensure procedural-fork doc tests are not run extern crate proc_macro; -#[cfg(not(test))] mod benchmark; -#[cfg(not(test))] mod construct_runtime; -#[cfg(not(test))] mod crate_version; -#[cfg(not(test))] mod derive_impl; -#[cfg(not(test))] mod dummy_part_checker; -#[cfg(not(test))] mod dynamic_params; -#[cfg(not(test))] mod key_prefix; -#[cfg(not(test))] mod match_and_insert; -#[cfg(not(test))] mod no_bound; -#[cfg(not(test))] mod pallet; -#[cfg(not(test))] mod pallet_error; -#[cfg(not(test))] mod runtime; -#[cfg(not(test))] mod storage_alias; -#[cfg(not(test))] mod transactional; -#[cfg(not(test))] mod tt_macro; -#[cfg(not(test))] + use std::{cell::RefCell, str::FromStr}; -#[cfg(not(test))] pub(crate) const INHERENT_INSTANCE_NAME: &str = "__InherentHiddenInstance"; /// The number of module instances supported by the runtime, starting at index 1, /// and up to `NUMBER_OF_INSTANCE`. -#[cfg(not(test))] pub(crate) const NUMBER_OF_INSTANCE: u8 = 16; thread_local! { /// A global counter, can be used to generate a relatively unique identifier. - #[cfg(not(test))] static COUNTER: RefCell = const { RefCell::new(Counter(0)) }; } /// Counter to generate a relatively unique identifier for macros. This is necessary because /// declarative macros gets hoisted to the crate root, which shares the namespace with other pallets /// containing the very same macros. -#[cfg(not(test))] struct Counter(u64); -#[cfg(not(test))] impl Counter { fn inc(&mut self) -> u64 { let ret = self.0; @@ -80,7 +62,6 @@ impl Counter { /// Get the value from the given environment variable set by cargo. /// /// The value is parsed into the requested destination type. -#[cfg(not(test))] fn get_cargo_env_var(version_env: &str) -> std::result::Result { let version = std::env::var(version_env) .unwrap_or_else(|_| panic!("`{}` is always set by cargo; qed", version_env)); @@ -90,12 +71,12 @@ fn get_cargo_env_var(version_env: &str) -> std::result::Result String { format!("CounterFor{}", prefix) } -#[cfg(not(test))] +pub use crate::pallet::parse::tests::simulate_manifest_dir; + pub mod exports { pub mod benchmark { pub use crate::benchmark::*; diff --git a/support/procedural-fork/src/pallet/parse/mod.rs b/support/procedural-fork/src/pallet/parse/mod.rs index 57c252473..573feda57 100644 --- a/support/procedural-fork/src/pallet/parse/mod.rs +++ b/support/procedural-fork/src/pallet/parse/mod.rs @@ -37,7 +37,6 @@ pub mod tasks; pub mod type_value; pub mod validate_unsigned; -#[cfg(test)] pub mod tests; use composite::{keyword::CompositeKeyword, CompositeDef}; From 2706ac245bcf519f6f4edd6439b2a0b91ecc86f6 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:01:21 -0400 Subject: [PATCH 11/45] revert --- Cargo.lock | 8 -------- Cargo.toml | 1 - examples/basic/Cargo.toml | 11 ----------- examples/basic/src/lib.rs | 4 ---- 4 files changed, 24 deletions(-) delete mode 100644 examples/basic/Cargo.toml delete mode 100644 examples/basic/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 8e231ae32..d3e27f8d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -746,14 +746,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "basic" -version = "0.1.0" -dependencies = [ - "frame-support", - "frame-system", -] - [[package]] name = "bincode" version = "1.3.3" diff --git a/Cargo.toml b/Cargo.toml index d2dca3689..abf4671f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ members = [ "support/linting", "support/procedural-fork", "support/code-coverage", - "examples/basic", ] resolver = "2" diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml deleted file mode 100644 index 80d319aeb..000000000 --- a/examples/basic/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "basic" -version = "0.1.0" -edition = "2021" - -[dependencies] -frame-system.workspace = true -frame-support.workspace = true - -[lints] -workspace = true diff --git a/examples/basic/src/lib.rs b/examples/basic/src/lib.rs deleted file mode 100644 index c552109be..000000000 --- a/examples/basic/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![doc(hidden)] - -// this crate is simply a stub to get the `procedural-fork` tests to pass since they expect a -// valid `Cargo.toml` at this path with `frame-system` and `frame-support` as dependencies. From bbc7855b6902bf172b1e569fac8a7809e05845df Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:02:02 -0400 Subject: [PATCH 12/45] modify update.sh to append proper ignores to each file --- support/procedural-fork/src/lib.rs | 1 - support/procedural-fork/update.sh | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs index 21f63daf5..a5d12cdf9 100644 --- a/support/procedural-fork/src/lib.rs +++ b/support/procedural-fork/src/lib.rs @@ -13,7 +13,6 @@ #![allow(warnings)] #![allow(clippy::all)] #![ignore] // ensure procedural-fork tests are not run -#![cfg(not(doc))] // ensure procedural-fork doc tests are not run extern crate proc_macro; diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index a8793b261..ba7be7f83 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -36,11 +36,21 @@ git sparse-checkout set "$SRC_DIR" echo "Contents of $TMP_DIR/$SRC_DIR after sparse-checkout:" ls -l "$TMP_DIR/$SRC_DIR" || { echo "Error: Sparse checkout failed, $SRC_DIR not found."; rm -rf "$TMP_DIR"; exit 1; } -# Copy all files from `src` except `lib.rs` to the destination folder +# Copy all files from `src` except `$DEST_DIR/lib.rs` to the destination folder echo "Copying files to $DEST_DIR ..." rsync -a --exclude='lib.rs' "$TMP_DIR/$SRC_DIR/" "$DEST_DIR/" +# Add the desired lines to the top of each Rust file, except the `lib.rs` in $DEST_DIR +for file in "$DEST_DIR"/*.rs; do + if [ -f "$file" ] && [ "$(realpath "$file")" != "$(realpath "$DEST_DIR/lib.rs")" ]; then + echo "Prepending configuration to $file ..." + # Use sed to prepend the lines to each file + sed -i '1i\ +#![ignore]\n#![cfg(not(doc))]\n' "$file" + fi +done + # Clean up the temporary directory rm -rf "$TMP_DIR" -echo "Update completed successfully." +echo "Update completed successfully with modifications." From f16fc186ce2e3ebeb5397c4176cd52727e9aaac8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:06:18 -0400 Subject: [PATCH 13/45] detection of platform-specific sed behavior --- support/procedural-fork/update.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index ba7be7f83..db1e63420 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -41,13 +41,10 @@ echo "Copying files to $DEST_DIR ..." rsync -a --exclude='lib.rs' "$TMP_DIR/$SRC_DIR/" "$DEST_DIR/" # Add the desired lines to the top of each Rust file, except the `lib.rs` in $DEST_DIR -for file in "$DEST_DIR"/*.rs; do - if [ -f "$file" ] && [ "$(realpath "$file")" != "$(realpath "$DEST_DIR/lib.rs")" ]; then - echo "Prepending configuration to $file ..." - # Use sed to prepend the lines to each file - sed -i '1i\ -#![ignore]\n#![cfg(not(doc))]\n' "$file" - fi +find "$DEST_DIR" -name '*.rs' -not -path "$DEST_DIR/lib.rs" | while read -r file; do + echo "Prepending configuration to $file ..." + # Use awk to prepend the lines to each file + awk 'BEGIN {print "#![ignore]\n#![cfg(not(doc))]"} {print}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" done # Clean up the temporary directory From d4341811f24ab71541355e970303bece27f00263 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:20:20 -0400 Subject: [PATCH 14/45] in script: remove all `#[cfg(test)]` lines from `pallet/parse/mod.rs` --- support/procedural-fork/update.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index db1e63420..d3b67e3e7 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -13,6 +13,7 @@ TMP_DIR=$(mktemp -d) # Define source and destination directories SRC_DIR="substrate/frame/support/procedural/src" DEST_DIR="$(pwd)/src" # Absolute path to `src` directory of procedural-fork +PARENT_DIR="$(dirname "$DEST_DIR")" # Get the parent directory of DEST_DIR # Check if DEST_DIR exists if [ ! -d "$DEST_DIR" ]; then @@ -47,7 +48,18 @@ find "$DEST_DIR" -name '*.rs' -not -path "$DEST_DIR/lib.rs" | while read -r file awk 'BEGIN {print "#![ignore]\n#![cfg(not(doc))]"} {print}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" done +# Remove all `#[cfg(test)]` lines from `pallet/parse/mod.rs` +MOD_RS="$DEST_DIR/pallet/parse/mod.rs" +if [ -f "$MOD_RS" ]; then + echo "Removing #[cfg(test)] from $MOD_RS ..." + grep -v '#\[cfg(test)\]' "$MOD_RS" > "$MOD_RS.tmp" && mv "$MOD_RS.tmp" "$MOD_RS" +fi + +# Change directory to the parent of $DEST_DIR to run cargo fmt +echo "Changing directory to $PARENT_DIR and running cargo fmt --all ..." +cd "$PARENT_DIR" && cargo fmt --all + # Clean up the temporary directory rm -rf "$TMP_DIR" -echo "Update completed successfully with modifications." +echo "Update and formatting completed successfully." From e329132ddd80996d1d2c2ae910c6789e9e3b095b Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:29:09 -0400 Subject: [PATCH 15/45] add update.sh section to add #[ignore] to all #[test] --- support/procedural-fork/update.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index d3b67e3e7..bd92ed559 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -55,6 +55,12 @@ if [ -f "$MOD_RS" ]; then grep -v '#\[cfg(test)\]' "$MOD_RS" > "$MOD_RS.tmp" && mv "$MOD_RS.tmp" "$MOD_RS" fi +# Replace all #[test] with #[test]\n#[ignore] using awk +echo "Replacing #[test] with #[test]\n#[ignore] ..." +find "$DEST_DIR" -name '*.rs' | while read -r file; do + awk '{if ($0 == "#[test]") print $0 "\n#[ignore]"; else print $0}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" +done + # Change directory to the parent of $DEST_DIR to run cargo fmt echo "Changing directory to $PARENT_DIR and running cargo fmt --all ..." cd "$PARENT_DIR" && cargo fmt --all From 845cde8df659f2f95cfbbc9126cc8e136a77055f Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:36:01 -0400 Subject: [PATCH 16/45] don't prepend `#[ignore]` to top of each file --- support/procedural-fork/update.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index bd92ed559..cdd537616 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -41,11 +41,11 @@ ls -l "$TMP_DIR/$SRC_DIR" || { echo "Error: Sparse checkout failed, $SRC_DIR not echo "Copying files to $DEST_DIR ..." rsync -a --exclude='lib.rs' "$TMP_DIR/$SRC_DIR/" "$DEST_DIR/" -# Add the desired lines to the top of each Rust file, except the `lib.rs` in $DEST_DIR +# Prepend only `#![cfg(not(doc))]` to the top of each Rust file, except the `lib.rs` in $DEST_DIR find "$DEST_DIR" -name '*.rs' -not -path "$DEST_DIR/lib.rs" | while read -r file; do echo "Prepending configuration to $file ..." - # Use awk to prepend the lines to each file - awk 'BEGIN {print "#![ignore]\n#![cfg(not(doc))]"} {print}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" + # Use awk to prepend only `#![cfg(not(doc))]` + awk 'BEGIN {print "#![cfg(not(doc))]"} {print}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" done # Remove all `#[cfg(test)]` lines from `pallet/parse/mod.rs` From 6b7588b9414def1469ba136ce46cc499a4498d19 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 16:43:48 -0400 Subject: [PATCH 17/45] fix --- support/code-coverage/src/lib.rs | 5 ++--- support/procedural-fork/src/benchmark.rs | 1 + .../src/construct_runtime/expand/call.rs | 1 + .../expand/composite_helper.rs | 1 + .../src/construct_runtime/expand/config.rs | 1 + .../construct_runtime/expand/freeze_reason.rs | 1 + .../construct_runtime/expand/hold_reason.rs | 1 + .../src/construct_runtime/expand/inherent.rs | 1 + .../src/construct_runtime/expand/lock_id.rs | 1 + .../src/construct_runtime/expand/metadata.rs | 1 + .../src/construct_runtime/expand/mod.rs | 1 + .../src/construct_runtime/expand/origin.rs | 1 + .../construct_runtime/expand/outer_enums.rs | 1 + .../construct_runtime/expand/slash_reason.rs | 1 + .../src/construct_runtime/expand/task.rs | 1 + .../src/construct_runtime/expand/unsigned.rs | 1 + .../src/construct_runtime/mod.rs | 1 + .../src/construct_runtime/parse.rs | 1 + support/procedural-fork/src/crate_version.rs | 1 + support/procedural-fork/src/derive_impl.rs | 4 ++++ .../procedural-fork/src/dummy_part_checker.rs | 1 + support/procedural-fork/src/dynamic_params.rs | 1 + support/procedural-fork/src/key_prefix.rs | 1 + support/procedural-fork/src/lib.rs | 5 +++-- .../procedural-fork/src/match_and_insert.rs | 1 + support/procedural-fork/src/no_bound/clone.rs | 1 + support/procedural-fork/src/no_bound/debug.rs | 1 + .../procedural-fork/src/no_bound/default.rs | 1 + support/procedural-fork/src/no_bound/mod.rs | 1 + support/procedural-fork/src/no_bound/ord.rs | 1 + .../src/no_bound/partial_eq.rs | 1 + .../src/no_bound/partial_ord.rs | 1 + .../procedural-fork/src/pallet/expand/call.rs | 1 + .../src/pallet/expand/composite.rs | 1 + .../src/pallet/expand/config.rs | 1 + .../src/pallet/expand/constants.rs | 1 + .../src/pallet/expand/doc_only.rs | 1 + .../src/pallet/expand/documentation.rs | 1 + .../src/pallet/expand/error.rs | 1 + .../src/pallet/expand/event.rs | 1 + .../src/pallet/expand/genesis_build.rs | 1 + .../src/pallet/expand/genesis_config.rs | 1 + .../src/pallet/expand/hooks.rs | 1 + .../src/pallet/expand/inherent.rs | 1 + .../src/pallet/expand/instances.rs | 1 + .../procedural-fork/src/pallet/expand/mod.rs | 1 + .../src/pallet/expand/origin.rs | 1 + .../src/pallet/expand/pallet_struct.rs | 1 + .../src/pallet/expand/storage.rs | 1 + .../src/pallet/expand/tasks.rs | 1 + .../src/pallet/expand/tt_default_parts.rs | 1 + .../src/pallet/expand/type_value.rs | 1 + .../src/pallet/expand/validate_unsigned.rs | 1 + .../src/pallet/expand/warnings.rs | 1 + support/procedural-fork/src/pallet/mod.rs | 1 + .../procedural-fork/src/pallet/parse/call.rs | 1 + .../src/pallet/parse/composite.rs | 1 + .../src/pallet/parse/config.rs | 1 + .../procedural-fork/src/pallet/parse/error.rs | 1 + .../procedural-fork/src/pallet/parse/event.rs | 1 + .../src/pallet/parse/extra_constants.rs | 1 + .../src/pallet/parse/genesis_build.rs | 1 + .../src/pallet/parse/genesis_config.rs | 1 + .../src/pallet/parse/helper.rs | 1 + .../procedural-fork/src/pallet/parse/hooks.rs | 1 + .../src/pallet/parse/inherent.rs | 1 + .../procedural-fork/src/pallet/parse/mod.rs | 1 + .../src/pallet/parse/origin.rs | 1 + .../src/pallet/parse/pallet_struct.rs | 1 + .../src/pallet/parse/storage.rs | 7 +++--- .../procedural-fork/src/pallet/parse/tasks.rs | 22 +++++++++++++++++++ .../src/pallet/parse/tests/mod.rs | 4 ++++ .../src/pallet/parse/tests/tasks.rs | 10 +++++++++ .../src/pallet/parse/type_value.rs | 1 + .../src/pallet/parse/validate_unsigned.rs | 1 + support/procedural-fork/src/pallet_error.rs | 1 + .../procedural-fork/src/runtime/expand/mod.rs | 1 + support/procedural-fork/src/runtime/mod.rs | 1 + .../src/runtime/parse/helper.rs | 1 + .../procedural-fork/src/runtime/parse/mod.rs | 21 +++++++++--------- .../src/runtime/parse/pallet.rs | 1 + .../src/runtime/parse/pallet_decl.rs | 1 + .../src/runtime/parse/runtime_struct.rs | 1 + .../src/runtime/parse/runtime_types.rs | 1 + support/procedural-fork/src/storage_alias.rs | 1 + support/procedural-fork/src/transactional.rs | 1 + support/procedural-fork/src/tt_macro.rs | 1 + support/procedural-fork/update.sh | 2 +- 88 files changed, 140 insertions(+), 19 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index c972f3814..d355c1da2 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,11 +1,10 @@ use proc_macro2::TokenStream as TokenStream2; -use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; +use procedural_fork::exports::{pallet::parse::Def, simulate_manifest_dir}; use std::{ collections::HashMap, - fs, panic, + fs, path::{Path, PathBuf}, str::FromStr, - sync::Mutex, }; use syn::{visit::Visit, File, ItemMod}; diff --git a/support/procedural-fork/src/benchmark.rs b/support/procedural-fork/src/benchmark.rs index 376200d6e..fd228c1c8 100644 --- a/support/procedural-fork/src/benchmark.rs +++ b/support/procedural-fork/src/benchmark.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/call.rs b/support/procedural-fork/src/construct_runtime/expand/call.rs index 7e8c2e856..74e6dcdd5 100644 --- a/support/procedural-fork/src/construct_runtime/expand/call.rs +++ b/support/procedural-fork/src/construct_runtime/expand/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs b/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs index be6b2f085..dea809ac7 100644 --- a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs +++ b/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/config.rs b/support/procedural-fork/src/construct_runtime/expand/config.rs index ff715e584..e70506779 100644 --- a/support/procedural-fork/src/construct_runtime/expand/config.rs +++ b/support/procedural-fork/src/construct_runtime/expand/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs b/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs index 131c919ef..797263433 100644 --- a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs b/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs index 58870a321..17ee803f9 100644 --- a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/inherent.rs b/support/procedural-fork/src/construct_runtime/expand/inherent.rs index b58d540fe..b679dac4c 100644 --- a/support/procedural-fork/src/construct_runtime/expand/inherent.rs +++ b/support/procedural-fork/src/construct_runtime/expand/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs b/support/procedural-fork/src/construct_runtime/expand/lock_id.rs index 67c2fb933..ac4bafd7e 100644 --- a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs +++ b/support/procedural-fork/src/construct_runtime/expand/lock_id.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/metadata.rs b/support/procedural-fork/src/construct_runtime/expand/metadata.rs index f98c719ca..4b58263a5 100644 --- a/support/procedural-fork/src/construct_runtime/expand/metadata.rs +++ b/support/procedural-fork/src/construct_runtime/expand/metadata.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/mod.rs b/support/procedural-fork/src/construct_runtime/expand/mod.rs index 88f9a3c6e..eff0cccc1 100644 --- a/support/procedural-fork/src/construct_runtime/expand/mod.rs +++ b/support/procedural-fork/src/construct_runtime/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/origin.rs b/support/procedural-fork/src/construct_runtime/expand/origin.rs index 2d50777bf..c55031049 100644 --- a/support/procedural-fork/src/construct_runtime/expand/origin.rs +++ b/support/procedural-fork/src/construct_runtime/expand/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs b/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs index 28e39c7a2..48a29a086 100644 --- a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs +++ b/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs b/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs index 0695d8102..50cba8d73 100644 --- a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs +++ b/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/task.rs b/support/procedural-fork/src/construct_runtime/expand/task.rs index 94a5f52bb..fdfc4d268 100644 --- a/support/procedural-fork/src/construct_runtime/expand/task.rs +++ b/support/procedural-fork/src/construct_runtime/expand/task.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs b/support/procedural-fork/src/construct_runtime/expand/unsigned.rs index 109f7081c..ad81c9c08 100644 --- a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs +++ b/support/procedural-fork/src/construct_runtime/expand/unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/mod.rs b/support/procedural-fork/src/construct_runtime/mod.rs index de688b3d6..aa057f7d6 100644 --- a/support/procedural-fork/src/construct_runtime/mod.rs +++ b/support/procedural-fork/src/construct_runtime/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/construct_runtime/parse.rs b/support/procedural-fork/src/construct_runtime/parse.rs index 173a8dd12..d52cf05d6 100644 --- a/support/procedural-fork/src/construct_runtime/parse.rs +++ b/support/procedural-fork/src/construct_runtime/parse.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/crate_version.rs b/support/procedural-fork/src/crate_version.rs index 63e7c7279..f65b4cbd5 100644 --- a/support/procedural-fork/src/crate_version.rs +++ b/support/procedural-fork/src/crate_version.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/derive_impl.rs b/support/procedural-fork/src/derive_impl.rs index e91f9c534..866be5bab 100644 --- a/support/procedural-fork/src/derive_impl.rs +++ b/support/procedural-fork/src/derive_impl.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -247,6 +248,7 @@ pub fn derive_impl( } #[test] +#[ignore] fn test_derive_impl_attr_args_parsing() { parse2::(quote!( some::path::TestDefaultConfig as some::path::DefaultConfig @@ -264,6 +266,7 @@ fn test_derive_impl_attr_args_parsing() { } #[test] +#[ignore] fn test_runtime_type_with_doc() { trait TestTrait { type Test; @@ -286,6 +289,7 @@ fn test_runtime_type_with_doc() { } #[test] +#[ignore] fn test_disambiguation_path() { let foreign_impl: ItemImpl = parse_quote!(impl SomeTrait for SomeType {}); let default_impl_path: Path = parse_quote!(SomeScope::SomeType); diff --git a/support/procedural-fork/src/dummy_part_checker.rs b/support/procedural-fork/src/dummy_part_checker.rs index 6bed541d1..a226c8f21 100644 --- a/support/procedural-fork/src/dummy_part_checker.rs +++ b/support/procedural-fork/src/dummy_part_checker.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/dynamic_params.rs b/support/procedural-fork/src/dynamic_params.rs index 70a18bf34..1b159fdd7 100644 --- a/support/procedural-fork/src/dynamic_params.rs +++ b/support/procedural-fork/src/dynamic_params.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/key_prefix.rs b/support/procedural-fork/src/key_prefix.rs index aea60ce3b..51f7af1fe 100644 --- a/support/procedural-fork/src/key_prefix.rs +++ b/support/procedural-fork/src/key_prefix.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs index a5d12cdf9..9c1873153 100644 --- a/support/procedural-fork/src/lib.rs +++ b/support/procedural-fork/src/lib.rs @@ -74,9 +74,10 @@ fn counter_prefix(prefix: &str) -> String { format!("CounterFor{}", prefix) } -pub use crate::pallet::parse::tests::simulate_manifest_dir; - +#[cfg(not(doc))] pub mod exports { + pub use crate::pallet::parse::tests::simulate_manifest_dir; + pub mod benchmark { pub use crate::benchmark::*; } diff --git a/support/procedural-fork/src/match_and_insert.rs b/support/procedural-fork/src/match_and_insert.rs index a80b6e95f..475136c13 100644 --- a/support/procedural-fork/src/match_and_insert.rs +++ b/support/procedural-fork/src/match_and_insert.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/clone.rs b/support/procedural-fork/src/no_bound/clone.rs index 17039bdc8..8071e82d9 100644 --- a/support/procedural-fork/src/no_bound/clone.rs +++ b/support/procedural-fork/src/no_bound/clone.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/debug.rs b/support/procedural-fork/src/no_bound/debug.rs index 8034bb5ec..3a171f1a0 100644 --- a/support/procedural-fork/src/no_bound/debug.rs +++ b/support/procedural-fork/src/no_bound/debug.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/default.rs b/support/procedural-fork/src/no_bound/default.rs index 3f896da35..108ceef84 100644 --- a/support/procedural-fork/src/no_bound/default.rs +++ b/support/procedural-fork/src/no_bound/default.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/mod.rs b/support/procedural-fork/src/no_bound/mod.rs index 9e0377dda..f33bf0911 100644 --- a/support/procedural-fork/src/no_bound/mod.rs +++ b/support/procedural-fork/src/no_bound/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/ord.rs b/support/procedural-fork/src/no_bound/ord.rs index 20f30eb9d..4b700280a 100644 --- a/support/procedural-fork/src/no_bound/ord.rs +++ b/support/procedural-fork/src/no_bound/ord.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/partial_eq.rs b/support/procedural-fork/src/no_bound/partial_eq.rs index 8833f6e5f..0b5b3a788 100644 --- a/support/procedural-fork/src/no_bound/partial_eq.rs +++ b/support/procedural-fork/src/no_bound/partial_eq.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/no_bound/partial_ord.rs b/support/procedural-fork/src/no_bound/partial_ord.rs index c73199d4e..dfd33872d 100644 --- a/support/procedural-fork/src/no_bound/partial_ord.rs +++ b/support/procedural-fork/src/no_bound/partial_ord.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/call.rs b/support/procedural-fork/src/pallet/expand/call.rs index a39e81fd1..cd6536fcf 100644 --- a/support/procedural-fork/src/pallet/expand/call.rs +++ b/support/procedural-fork/src/pallet/expand/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/composite.rs b/support/procedural-fork/src/pallet/expand/composite.rs index 49c0ad675..aacf70bf6 100644 --- a/support/procedural-fork/src/pallet/expand/composite.rs +++ b/support/procedural-fork/src/pallet/expand/composite.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/config.rs b/support/procedural-fork/src/pallet/expand/config.rs index 836c74ae7..56811626c 100644 --- a/support/procedural-fork/src/pallet/expand/config.rs +++ b/support/procedural-fork/src/pallet/expand/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/constants.rs b/support/procedural-fork/src/pallet/expand/constants.rs index 5153ccf49..3a148af10 100644 --- a/support/procedural-fork/src/pallet/expand/constants.rs +++ b/support/procedural-fork/src/pallet/expand/constants.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/doc_only.rs b/support/procedural-fork/src/pallet/expand/doc_only.rs index 3e60e9a9b..87579bcde 100644 --- a/support/procedural-fork/src/pallet/expand/doc_only.rs +++ b/support/procedural-fork/src/pallet/expand/doc_only.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/documentation.rs b/support/procedural-fork/src/pallet/expand/documentation.rs index adc4f7ce9..a7dc5af43 100644 --- a/support/procedural-fork/src/pallet/expand/documentation.rs +++ b/support/procedural-fork/src/pallet/expand/documentation.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/error.rs b/support/procedural-fork/src/pallet/expand/error.rs index e2c3f680c..85afb4cd7 100644 --- a/support/procedural-fork/src/pallet/expand/error.rs +++ b/support/procedural-fork/src/pallet/expand/error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/event.rs b/support/procedural-fork/src/pallet/expand/event.rs index 931dcd95a..eb7d5b123 100644 --- a/support/procedural-fork/src/pallet/expand/event.rs +++ b/support/procedural-fork/src/pallet/expand/event.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/genesis_build.rs b/support/procedural-fork/src/pallet/expand/genesis_build.rs index c6089550d..42d413ddc 100644 --- a/support/procedural-fork/src/pallet/expand/genesis_build.rs +++ b/support/procedural-fork/src/pallet/expand/genesis_build.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/genesis_config.rs b/support/procedural-fork/src/pallet/expand/genesis_config.rs index e171e2468..a5deb70d6 100644 --- a/support/procedural-fork/src/pallet/expand/genesis_config.rs +++ b/support/procedural-fork/src/pallet/expand/genesis_config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/hooks.rs b/support/procedural-fork/src/pallet/expand/hooks.rs index 6967f4c08..618b3d3f4 100644 --- a/support/procedural-fork/src/pallet/expand/hooks.rs +++ b/support/procedural-fork/src/pallet/expand/hooks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/inherent.rs b/support/procedural-fork/src/pallet/expand/inherent.rs index 0a80d672a..b685b071f 100644 --- a/support/procedural-fork/src/pallet/expand/inherent.rs +++ b/support/procedural-fork/src/pallet/expand/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/instances.rs b/support/procedural-fork/src/pallet/expand/instances.rs index 12423409c..f0515fd14 100644 --- a/support/procedural-fork/src/pallet/expand/instances.rs +++ b/support/procedural-fork/src/pallet/expand/instances.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/mod.rs b/support/procedural-fork/src/pallet/expand/mod.rs index ff4423f85..4b07a83fb 100644 --- a/support/procedural-fork/src/pallet/expand/mod.rs +++ b/support/procedural-fork/src/pallet/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/origin.rs b/support/procedural-fork/src/pallet/expand/origin.rs index 167445ad6..e1470d4d8 100644 --- a/support/procedural-fork/src/pallet/expand/origin.rs +++ b/support/procedural-fork/src/pallet/expand/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/pallet_struct.rs b/support/procedural-fork/src/pallet/expand/pallet_struct.rs index c5def65ed..f630216c6 100644 --- a/support/procedural-fork/src/pallet/expand/pallet_struct.rs +++ b/support/procedural-fork/src/pallet/expand/pallet_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/storage.rs b/support/procedural-fork/src/pallet/expand/storage.rs index b77e9846b..443eee4b5 100644 --- a/support/procedural-fork/src/pallet/expand/storage.rs +++ b/support/procedural-fork/src/pallet/expand/storage.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/tasks.rs b/support/procedural-fork/src/pallet/expand/tasks.rs index 8c4dfb54f..5b4abca0a 100644 --- a/support/procedural-fork/src/pallet/expand/tasks.rs +++ b/support/procedural-fork/src/pallet/expand/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] //! Contains logic for expanding task-related items. // This file is part of Substrate. diff --git a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs b/support/procedural-fork/src/pallet/expand/tt_default_parts.rs index 57b78339a..c203d3761 100644 --- a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs +++ b/support/procedural-fork/src/pallet/expand/tt_default_parts.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/type_value.rs b/support/procedural-fork/src/pallet/expand/type_value.rs index 84db3e431..b38a2b5ea 100644 --- a/support/procedural-fork/src/pallet/expand/type_value.rs +++ b/support/procedural-fork/src/pallet/expand/type_value.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs b/support/procedural-fork/src/pallet/expand/validate_unsigned.rs index 28c78a1c6..532fd4d07 100644 --- a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs +++ b/support/procedural-fork/src/pallet/expand/validate_unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/expand/warnings.rs b/support/procedural-fork/src/pallet/expand/warnings.rs index 3d71b83af..e75a2389d 100644 --- a/support/procedural-fork/src/pallet/expand/warnings.rs +++ b/support/procedural-fork/src/pallet/expand/warnings.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/mod.rs b/support/procedural-fork/src/pallet/mod.rs index d3796662f..21f08fc79 100644 --- a/support/procedural-fork/src/pallet/mod.rs +++ b/support/procedural-fork/src/pallet/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/call.rs b/support/procedural-fork/src/pallet/parse/call.rs index 865c63473..cbe509c44 100644 --- a/support/procedural-fork/src/pallet/parse/call.rs +++ b/support/procedural-fork/src/pallet/parse/call.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/composite.rs b/support/procedural-fork/src/pallet/parse/composite.rs index 38da1f205..651360016 100644 --- a/support/procedural-fork/src/pallet/parse/composite.rs +++ b/support/procedural-fork/src/pallet/parse/composite.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/config.rs b/support/procedural-fork/src/pallet/parse/config.rs index cde565245..5cda99fea 100644 --- a/support/procedural-fork/src/pallet/parse/config.rs +++ b/support/procedural-fork/src/pallet/parse/config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/error.rs b/support/procedural-fork/src/pallet/parse/error.rs index e93e2113f..e97249b53 100644 --- a/support/procedural-fork/src/pallet/parse/error.rs +++ b/support/procedural-fork/src/pallet/parse/error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/event.rs b/support/procedural-fork/src/pallet/parse/event.rs index 6102dd31f..280440cde 100644 --- a/support/procedural-fork/src/pallet/parse/event.rs +++ b/support/procedural-fork/src/pallet/parse/event.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/extra_constants.rs b/support/procedural-fork/src/pallet/parse/extra_constants.rs index 38acea21a..80ca9a4da 100644 --- a/support/procedural-fork/src/pallet/parse/extra_constants.rs +++ b/support/procedural-fork/src/pallet/parse/extra_constants.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/genesis_build.rs b/support/procedural-fork/src/pallet/parse/genesis_build.rs index 670d4d5ef..3ee7270a7 100644 --- a/support/procedural-fork/src/pallet/parse/genesis_build.rs +++ b/support/procedural-fork/src/pallet/parse/genesis_build.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/genesis_config.rs b/support/procedural-fork/src/pallet/parse/genesis_config.rs index 1c52345eb..90defee72 100644 --- a/support/procedural-fork/src/pallet/parse/genesis_config.rs +++ b/support/procedural-fork/src/pallet/parse/genesis_config.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/helper.rs b/support/procedural-fork/src/pallet/parse/helper.rs index f58c8d81c..1eb94a3e1 100644 --- a/support/procedural-fork/src/pallet/parse/helper.rs +++ b/support/procedural-fork/src/pallet/parse/helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/hooks.rs b/support/procedural-fork/src/pallet/parse/hooks.rs index 1cf5c72cc..441618cd8 100644 --- a/support/procedural-fork/src/pallet/parse/hooks.rs +++ b/support/procedural-fork/src/pallet/parse/hooks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/inherent.rs b/support/procedural-fork/src/pallet/parse/inherent.rs index 4eb04e914..6910d4ec1 100644 --- a/support/procedural-fork/src/pallet/parse/inherent.rs +++ b/support/procedural-fork/src/pallet/parse/inherent.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/mod.rs b/support/procedural-fork/src/pallet/parse/mod.rs index 573feda57..52dee9bf2 100644 --- a/support/procedural-fork/src/pallet/parse/mod.rs +++ b/support/procedural-fork/src/pallet/parse/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/origin.rs b/support/procedural-fork/src/pallet/parse/origin.rs index 2dd84c40d..d38f2c638 100644 --- a/support/procedural-fork/src/pallet/parse/origin.rs +++ b/support/procedural-fork/src/pallet/parse/origin.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/pallet_struct.rs b/support/procedural-fork/src/pallet/parse/pallet_struct.rs index 320cf01fa..389d3eccf 100644 --- a/support/procedural-fork/src/pallet/parse/pallet_struct.rs +++ b/support/procedural-fork/src/pallet/parse/pallet_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/storage.rs b/support/procedural-fork/src/pallet/parse/storage.rs index 64a5e685b..dcc88f629 100644 --- a/support/procedural-fork/src/pallet/parse/storage.rs +++ b/support/procedural-fork/src/pallet/parse/storage.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -718,11 +719,11 @@ fn process_generics( "CountedStorageNMap" => StorageKind::CountedNMap, found => { let msg = format!( - "Invalid pallet::storage, expected ident: `StorageValue` or \ + "Invalid pallet::storage, expected ident: `StorageValue` or \ `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` or `CountedStorageNMap` \ in order to expand metadata, found `{}`.", - found, - ); + found, + ); return Err(syn::Error::new(segment.ident.span(), msg)); } }; diff --git a/support/procedural-fork/src/pallet/parse/tasks.rs b/support/procedural-fork/src/pallet/parse/tasks.rs index 50633fbd0..a496e02d9 100644 --- a/support/procedural-fork/src/pallet/parse/tasks.rs +++ b/support/procedural-fork/src/pallet/parse/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -597,6 +598,7 @@ fn partition_task_attrs(item: &ImplItemFn) -> (Vec, Vec(quote!(#[pallet::task_list(Something::iter())])).unwrap(); parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); @@ -612,6 +614,7 @@ fn test_parse_task_list_() { } #[test] +#[ignore] fn test_parse_task_index() { parse2::(quote!(#[pallet::task_index(3)])).unwrap(); parse2::(quote!(#[pallet::task_index(0)])).unwrap(); @@ -631,6 +634,7 @@ fn test_parse_task_index() { } #[test] +#[ignore] fn test_parse_task_condition() { parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); @@ -639,6 +643,7 @@ fn test_parse_task_condition() { } #[test] +#[ignore] fn test_parse_tasks_attr() { parse2::(quote!(#[pallet::tasks_experimental])).unwrap(); assert_parse_error_matches!( @@ -660,6 +665,7 @@ fn test_parse_tasks_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_basic() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { @@ -686,6 +692,7 @@ fn test_parse_tasks_def_basic() { } #[test] +#[ignore] fn test_parse_tasks_def_basic_increment_decrement() { simulate_manifest_dir("../../examples/basic", || { let parsed = parse2::(quote! { @@ -738,6 +745,7 @@ fn test_parse_tasks_def_basic_increment_decrement() { } #[test] +#[ignore] fn test_parse_tasks_def_duplicate_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -767,6 +775,7 @@ fn test_parse_tasks_def_duplicate_index() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_list() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -786,6 +795,7 @@ fn test_parse_tasks_def_missing_task_list() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_condition() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -805,6 +815,7 @@ fn test_parse_tasks_def_missing_task_condition() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_index() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -824,6 +835,7 @@ fn test_parse_tasks_def_missing_task_index() { } #[test] +#[ignore] fn test_parse_tasks_def_missing_task_weight() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -844,6 +856,7 @@ fn test_parse_tasks_def_missing_task_weight() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_list_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -866,6 +879,7 @@ fn test_parse_tasks_def_unexpected_extra_task_list_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -888,6 +902,7 @@ fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_unexpected_extra_task_index_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -910,6 +925,7 @@ fn test_parse_tasks_def_unexpected_extra_task_index_attr() { } #[test] +#[ignore] fn test_parse_tasks_def_extra_tasks_attribute() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -924,6 +940,7 @@ fn test_parse_tasks_def_extra_tasks_attribute() { } #[test] +#[ignore] fn test_parse_task_enum_def_basic() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -938,6 +955,7 @@ fn test_parse_task_enum_def_basic() { } #[test] +#[ignore] fn test_parse_task_enum_def_non_task_name() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -951,6 +969,7 @@ fn test_parse_task_enum_def_non_task_name() { } #[test] +#[ignore] fn test_parse_task_enum_def_missing_attr_allowed() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -964,6 +983,7 @@ fn test_parse_task_enum_def_missing_attr_allowed() { } #[test] +#[ignore] fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { simulate_manifest_dir("../../examples/basic", || { parse2::(quote! { @@ -976,6 +996,7 @@ fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { } #[test] +#[ignore] fn test_parse_task_enum_def_wrong_attr() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( @@ -992,6 +1013,7 @@ fn test_parse_task_enum_def_wrong_attr() { } #[test] +#[ignore] fn test_parse_task_enum_def_wrong_item() { simulate_manifest_dir("../../examples/basic", || { assert_parse_error_matches!( diff --git a/support/procedural-fork/src/pallet/parse/tests/mod.rs b/support/procedural-fork/src/pallet/parse/tests/mod.rs index fd7dc2dbe..631afcb0a 100644 --- a/support/procedural-fork/src/pallet/parse/tests/mod.rs +++ b/support/procedural-fork/src/pallet/parse/tests/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -223,6 +224,7 @@ pub fn simulate_manifest_dir, F: FnOnce() + std::panic mod tasks; #[test] +#[ignore] fn test_parse_minimal_pallet() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -238,6 +240,7 @@ fn test_parse_minimal_pallet() { } #[test] +#[ignore] fn test_parse_pallet_missing_pallet() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -251,6 +254,7 @@ fn test_parse_pallet_missing_pallet() { } #[test] +#[ignore] fn test_parse_pallet_missing_config() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] diff --git a/support/procedural-fork/src/pallet/parse/tests/tasks.rs b/support/procedural-fork/src/pallet/parse/tests/tasks.rs index 6cd4d13bb..88ad0acfb 100644 --- a/support/procedural-fork/src/pallet/parse/tests/tasks.rs +++ b/support/procedural-fork/src/pallet/parse/tests/tasks.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -18,6 +19,7 @@ use syn::parse_quote; #[test] +#[ignore] fn test_parse_pallet_with_task_enum_missing_impl() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -39,6 +41,7 @@ fn test_parse_pallet_with_task_enum_missing_impl() { } #[test] +#[ignore] fn test_parse_pallet_with_task_enum_wrong_attribute() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -66,6 +69,7 @@ fn test_parse_pallet_with_task_enum_wrong_attribute() { } #[test] +#[ignore] fn test_parse_pallet_missing_task_enum() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -88,6 +92,7 @@ fn test_parse_pallet_missing_task_enum() { } #[test] +#[ignore] fn test_parse_pallet_task_list_in_wrong_place() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -113,6 +118,7 @@ fn test_parse_pallet_task_list_in_wrong_place() { } #[test] +#[ignore] fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { assert_pallet_parse_error! { #[manifest_dir("../../examples/basic")] @@ -141,6 +147,7 @@ fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_non_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -166,6 +173,7 @@ fn test_parse_pallet_manual_task_enum_non_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_non_manual_task_enum_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -191,6 +199,7 @@ fn test_parse_pallet_non_manual_task_enum_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_manual_impl() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] @@ -215,6 +224,7 @@ fn test_parse_pallet_manual_task_enum_manual_impl() { } #[test] +#[ignore] fn test_parse_pallet_manual_task_enum_mismatch_ident() { assert_pallet_parses! { #[manifest_dir("../../examples/basic")] diff --git a/support/procedural-fork/src/pallet/parse/type_value.rs b/support/procedural-fork/src/pallet/parse/type_value.rs index d5c85248f..7a4ba328f 100644 --- a/support/procedural-fork/src/pallet/parse/type_value.rs +++ b/support/procedural-fork/src/pallet/parse/type_value.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs b/support/procedural-fork/src/pallet/parse/validate_unsigned.rs index 6e5109a74..f035cad9d 100644 --- a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs +++ b/support/procedural-fork/src/pallet/parse/validate_unsigned.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/pallet_error.rs b/support/procedural-fork/src/pallet_error.rs index bdf8330cd..4c58d064e 100644 --- a/support/procedural-fork/src/pallet_error.rs +++ b/support/procedural-fork/src/pallet_error.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/expand/mod.rs b/support/procedural-fork/src/runtime/expand/mod.rs index c26cbccb7..19a1d3146 100644 --- a/support/procedural-fork/src/runtime/expand/mod.rs +++ b/support/procedural-fork/src/runtime/expand/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/mod.rs b/support/procedural-fork/src/runtime/mod.rs index 589acff6c..e932478ce 100644 --- a/support/procedural-fork/src/runtime/mod.rs +++ b/support/procedural-fork/src/runtime/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/helper.rs b/support/procedural-fork/src/runtime/parse/helper.rs index 17e362410..da5ae2761 100644 --- a/support/procedural-fork/src/runtime/parse/helper.rs +++ b/support/procedural-fork/src/runtime/parse/helper.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/mod.rs b/support/procedural-fork/src/runtime/parse/mod.rs index 79cf894e8..74ffc6e20 100644 --- a/support/procedural-fork/src/runtime/parse/mod.rs +++ b/support/procedural-fork/src/runtime/parse/mod.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. @@ -255,20 +256,20 @@ impl Def { }; let def = Def { - input, - item, - runtime_struct: runtime_struct.ok_or_else(|| { - syn::Error::new(item_span, + input, + item, + runtime_struct: runtime_struct.ok_or_else(|| { + syn::Error::new(item_span, "Missing Runtime. Please add a struct inside the module and annotate it with `#[runtime::runtime]`" ) - })?, - pallets, - runtime_types: runtime_types.ok_or_else(|| { - syn::Error::new(item_span, + })?, + pallets, + runtime_types: runtime_types.ok_or_else(|| { + syn::Error::new(item_span, "Missing Runtime Types. Please annotate the runtime struct with `#[runtime::derive]`" ) - })?, - }; + })?, + }; Ok(def) } diff --git a/support/procedural-fork/src/runtime/parse/pallet.rs b/support/procedural-fork/src/runtime/parse/pallet.rs index 039e2631b..ab5a494e8 100644 --- a/support/procedural-fork/src/runtime/parse/pallet.rs +++ b/support/procedural-fork/src/runtime/parse/pallet.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/pallet_decl.rs b/support/procedural-fork/src/runtime/parse/pallet_decl.rs index bb1246606..d869cde07 100644 --- a/support/procedural-fork/src/runtime/parse/pallet_decl.rs +++ b/support/procedural-fork/src/runtime/parse/pallet_decl.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/runtime_struct.rs b/support/procedural-fork/src/runtime/parse/runtime_struct.rs index 7ddbdcfeb..619baf048 100644 --- a/support/procedural-fork/src/runtime/parse/runtime_struct.rs +++ b/support/procedural-fork/src/runtime/parse/runtime_struct.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/runtime/parse/runtime_types.rs b/support/procedural-fork/src/runtime/parse/runtime_types.rs index 4d8c8358c..da25cdeed 100644 --- a/support/procedural-fork/src/runtime/parse/runtime_types.rs +++ b/support/procedural-fork/src/runtime/parse/runtime_types.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/storage_alias.rs b/support/procedural-fork/src/storage_alias.rs index 7099239f9..be2dd6ac2 100644 --- a/support/procedural-fork/src/storage_alias.rs +++ b/support/procedural-fork/src/storage_alias.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/transactional.rs b/support/procedural-fork/src/transactional.rs index 73a841d9b..d034ef132 100644 --- a/support/procedural-fork/src/transactional.rs +++ b/support/procedural-fork/src/transactional.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/src/tt_macro.rs b/support/procedural-fork/src/tt_macro.rs index 3f280013f..651828a06 100644 --- a/support/procedural-fork/src/tt_macro.rs +++ b/support/procedural-fork/src/tt_macro.rs @@ -1,3 +1,4 @@ +#![cfg(not(doc))] // This file is part of Substrate. // Copyright (C) Parity Technologies (UK) Ltd. diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh index cdd537616..5cf78c744 100755 --- a/support/procedural-fork/update.sh +++ b/support/procedural-fork/update.sh @@ -56,7 +56,7 @@ if [ -f "$MOD_RS" ]; then fi # Replace all #[test] with #[test]\n#[ignore] using awk -echo "Replacing #[test] with #[test]\n#[ignore] ..." +echo "Replacing #[test] with #[ignore] ..." find "$DEST_DIR" -name '*.rs' | while read -r file; do awk '{if ($0 == "#[test]") print $0 "\n#[ignore]"; else print $0}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" done From 75b68b918e35721d9fa57dfed468cbd1fbd12ce8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 17:17:12 -0400 Subject: [PATCH 18/45] successfully identifying pallets --- build.rs | 2 +- support/code-coverage/src/lib.rs | 28 +++++++++++----------------- support/procedural-fork/src/lib.rs | 26 +++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index ef2f90136..d5806623b 100644 --- a/build.rs +++ b/build.rs @@ -29,7 +29,7 @@ fn main() { let infos = analyze_file(path); //build_print::info!("File: {}", path.display()); for info in infos { - build_print::info!("pallet: {}", info.path.display()); + build_print::info!("found pallet: {}", info.path.display()); } }); diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index d355c1da2..e1ad24fc2 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,5 +1,5 @@ use proc_macro2::TokenStream as TokenStream2; -use procedural_fork::exports::{pallet::parse::Def, simulate_manifest_dir}; +use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use std::{ collections::HashMap, fs, @@ -15,21 +15,15 @@ pub struct PalletCoverageInfo { } pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { - if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { - return Some(pallet); - } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { - return Some(pallet); - } - let err = match Def::try_from(item_mod.clone(), false) { - Err(err) => err, - _ => unreachable!(), - }; - build_print::warn!( - "A: pallet: {}, {}", - item_mod.ident.to_string(), - err.to_string() - ); - None + simulate_manifest_dir("pallets/subtensor", || -> Option { + if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + Some(pallet) + } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { + Some(pallet) + } else { + None + } + }) } pub fn analyze_file(path: &Path) -> Vec { @@ -43,7 +37,7 @@ pub fn analyze_file(path: &Path) -> Vec { return Vec::new(); }; let mut infos = Vec::new(); - PalletVisitor::for_each_pallet(&file, |item_mod, pallet: &Def| { + PalletVisitor::for_each_pallet(&file, |_item_mod, _pallet: &Def| { let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); infos.push(info); diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs index 9c1873153..7564514cd 100644 --- a/support/procedural-fork/src/lib.rs +++ b/support/procedural-fork/src/lib.rs @@ -32,7 +32,13 @@ mod storage_alias; mod transactional; mod tt_macro; -use std::{cell::RefCell, str::FromStr}; +use std::{ + cell::RefCell, + env::{set_var, var}, + path::PathBuf, + str::FromStr, + sync::Mutex, +}; pub(crate) const INHERENT_INSTANCE_NAME: &str = "__InherentHiddenInstance"; @@ -74,6 +80,24 @@ fn counter_prefix(prefix: &str) -> String { format!("CounterFor{}", prefix) } +/// Improvement on [`exports::simulate_manifest_dir`] that allows for an arbitrary return type +pub fn simulate_manifest_dir(path: P, closure: F) -> R +where + P: AsRef, + F: FnOnce() -> R + std::panic::UnwindSafe, +{ + static MANIFEST_DIR_LOCK: Mutex<()> = Mutex::new(()); + let guard = MANIFEST_DIR_LOCK.lock().unwrap(); + let orig = PathBuf::from( + var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), + ); + set_var("CARGO_MANIFEST_DIR", orig.join(path.as_ref())); + let result = std::panic::catch_unwind(closure); + set_var("CARGO_MANIFEST_DIR", &orig); + drop(guard); + result.unwrap() +} + #[cfg(not(doc))] pub mod exports { pub use crate::pallet::parse::tests::simulate_manifest_dir; From ef6244a7aa1f423299e38137e2ced2781f7ddd65 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 17:28:35 -0400 Subject: [PATCH 19/45] increase verbosity while we debug subtensor pallet --- build.rs | 9 ++++----- support/code-coverage/src/lib.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index d5806623b..ab320a383 100644 --- a/build.rs +++ b/build.rs @@ -25,7 +25,7 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); - rust_files.par_iter().for_each(|path| { + rust_files.iter().for_each(|path| { let infos = analyze_file(path); //build_print::info!("File: {}", path.display()); for info in infos { @@ -90,10 +90,9 @@ fn collect_rust_files(dir: &Path) -> Vec { let path = entry.path(); // Skip any path that contains "target" directory - if path - .components() - .any(|component| component.as_os_str() == "target") - || path.ends_with("build.rs") + if path.components().any(|component| { + component.as_os_str() == "target" || component.as_os_str() == "procedural-fork" + }) || path.ends_with("build.rs") { continue; } diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index e1ad24fc2..946df383b 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -16,11 +16,24 @@ pub struct PalletCoverageInfo { pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { + if item_mod.content.is_none() || item_mod.ident != "pallet" { + build_print::info!( + "Skipping blank or irrelevant module: {}", + item_mod.ident.to_string() + ); + return None; + } + build_print::info!("Parsing module: {}", item_mod.ident.to_string()); if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { Some(pallet) } else { + let err = match Def::try_from(item_mod.clone(), false) { + Err(e) => e, + Ok(_) => unreachable!(), + }; + build_print::error!("Error parsing pallet: {}", err); None } }) @@ -37,6 +50,7 @@ pub fn analyze_file(path: &Path) -> Vec { return Vec::new(); }; let mut infos = Vec::new(); + build_print::info!("Analyzing file: {}", path.display()); PalletVisitor::for_each_pallet(&file, |_item_mod, _pallet: &Def| { let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); From f70dd00a91842d677bc984c64633f6af060943e3 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 1 Oct 2024 17:32:11 -0400 Subject: [PATCH 20/45] tweak --- build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.rs b/build.rs index ab320a383..2ab509cc1 100644 --- a/build.rs +++ b/build.rs @@ -25,9 +25,8 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); - rust_files.iter().for_each(|path| { + rust_files.par_iter().for_each(|path| { let infos = analyze_file(path); - //build_print::info!("File: {}", path.display()); for info in infos { build_print::info!("found pallet: {}", info.path.display()); } From eb1b0a94dbc52fc54ac05b59331cdffdc9a066fd Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 00:50:49 -0400 Subject: [PATCH 21/45] document a path forward for resolving #[import_section(..)] --- support/code-coverage/src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 946df383b..fd1388dba 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,5 +1,6 @@ use proc_macro2::TokenStream as TokenStream2; use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; +use quote::ToTokens; use std::{ collections::HashMap, fs, @@ -14,7 +15,7 @@ pub struct PalletCoverageInfo { pub extrinsics: HashMap, } -pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { +pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { if item_mod.content.is_none() || item_mod.ident != "pallet" { build_print::info!( @@ -23,6 +24,17 @@ pub fn try_parse_pallet(item_mod: &ItemMod) -> Option { ); return None; } + let item_mod = item_mod.clone(); + // manually import foreign sections defined by the `#[import_section]` attribute + for attr in item_mod.attrs.iter() { + if attr.meta.path().segments.last().unwrap().ident == "import_section" { + build_print::note!("Importing section: {}", attr.to_token_stream().to_string()); + build_print::note!("path: {:?}", file_path); + // TODO: in parallel, recursively search all files in the parent dir of `file_path` until we + // find a module with a `#[pallet_section]` attribute whose name also matches + // that of the `#[import_section]` attribute + } + } build_print::info!("Parsing module: {}", item_mod.ident.to_string()); if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) @@ -51,7 +63,7 @@ pub fn analyze_file(path: &Path) -> Vec { }; let mut infos = Vec::new(); build_print::info!("Analyzing file: {}", path.display()); - PalletVisitor::for_each_pallet(&file, |_item_mod, _pallet: &Def| { + PalletVisitor::for_each_pallet(&file, &path, |_item_mod, _pallet: &Def| { let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); infos.push(info); @@ -62,14 +74,18 @@ pub fn analyze_file(path: &Path) -> Vec { #[derive(Default)] pub struct PalletVisitor { pub pallets: Vec<(ItemMod, Def)>, + pub file_path: PathBuf, } impl PalletVisitor { - pub fn for_each_pallet(file: &File, mut f: F) -> Self + pub fn for_each_pallet(file: &File, file_path: &Path, mut f: F) -> Self where F: FnMut(&ItemMod, &Def), { - let mut visitor = PalletVisitor::default(); + let mut visitor = PalletVisitor { + pallets: Vec::new(), + file_path: file_path.to_path_buf(), + }; visitor.visit_file(file); for (item_mod, pallet) in &visitor.pallets { f(item_mod, pallet); @@ -80,7 +96,7 @@ impl PalletVisitor { impl<'ast> Visit<'ast> for PalletVisitor { fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { - if let Some(pallet) = try_parse_pallet(item_mod) { + if let Some(pallet) = try_parse_pallet(item_mod, &self.file_path) { self.pallets.push((item_mod.clone(), pallet)); } syn::visit::visit_item_mod(self, item_mod); From daafe8e1f0f1c9786e94d3594da5d30446f048cc Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 12:32:41 -0400 Subject: [PATCH 22/45] works in principle! --- Cargo.lock | 1 + build.rs | 2 +- support/code-coverage/Cargo.toml | 1 + support/code-coverage/src/lib.rs | 77 +++++++++++++++++++++++++++----- 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3e27f8d8..840982d0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9890,6 +9890,7 @@ dependencies = [ "procedural-fork", "quote", "syn 2.0.77", + "walkdir", ] [[package]] diff --git a/build.rs b/build.rs index 2ab509cc1..1613c8535 100644 --- a/build.rs +++ b/build.rs @@ -25,7 +25,7 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); - rust_files.par_iter().for_each(|path| { + rust_files.iter().for_each(|path| { let infos = analyze_file(path); for info in infos { build_print::info!("found pallet: {}", info.path.display()); diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index 2df598866..740abd083 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -9,6 +9,7 @@ syn.workspace = true quote.workspace = true proc-macro2.workspace = true procedural-fork.workspace = true +walkdir.workspace = true [lints] workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index fd1388dba..ff22385be 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -3,11 +3,12 @@ use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; use std::{ collections::HashMap, - fs, + fs::{self}, path::{Path, PathBuf}, str::FromStr, }; -use syn::{visit::Visit, File, ItemMod}; +use syn::{visit::Visit, Attribute, File, Ident, ItemMod}; +use walkdir::WalkDir; #[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { @@ -17,24 +18,39 @@ pub struct PalletCoverageInfo { pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { + // Single check for both content and identifier relevance if item_mod.content.is_none() || item_mod.ident != "pallet" { build_print::info!( - "Skipping blank or irrelevant module: {}", + "Skipping irrelevant or blank module: {}", item_mod.ident.to_string() ); return None; } - let item_mod = item_mod.clone(); + // manually import foreign sections defined by the `#[import_section]` attribute for attr in item_mod.attrs.iter() { - if attr.meta.path().segments.last().unwrap().ident == "import_section" { - build_print::note!("Importing section: {}", attr.to_token_stream().to_string()); - build_print::note!("path: {:?}", file_path); - // TODO: in parallel, recursively search all files in the parent dir of `file_path` until we - // find a module with a `#[pallet_section]` attribute whose name also matches - // that of the `#[import_section]` attribute + if attr.meta.path().segments.last().unwrap().ident != "import_section" { + continue; + } + build_print::note!("Importing section: {}", attr.to_token_stream().to_string()); + build_print::note!("path: {:?}", file_path); + + // Extract the section name from the attribute's args + let Ok(inner_path) = attr.parse_args::() else { + continue; + }; + let section_name = &inner_path.segments.last().unwrap().ident; + + if let Some(matching_path) = find_matching_pallet_section(file_path, §ion_name) { + build_print::note!("Found matching pallet section at: {:?}", matching_path); + } else { + build_print::warn!( + "Could not find a matching pallet section for: {}", + section_name + ); } } + build_print::info!("Parsing module: {}", item_mod.ident.to_string()); if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) @@ -51,6 +67,47 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { }) } +fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option { + let Some(base_path) = src_path.parent() else { + return None; + }; + for entry in WalkDir::new(base_path.parent().unwrap()) + .into_iter() + .filter_map(Result::ok) + { + let path = entry.path(); + if path == src_path { + continue; + } + if path.is_file() { + build_print::warn!("Checking file: {}", path.display()); + let Ok(content) = fs::read_to_string(path) else { + continue; + }; + let Ok(file) = syn::parse_file(&content) else { + continue; + }; + for item in file.items { + let syn::Item::Mod(item_mod) = item else { + continue; + }; + if item_mod.ident != *section_name { + continue; + } + build_print::note!("Checking module: {}", item_mod.ident.to_string()); + if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { + return Some(path.to_path_buf()); + } + } + } + } + None +} + +fn is_pallet_section(attr: &Attribute) -> bool { + attr.meta.path().segments.last().unwrap().ident != "pallet_section" +} + pub fn analyze_file(path: &Path) -> Vec { let Ok(content) = fs::read_to_string(path) else { return Vec::new(); From 5c1eb4cece806b50dc0106c0fc701481c889e0ec Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 12:44:29 -0400 Subject: [PATCH 23/45] clean up --- support/code-coverage/src/lib.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index ff22385be..faa3b1e28 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -18,12 +18,7 @@ pub struct PalletCoverageInfo { pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { - // Single check for both content and identifier relevance if item_mod.content.is_none() || item_mod.ident != "pallet" { - build_print::info!( - "Skipping irrelevant or blank module: {}", - item_mod.ident.to_string() - ); return None; } @@ -32,8 +27,6 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { if attr.meta.path().segments.last().unwrap().ident != "import_section" { continue; } - build_print::note!("Importing section: {}", attr.to_token_stream().to_string()); - build_print::note!("path: {:?}", file_path); // Extract the section name from the attribute's args let Ok(inner_path) = attr.parse_args::() else { @@ -51,7 +44,6 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { } } - build_print::info!("Parsing module: {}", item_mod.ident.to_string()); if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { @@ -61,7 +53,8 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { Err(e) => e, Ok(_) => unreachable!(), }; - build_print::error!("Error parsing pallet: {}", err); + build_print::error!("unable to parse pallet in {}:", file_path.display()); + build_print::println!(" {}", err); None } }) @@ -80,7 +73,6 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option continue; } if path.is_file() { - build_print::warn!("Checking file: {}", path.display()); let Ok(content) = fs::read_to_string(path) else { continue; }; @@ -94,7 +86,6 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option if item_mod.ident != *section_name { continue; } - build_print::note!("Checking module: {}", item_mod.ident.to_string()); if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { return Some(path.to_path_buf()); } @@ -119,7 +110,6 @@ pub fn analyze_file(path: &Path) -> Vec { return Vec::new(); }; let mut infos = Vec::new(); - build_print::info!("Analyzing file: {}", path.display()); PalletVisitor::for_each_pallet(&file, &path, |_item_mod, _pallet: &Def| { let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); From 661a63b83d4441cc0de37f6af6d1bcecc3e2fb9a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 13:32:03 -0400 Subject: [PATCH 24/45] parallelize pallet section searching --- Cargo.lock | 1 + Cargo.toml | 3 ++- build.rs | 2 +- support/code-coverage/Cargo.toml | 1 + support/code-coverage/src/lib.rs | 38 ++++++++++++++++++++------------ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 840982d0b..7e8c0cddd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9889,6 +9889,7 @@ dependencies = [ "proc-macro2", "procedural-fork", "quote", + "rayon", "syn 2.0.77", "walkdir", ] diff --git a/Cargo.toml b/Cargo.toml index abf4671f8..ed345e836 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ syn.workspace = true quote.workspace = true proc-macro2.workspace = true walkdir.workspace = true -rayon = "1.10" +rayon.workspace = true [workspace] members = [ @@ -48,6 +48,7 @@ unwrap-used = "deny" manual_inspect = "allow" [workspace.dependencies] +rayon = "1" build-print = "0.1" cargo-husky = { version = "1", default-features = false } clap = "4.5.4" diff --git a/build.rs b/build.rs index 1613c8535..2ab509cc1 100644 --- a/build.rs +++ b/build.rs @@ -25,7 +25,7 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); - rust_files.iter().for_each(|path| { + rust_files.par_iter().for_each(|path| { let infos = analyze_file(path); for info in infos { build_print::info!("found pallet: {}", info.path.display()); diff --git a/support/code-coverage/Cargo.toml b/support/code-coverage/Cargo.toml index 740abd083..0e19c2bb4 100644 --- a/support/code-coverage/Cargo.toml +++ b/support/code-coverage/Cargo.toml @@ -10,6 +10,7 @@ quote.workspace = true proc-macro2.workspace = true procedural-fork.workspace = true walkdir.workspace = true +rayon.workspace = true [lints] workspace = true diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index faa3b1e28..31269e0d7 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,8 +1,10 @@ use proc_macro2::TokenStream as TokenStream2; use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; +use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use std::{ collections::HashMap, + ffi::OsStr, fs::{self}, path::{Path, PathBuf}, str::FromStr, @@ -64,35 +66,43 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option let Some(base_path) = src_path.parent() else { return None; }; - for entry in WalkDir::new(base_path.parent().unwrap()) + let rust_files = WalkDir::new(base_path.parent().unwrap()) .into_iter() .filter_map(Result::ok) - { - let path = entry.path(); - if path == src_path { - continue; - } - if path.is_file() { + .filter(|e| { + e.path() != src_path + && e.path().is_file() + && e.path().extension() == Some(OsStr::new("rs")) + }) + .map(|e| e.path().to_path_buf()) + .collect::>(); + let section_name = section_name.to_string().trim().to_string(); + rust_files + .par_iter() + .find_any(|path| { + if !path.display().to_string().contains("macros") { + return false; + } let Ok(content) = fs::read_to_string(path) else { - continue; + return false; }; let Ok(file) = syn::parse_file(&content) else { - continue; + return false; }; for item in file.items { let syn::Item::Mod(item_mod) = item else { continue; }; - if item_mod.ident != *section_name { + if item_mod.ident != section_name { continue; } if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { - return Some(path.to_path_buf()); + return true; } } - } - } - None + false + }) + .cloned() } fn is_pallet_section(attr: &Attribute) -> bool { From ab44805a30609a42b9dafae54ce67f8bc3be9c34 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 15:51:53 -0400 Subject: [PATCH 25/45] cleaned up parsing :tada: --- build.rs | 5 +- support/code-coverage/src/lib.rs | 87 +++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/build.rs b/build.rs index 2ab509cc1..c6c13800a 100644 --- a/build.rs +++ b/build.rs @@ -26,10 +26,7 @@ fn main() { let rust_files = collect_rust_files(workspace_root); rust_files.par_iter().for_each(|path| { - let infos = analyze_file(path); - for info in infos { - build_print::info!("found pallet: {}", info.path.display()); - } + let _infos = analyze_file(path); }); // Channel used to communicate errors back to the main thread from the parallel processing diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 31269e0d7..9c852521e 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -1,3 +1,4 @@ +use build_print::*; use proc_macro2::TokenStream as TokenStream2; use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; @@ -20,10 +21,19 @@ pub struct PalletCoverageInfo { pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { - if item_mod.content.is_none() || item_mod.ident != "pallet" { + // skip non-inline modules + let mut item_mod = item_mod.clone(); + let Some((_, ref mut content)) = item_mod.content else { + return None; + }; + + // skip non-pallet modules + if item_mod.ident != "pallet" { return None; } + let mut section_announced = false; + // manually import foreign sections defined by the `#[import_section]` attribute for attr in item_mod.attrs.iter() { if attr.meta.path().segments.last().unwrap().ident != "import_section" { @@ -36,17 +46,33 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { }; let section_name = &inner_path.segments.last().unwrap().ident; - if let Some(matching_path) = find_matching_pallet_section(file_path, §ion_name) { - build_print::note!("Found matching pallet section at: {:?}", matching_path); + if !section_announced { + custom_println!( + "[code-coverage]", + cyan, + "importing pallet sections for '{}'...", + extract_pallet_name(file_path).unwrap_or("unknown".to_string()), + ); + section_announced = true; + } + + if let Some(section_mod) = find_matching_pallet_section(file_path, §ion_name) { + let Some((_, mut section_content)) = section_mod.content else { + continue; + }; + content.append(&mut section_content); + custom_println!("[code-coverage]", cyan, "â”” imported '{}' ✔", section_name,); } else { - build_print::warn!( - "Could not find a matching pallet section for: {}", - section_name + custom_println!( + "[code-coverage]", + red, + "could not find matching section for: '{}'", + section_name, ); } } - if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + let pallet = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { Some(pallet) @@ -55,14 +81,31 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { Err(e) => e, Ok(_) => unreachable!(), }; - build_print::error!("unable to parse pallet in {}:", file_path.display()); - build_print::println!(" {}", err); + custom_println!( + "[code-coverage]", + red, + "unable to parse pallet in {}:", + file_path.display() + ); + custom_println!("[code-coverage]", red, "{}", err); None + }; + match pallet { + Some(pallet) => { + custom_println!( + "[code-coverage]", + green, + "parsed pallet '{}' ✔", + extract_pallet_name(file_path).unwrap_or("unknown".to_string()), + ); + Some(pallet) + } + None => None, } }) } -fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option { +fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option { let Some(base_path) = src_path.parent() else { return None; }; @@ -79,15 +122,15 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option let section_name = section_name.to_string().trim().to_string(); rust_files .par_iter() - .find_any(|path| { + .find_map_any(|path| { if !path.display().to_string().contains("macros") { - return false; + return None; } let Ok(content) = fs::read_to_string(path) else { - return false; + return None; }; let Ok(file) = syn::parse_file(&content) else { - return false; + return None; }; for item in file.items { let syn::Item::Mod(item_mod) = item else { @@ -97,12 +140,13 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option continue; } if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { - return true; + // can't move ItemMod across thread boundaries + return Some(item_mod.to_token_stream().to_string()); } } - false + None }) - .cloned() + .map(|s| syn::parse_str::(&s).unwrap()) // can't move ItemMod across thread boundaries } fn is_pallet_section(attr: &Attribute) -> bool { @@ -159,3 +203,12 @@ impl<'ast> Visit<'ast> for PalletVisitor { syn::visit::visit_item_mod(self, item_mod); } } + +pub fn extract_pallet_name(path: &Path) -> Option { + // Try to get the parent directory, then the directory name + path.parent()? + .parent()? // Go up one level to the "pallets" directory + .file_name() // Get the directory name "subtensor" + .and_then(|os_str| os_str.to_str()) // Convert OsStr to &str + .map(|s| s.to_string()) // Convert &str to String +} From b32d051f5ec3e2ee13bdc297ed94a6d4aace5870 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 15:58:23 -0400 Subject: [PATCH 26/45] fix --- build.rs | 3 +++ support/code-coverage/src/lib.rs | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index c6c13800a..232277348 100644 --- a/build.rs +++ b/build.rs @@ -26,6 +26,9 @@ fn main() { let rust_files = collect_rust_files(workspace_root); rust_files.par_iter().for_each(|path| { + if path.display().to_string().contains("test") { + return; + } let _infos = analyze_file(path); }); diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 9c852521e..a0d76edee 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -95,8 +95,9 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { custom_println!( "[code-coverage]", green, - "parsed pallet '{}' ✔", + "parsed pallet '{}' ✔ ({})", extract_pallet_name(file_path).unwrap_or("unknown".to_string()), + file_path.display(), ); Some(pallet) } From 9e21e5c328ff7105525d8f4c63bf5c79bda2401c Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 20:56:01 -0400 Subject: [PATCH 27/45] correct comment --- build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 232277348..c3d37b36e 100644 --- a/build.rs +++ b/build.rs @@ -56,8 +56,7 @@ fn main() { for error in errors { let loc = error.span().start(); let file_path = relative_path.display(); - // note that spans can't go across thread boundaries without losing their location - // info so we serialize here and send a String + // note that spans can't go across thread boundaries so we serialize here and send a String tx.send(format!( "cargo:warning={}:{}:{}: {}", file_path, loc.line, loc.column, error, From d6ddd0ebdf41b2b2078e5761d4565f27f28f6cb8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 2 Oct 2024 21:33:08 -0400 Subject: [PATCH 28/45] refactor --- support/code-coverage/src/lib.rs | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index a0d76edee..cc65cd676 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -19,6 +19,25 @@ pub struct PalletCoverageInfo { pub extrinsics: HashMap, } +pub fn analyze_file(path: &Path) -> Vec { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(parsed_tokens) = TokenStream2::from_str(&content) else { + return Vec::new(); + }; + let Ok(file) = syn::parse2::(parsed_tokens) else { + return Vec::new(); + }; + let mut infos = Vec::new(); + PalletVisitor::for_each_pallet(&file, &path, |_item_mod, _pallet: &Def| { + let mut info = PalletCoverageInfo::default(); + info.path = path.to_path_buf(); + infos.push(info); + }); + infos +} + pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { // skip non-inline modules @@ -154,25 +173,6 @@ fn is_pallet_section(attr: &Attribute) -> bool { attr.meta.path().segments.last().unwrap().ident != "pallet_section" } -pub fn analyze_file(path: &Path) -> Vec { - let Ok(content) = fs::read_to_string(path) else { - return Vec::new(); - }; - let Ok(parsed_tokens) = TokenStream2::from_str(&content) else { - return Vec::new(); - }; - let Ok(file) = syn::parse2::(parsed_tokens) else { - return Vec::new(); - }; - let mut infos = Vec::new(); - PalletVisitor::for_each_pallet(&file, &path, |_item_mod, _pallet: &Def| { - let mut info = PalletCoverageInfo::default(); - info.path = path.to_path_buf(); - infos.push(info); - }); - infos -} - #[derive(Default)] pub struct PalletVisitor { pub pallets: Vec<(ItemMod, Def)>, From dc002758d04c38ae36aa2cbb49b7c3c23b8b0b9e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 4 Oct 2024 15:54:02 -0400 Subject: [PATCH 29/45] clean up significantly --- build.rs | 2 +- support/code-coverage/src/lib.rs | 135 +++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 25 deletions(-) diff --git a/build.rs b/build.rs index c3d37b36e..eba84d048 100644 --- a/build.rs +++ b/build.rs @@ -29,7 +29,7 @@ fn main() { if path.display().to_string().contains("test") { return; } - let _infos = analyze_file(path); + let _infos = analyze_file(path, workspace_root); }); // Channel used to communicate errors back to the main thread from the parallel processing diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index cc65cd676..512d85b36 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -13,13 +13,15 @@ use std::{ use syn::{visit::Visit, Attribute, File, Ident, ItemMod}; use walkdir::WalkDir; +/// Code coverage information for a pallet #[derive(Default, Debug, PartialEq, Eq, Clone)] pub struct PalletCoverageInfo { pub path: PathBuf, pub extrinsics: HashMap, } -pub fn analyze_file(path: &Path) -> Vec { +/// Collects code coverage information for all pallets in the specified file +pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { let Ok(content) = fs::read_to_string(path) else { return Vec::new(); }; @@ -30,7 +32,15 @@ pub fn analyze_file(path: &Path) -> Vec { return Vec::new(); }; let mut infos = Vec::new(); - PalletVisitor::for_each_pallet(&file, &path, |_item_mod, _pallet: &Def| { + PalletVisitor::for_each_pallet(&file, path, root_path, |_item_mod, _pallet: &Def| { + custom_println!( + "[code-coverage]", + green, + "parsed pallet '{}' ({})", + extract_pallet_name(path).unwrap_or("unknown".to_string()), + strip_common_suffix("/src/lib.rs".as_ref(), strip_common_prefix(root_path, path)) + .display(), + ); let mut info = PalletCoverageInfo::default(); info.path = path.to_path_buf(); infos.push(info); @@ -38,7 +48,8 @@ pub fn analyze_file(path: &Path) -> Vec { infos } -pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { +/// Tries to parse a pallet from a module +pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { // skip non-inline modules let mut item_mod = item_mod.clone(); @@ -69,18 +80,35 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { custom_println!( "[code-coverage]", cyan, - "importing pallet sections for '{}'...", + "importing pallet sections for '{}' ({})...", extract_pallet_name(file_path).unwrap_or("unknown".to_string()), + strip_common_suffix( + "/src/lib.rs".as_ref(), + strip_common_prefix(root_path, file_path) + ) + .display(), ); section_announced = true; } - if let Some(section_mod) = find_matching_pallet_section(file_path, §ion_name) { + if let Some((section_mod, section_path)) = + find_matching_pallet_section(file_path, §ion_name) + { let Some((_, mut section_content)) = section_mod.content else { continue; }; content.append(&mut section_content); - custom_println!("[code-coverage]", cyan, "â”” imported '{}' ✔", section_name,); + custom_println!( + "[code-coverage]", + cyan, + "â”” imported '{}' ({})", + section_name, + strip_common_suffix( + "/src/lib.rs".as_ref(), + strip_common_prefix(file_path, §ion_path) + ) + .display() + ); } else { custom_println!( "[code-coverage]", @@ -109,23 +137,14 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path) -> Option { custom_println!("[code-coverage]", red, "{}", err); None }; - match pallet { - Some(pallet) => { - custom_println!( - "[code-coverage]", - green, - "parsed pallet '{}' ✔ ({})", - extract_pallet_name(file_path).unwrap_or("unknown".to_string()), - file_path.display(), - ); - Some(pallet) - } - None => None, - } + pallet }) } -fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option { +fn find_matching_pallet_section( + src_path: &Path, + section_name: &Ident, +) -> Option<(ItemMod, PathBuf)> { let Some(base_path) = src_path.parent() else { return None; }; @@ -161,32 +180,35 @@ fn find_matching_pallet_section(src_path: &Path, section_name: &Ident) -> Option } if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { // can't move ItemMod across thread boundaries - return Some(item_mod.to_token_stream().to_string()); + return Some((item_mod.to_token_stream().to_string(), path.to_path_buf())); } } None }) - .map(|s| syn::parse_str::(&s).unwrap()) // can't move ItemMod across thread boundaries + .map(|(s, p)| (syn::parse_str::(&s).unwrap(), p)) // can't move ItemMod across thread boundaries } fn is_pallet_section(attr: &Attribute) -> bool { attr.meta.path().segments.last().unwrap().ident != "pallet_section" } +/// A visitor that collects pallets from a file/module #[derive(Default)] pub struct PalletVisitor { pub pallets: Vec<(ItemMod, Def)>, pub file_path: PathBuf, + pub workspace_root_path: PathBuf, } impl PalletVisitor { - pub fn for_each_pallet(file: &File, file_path: &Path, mut f: F) -> Self + pub fn for_each_pallet(file: &File, file_path: &Path, root_path: &Path, mut f: F) -> Self where F: FnMut(&ItemMod, &Def), { let mut visitor = PalletVisitor { pallets: Vec::new(), file_path: file_path.to_path_buf(), + workspace_root_path: root_path.to_path_buf(), }; visitor.visit_file(file); for (item_mod, pallet) in &visitor.pallets { @@ -198,13 +220,15 @@ impl PalletVisitor { impl<'ast> Visit<'ast> for PalletVisitor { fn visit_item_mod(&mut self, item_mod: &'ast ItemMod) { - if let Some(pallet) = try_parse_pallet(item_mod, &self.file_path) { + if let Some(pallet) = try_parse_pallet(item_mod, &self.file_path, &self.workspace_root_path) + { self.pallets.push((item_mod.clone(), pallet)); } syn::visit::visit_item_mod(self, item_mod); } } +/// Extracts the pallet name from a path pub fn extract_pallet_name(path: &Path) -> Option { // Try to get the parent directory, then the directory name path.parent()? @@ -213,3 +237,66 @@ pub fn extract_pallet_name(path: &Path) -> Option { .and_then(|os_str| os_str.to_str()) // Convert OsStr to &str .map(|s| s.to_string()) // Convert &str to String } + +/// Strips the longest common prefix from two paths (i.e. base is allowed to have more +/// components that are not shared with target and these are ignored) +pub fn strip_common_prefix<'a>(base: &'a Path, target: &'a Path) -> &'a Path { + let mut base_components = base.components(); + let mut target_components = target.components(); + let mut common_length = 0; + + // Find the longest common prefix + while let (Some(bc), Some(tc)) = (base_components.next(), target_components.next()) { + if bc == tc { + common_length += 1; + } else { + break; + } + } + + // Create a Path that skips the common prefix + let mut remaining = target; + for _ in 0..common_length { + remaining = remaining + .strip_prefix(remaining.components().next().unwrap()) + .unwrap_or(remaining); + } + + remaining +} + +/// Strips the longest common suffix from two paths (i.e. base is allowed to have more +/// leading components that are not shared with target and these are ignored) +pub fn strip_common_suffix<'a>(base: &'a Path, target: &'a Path) -> &'a Path { + let base_components: Vec<_> = base.components().collect(); + let target_components: Vec<_> = target.components().collect(); + + let mut common_suffix_length = 0; + + // Reverse iterate over both paths to find the longest common suffix + for (bc, tc) in base_components + .iter() + .rev() + .zip(target_components.iter().rev()) + { + if bc == tc { + common_suffix_length += 1; + } else { + break; + } + } + + // If there is no common suffix, return target verbatim + if common_suffix_length == 0 { + return target; + } + + // Create a new path without the common suffix + let mut remaining = target; + + for _ in 0..common_suffix_length { + remaining = remaining.parent().unwrap_or(target); + } + + remaining +} From 24658d07ac5074982258538a4650e15405bfe609 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 4 Oct 2024 16:04:08 -0400 Subject: [PATCH 30/45] collect method calls --- support/code-coverage/src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 512d85b36..4fd855bee 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -4,7 +4,6 @@ use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use std::{ - collections::HashMap, ffi::OsStr, fs::{self}, path::{Path, PathBuf}, @@ -15,13 +14,14 @@ use walkdir::WalkDir; /// Code coverage information for a pallet #[derive(Default, Debug, PartialEq, Eq, Clone)] -pub struct PalletCoverageInfo { +pub struct PalletInfo { pub path: PathBuf, - pub extrinsics: HashMap, + pub pallet_name: String, + pub methods: Vec, } /// Collects code coverage information for all pallets in the specified file -pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { +pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { let Ok(content) = fs::read_to_string(path) else { return Vec::new(); }; @@ -32,7 +32,7 @@ pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { return Vec::new(); }; let mut infos = Vec::new(); - PalletVisitor::for_each_pallet(&file, path, root_path, |_item_mod, _pallet: &Def| { + PalletVisitor::for_each_pallet(&file, path, root_path, |_item_mod, pallet: &Def| { custom_println!( "[code-coverage]", green, @@ -41,8 +41,18 @@ pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { strip_common_suffix("/src/lib.rs".as_ref(), strip_common_prefix(root_path, path)) .display(), ); - let mut info = PalletCoverageInfo::default(); + let mut info = PalletInfo::default(); info.path = path.to_path_buf(); + info.pallet_name = extract_pallet_name(path).unwrap_or("pallet".to_string()); + + // collect all Call methods + if let Some(call) = &pallet.call { + info.methods + .append(&mut call.methods.iter().map(|m| m.name.to_string()).collect()); + } + + build_print::println!("{:?}", info); + infos.push(info); }); infos From 12574325331ccffa17af5c5437f0b318c3639c27 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 4 Oct 2024 16:05:42 -0400 Subject: [PATCH 31/45] no need to hard-code `macros` directory --- support/code-coverage/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 4fd855bee..fb3441143 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -172,7 +172,7 @@ fn find_matching_pallet_section( rust_files .par_iter() .find_map_any(|path| { - if !path.display().to_string().contains("macros") { + if path.display().to_string().contains("test") { return None; } let Ok(content) = fs::read_to_string(path) else { From b0cc18bc66cb00bb21ece9c7ca4f62c09eee5d20 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 4 Oct 2024 17:03:24 -0400 Subject: [PATCH 32/45] WIP --- build.rs | 43 ++------------------------------ support/code-coverage/src/lib.rs | 41 ++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/build.rs b/build.rs index eba84d048..4afb54693 100644 --- a/build.rs +++ b/build.rs @@ -1,12 +1,6 @@ use rayon::prelude::*; -use std::{ - env, fs, - path::{Path, PathBuf}, - str::FromStr, - sync::mpsc::channel, -}; -use subtensor_code_coverage::analyze_file; -use walkdir::WalkDir; +use std::{env, fs, path::Path, str::FromStr, sync::mpsc::channel}; +use subtensor_code_coverage::collect_rust_files; use subtensor_linting::*; @@ -25,13 +19,6 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); - rust_files.par_iter().for_each(|path| { - if path.display().to_string().contains("test") { - return; - } - let _infos = analyze_file(path, workspace_root); - }); - // Channel used to communicate errors back to the main thread from the parallel processing // as we process each Rust file let (tx, rx) = channel(); @@ -76,29 +63,3 @@ fn main() { println!("{error}"); } } - -/// Recursively collects all Rust files in the given directory -fn collect_rust_files(dir: &Path) -> Vec { - let mut rust_files = Vec::new(); - - for entry in WalkDir::new(dir) { - let Ok(entry) = entry else { - continue; - }; - let path = entry.path(); - - // Skip any path that contains "target" directory - if path.components().any(|component| { - component.as_os_str() == "target" || component.as_os_str() == "procedural-fork" - }) || path.ends_with("build.rs") - { - continue; - } - - if path.is_file() && path.extension().and_then(|ext| ext.to_str()) == Some("rs") { - rust_files.push(path.to_path_buf()); - } - } - - rust_files -} diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index fb3441143..52fd89949 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -20,8 +20,45 @@ pub struct PalletInfo { pub methods: Vec, } -/// Collects code coverage information for all pallets in the specified file -pub fn analyze_file(path: &Path, root_path: &Path) -> Vec { +/// Recursively collects all Rust files in the given directory +pub fn collect_rust_files(dir: &Path) -> Vec { + let mut rust_files = Vec::new(); + + for entry in WalkDir::new(dir) { + let Ok(entry) = entry else { + continue; + }; + let path = entry.path(); + + // Skip any path that contains "target" directory + if path.components().any(|component| { + component.as_os_str() == "target" || component.as_os_str() == "procedural-fork" + }) || path.ends_with("build.rs") + { + continue; + } + + if path.is_file() && path.extension().and_then(|ext| ext.to_str()) == Some("rs") { + rust_files.push(path.to_path_buf()); + } + } + + rust_files +} + +pub fn analyze_files(workspace_root: &Path) -> Vec { + let rust_files = collect_rust_files(workspace_root); + let mut infos = Vec::new(); + for path in rust_files { + if path.display().to_string().contains("test") { + continue; + } + infos.append(&mut analyze_file(&path, workspace_root)); + } + infos +} + +fn analyze_file(path: &Path, root_path: &Path) -> Vec { let Ok(content) = fs::read_to_string(path) else { return Vec::new(); }; From 84c687d21c1587016261edd70d28a387db8968c2 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 03:04:07 -0400 Subject: [PATCH 33/45] use a proper map-reduce for analyze_files --- build.rs | 3 +++ support/code-coverage/src/lib.rs | 34 +++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index 4afb54693..c735bea60 100644 --- a/build.rs +++ b/build.rs @@ -19,6 +19,9 @@ fn main() { // Collect all Rust source files in the workspace let rust_files = collect_rust_files(workspace_root); + // Generate code coverage report + subtensor_code_coverage::analyze_files(&rust_files, &workspace_root); + // Channel used to communicate errors back to the main thread from the parallel processing // as we process each Rust file let (tx, rx) = channel(); diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 52fd89949..f493e6a68 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -46,15 +46,29 @@ pub fn collect_rust_files(dir: &Path) -> Vec { rust_files } -pub fn analyze_files(workspace_root: &Path) -> Vec { - let rust_files = collect_rust_files(workspace_root); - let mut infos = Vec::new(); - for path in rust_files { - if path.display().to_string().contains("test") { - continue; - } - infos.append(&mut analyze_file(&path, workspace_root)); - } +pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { + custom_println!( + "[code-coverage]", + green, + "searching {} rust files for pallets in parallel...", + rust_files.len() + ); + let infos = rust_files + .par_iter() + .map(|path| { + if path.display().to_string().contains("test") { + return Vec::new(); + } + analyze_file(&path, workspace_root) + }) + .reduce( + || Vec::new(), + |mut acc, mut infos| { + acc.append(&mut infos); + acc + }, + ); + custom_println!("[code-coverage]", green, "found {} pallets", infos.len()); infos } @@ -88,8 +102,6 @@ fn analyze_file(path: &Path, root_path: &Path) -> Vec { .append(&mut call.methods.iter().map(|m| m.name.to_string()).collect()); } - build_print::println!("{:?}", info); - infos.push(info); }); infos From 5269e3acf559ea8f50aadca61c4f996bfd61b27e Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 10:34:36 -0400 Subject: [PATCH 34/45] find_tests scaffold --- support/code-coverage/src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index f493e6a68..8637f8f8c 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -49,7 +49,7 @@ pub fn collect_rust_files(dir: &Path) -> Vec { pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { custom_println!( "[code-coverage]", - green, + cyan, "searching {} rust files for pallets in parallel...", rust_files.len() ); @@ -69,6 +69,12 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec { infos } +fn find_tests(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { + custom_println!( + "[code-coverage]", + cyan, + "searching {} rust files for tests in parallel...", + rust_files.len() + ); + let infos = rust_files.par_iter().map(|path| todo!()).reduce( + || Vec::new(), + |mut acc, mut infos| { + acc.append(&mut infos); + acc + }, + ); + custom_println!("[code-coverage]", green, "found {} tests", infos.len()); + infos +} + /// Tries to parse a pallet from a module pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { From 5ee1d2b2a97475cafadc911f46f470cc995c22be Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 13:13:22 -0400 Subject: [PATCH 35/45] accumulate list of tests in parallel --- support/code-coverage/src/lib.rs | 68 ++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 8637f8f8c..9fe96ec86 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -9,7 +9,7 @@ use std::{ path::{Path, PathBuf}, str::FromStr, }; -use syn::{visit::Visit, Attribute, File, Ident, ItemMod}; +use syn::{visit::Visit, Attribute, File, Ident, ItemFn, ItemMod}; use walkdir::WalkDir; /// Code coverage information for a pallet @@ -75,6 +75,8 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec { infos } -fn find_tests(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { - custom_println!( - "[code-coverage]", - cyan, - "searching {} rust files for tests in parallel...", - rust_files.len() - ); - let infos = rust_files.par_iter().map(|path| todo!()).reduce( - || Vec::new(), - |mut acc, mut infos| { - acc.append(&mut infos); - acc - }, - ); - custom_println!("[code-coverage]", green, "found {} tests", infos.len()); - infos +/// Finds all tests in the given set of rust files, using a parallel map-reduce. +pub fn find_tests(rust_files: &[PathBuf]) -> Vec { + let tests: Vec = rust_files + .par_iter() + .map(|path| { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(file) = syn::parse_file(&content) else { + return Vec::new(); + }; + let mut visitor = TestVisitor { tests: Vec::new() }; + visitor.visit_file(&file); + visitor + .tests + .into_iter() + .map(|f| f.to_token_stream().to_string()) + .collect() + }) + .reduce( + || Vec::new(), + |mut acc, mut infos| { + acc.append(&mut infos); + acc + }, + ); + tests + .into_iter() + .map(|s| syn::parse_str::(&s).unwrap()) + .collect() +} + +pub struct TestVisitor { + pub tests: Vec, +} + +impl<'ast> Visit<'ast> for TestVisitor { + fn visit_item_fn(&mut self, item_fn: &'ast ItemFn) { + if item_fn.attrs.iter().any(|attr| { + let Some(seg) = attr.path().segments.last() else { + return false; + }; + seg.ident == "test" || seg.ident == "should_panic" + }) { + self.tests.push(item_fn.clone()); + } + syn::visit::visit_item_fn(self, item_fn); + } } /// Tries to parse a pallet from a module From 07084c104c480c324482f931536f1fda03a34f74 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 15:02:27 -0400 Subject: [PATCH 36/45] collect TestInfo --- support/code-coverage/src/lib.rs | 81 ++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 9fe96ec86..719c802b6 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -4,6 +4,7 @@ use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use std::{ + collections::HashSet, ffi::OsStr, fs::{self}, path::{Path, PathBuf}, @@ -47,6 +48,7 @@ pub fn collect_rust_files(dir: &Path) -> Vec { } pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { + let start = std::time::Instant::now(); custom_println!( "[code-coverage]", cyan, @@ -77,6 +79,27 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec>(); + custom_println!( + "[code-coverage]", + cyan, + "reduced {} methods to {} unique methods", + infos.iter().map(|info| info.methods.len()).sum::(), + methods.len(), + ); + + build_print::println!("test: {:?}", tests); + + let finish = std::time::Instant::now(); + custom_println!( + "[code-coverage]", + green, + "coverage report generated in {:?}", + finish - start + ); infos } @@ -115,9 +138,16 @@ fn analyze_file(path: &Path, root_path: &Path) -> Vec { infos } +#[derive(Default, Debug, Clone, PartialEq, Eq)] +pub struct TestInfo { + pub path: PathBuf, + pub name: String, + pub method_calls: HashSet, +} + /// Finds all tests in the given set of rust files, using a parallel map-reduce. -pub fn find_tests(rust_files: &[PathBuf]) -> Vec { - let tests: Vec = rust_files +pub fn find_tests(rust_files: &[PathBuf]) -> Vec { + rust_files .par_iter() .map(|path| { let Ok(content) = fs::read_to_string(path) else { @@ -131,7 +161,18 @@ pub fn find_tests(rust_files: &[PathBuf]) -> Vec { visitor .tests .into_iter() - .map(|f| f.to_token_stream().to_string()) + .map(|f| { + let mut method_calls = HashSet::new(); + let mut visitor = CallVisitor { + method_calls: &mut method_calls, + }; + visitor.visit_item_fn(&f); + TestInfo { + path: path.clone(), + name: f.sig.ident.to_string(), + method_calls, + } + }) .collect() }) .reduce( @@ -140,11 +181,35 @@ pub fn find_tests(rust_files: &[PathBuf]) -> Vec { acc.append(&mut infos); acc }, - ); - tests - .into_iter() - .map(|s| syn::parse_str::(&s).unwrap()) - .collect() + ) +} + +pub struct CallVisitor<'a> { + pub method_calls: &'a mut HashSet, +} + +impl<'ast> Visit<'ast> for CallVisitor<'_> { + // fn visit_expr_method_call(&mut self, i: &'ast syn::ExprMethodCall) { + // self.method_calls.insert(i.method.to_string()); + // syn::visit::visit_expr_method_call(self, i); + // } + + fn visit_expr_path(&mut self, i: &'ast syn::ExprPath) { + let segments: Vec<_> = i.path.segments.iter().collect(); + // truncate all but the last 2 segments so we preserve the `SubtensorModule` in `some::path::SubtensorModule::foo` + let truncated_segments = if segments.len() > 2 { + &segments[segments.len() - 2..] + } else { + &segments[..] + }; + let truncated_path = truncated_segments + .iter() + .map(|segment| segment.ident.to_string()) + .collect::>() + .join("::"); + self.method_calls.insert(truncated_path); + syn::visit::visit_expr_path(self, i); + } } pub struct TestVisitor { From e0f9f3935c774bfcfa11f4ce647942468a85c2c4 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 15:54:33 -0400 Subject: [PATCH 37/45] compiling report, still optimizing --- support/code-coverage/src/lib.rs | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 719c802b6..b2159a17d 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -4,7 +4,7 @@ use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use std::{ - collections::HashSet, + collections::{HashMap, HashSet}, ffi::OsStr, fs::{self}, path::{Path, PathBuf}, @@ -48,6 +48,7 @@ pub fn collect_rust_files(dir: &Path) -> Vec { } pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec { + custom_println!("[code-coverage]", cyan, "generating coverage report..."); let start = std::time::Instant::now(); custom_println!( "[code-coverage]", @@ -70,7 +71,7 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec>(); + + custom_println!("[code-coverage]", green, "found {} tests", tests.len()); + custom_println!( "[code-coverage]", - cyan, - "reduced {} methods to {} unique methods", - infos.iter().map(|info| info.methods.len()).sum::(), + green, + "found {} unique calls across {} pallets", methods.len(), + infos.len(), ); - build_print::println!("test: {:?}", tests); + custom_println!("[code-coverage]", cyan, "compiling statistics..."); + + let mut coverage: HashMap = HashMap::new(); + // this takes about 6ms serially so better to keep serial for now + for test in &tests { + for method in &test.method_calls { + if methods.contains(method) { + *coverage.entry(method.clone()).or_insert(0) += 1; + } + } + } let finish = std::time::Instant::now(); custom_println!( From 5a8dc6eb52b80a99f8a4be2fcebb5ac507df7428 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 7 Oct 2024 18:48:54 -0400 Subject: [PATCH 38/45] preliminary coverage report working :tada: --- support/code-coverage/src/lib.rs | 70 ++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index b2159a17d..4d1ae135c 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -2,7 +2,10 @@ use build_print::*; use proc_macro2::TokenStream as TokenStream2; use procedural_fork::{exports::pallet::parse::Def, simulate_manifest_dir}; use quote::ToTokens; -use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; +use rayon::{ + iter::{IntoParallelRefIterator, ParallelIterator}, + slice::ParallelSliceMut, +}; use std::{ collections::{HashMap, HashSet}, ffi::OsStr, @@ -82,11 +85,7 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec>(); custom_println!("[code-coverage]", green, "found {} tests", tests.len()); @@ -103,13 +102,43 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec = HashMap::new(); // this takes about 6ms serially so better to keep serial for now + for method in &methods { + coverage + .entry(method.strip_prefix("sudo_").unwrap_or(&method).to_string()) + .or_insert(0); + } for test in &tests { for method in &test.method_calls { - if methods.contains(method) { - *coverage.entry(method.clone()).or_insert(0) += 1; - } + let method = method.strip_prefix("sudo_").unwrap_or(method); + let Some(count) = coverage.get_mut(method) else { + continue; + }; + *count += 1; } } + let mut coverage = coverage.into_iter().collect::>(); + coverage.par_sort_by_key(|(_, v)| *v); + + let (covered, uncovered) = coverage.iter().partition::, _>(|(_, v)| *v > 0); + + custom_println!( + "[code-coverage]", + cyan, + " total covered: {}", + covered.len() + ); + custom_println!( + "[code-coverage]", + cyan, + " total uncovered: {}", + uncovered.len() + ); + custom_println!( + "[code-coverage]", + cyan, + " total coverage: {:.2}%", + covered.len() as f64 / methods.len() as f64 * 100.0 + ); let finish = std::time::Instant::now(); custom_println!( @@ -207,25 +236,14 @@ pub struct CallVisitor<'a> { } impl<'ast> Visit<'ast> for CallVisitor<'_> { - // fn visit_expr_method_call(&mut self, i: &'ast syn::ExprMethodCall) { - // self.method_calls.insert(i.method.to_string()); - // syn::visit::visit_expr_method_call(self, i); - // } + fn visit_expr_method_call(&mut self, i: &'ast syn::ExprMethodCall) { + self.method_calls.insert(i.method.to_string()); + syn::visit::visit_expr_method_call(self, i); + } fn visit_expr_path(&mut self, i: &'ast syn::ExprPath) { - let segments: Vec<_> = i.path.segments.iter().collect(); - // truncate all but the last 2 segments so we preserve the `SubtensorModule` in `some::path::SubtensorModule::foo` - let truncated_segments = if segments.len() > 2 { - &segments[segments.len() - 2..] - } else { - &segments[..] - }; - let truncated_path = truncated_segments - .iter() - .map(|segment| segment.ident.to_string()) - .collect::>() - .join("::"); - self.method_calls.insert(truncated_path); + self.method_calls + .insert(i.path.segments.last().unwrap().ident.to_string()); syn::visit::visit_expr_path(self, i); } } From f5d4c686a4fc2bc3d0faf16c8399e6e5552f851d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 9 Oct 2024 12:47:50 -0400 Subject: [PATCH 39/45] clippy fixes --- build.rs | 2 +- support/code-coverage/src/lib.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index c735bea60..28e69f49c 100644 --- a/build.rs +++ b/build.rs @@ -20,7 +20,7 @@ fn main() { let rust_files = collect_rust_files(workspace_root); // Generate code coverage report - subtensor_code_coverage::analyze_files(&rust_files, &workspace_root); + subtensor_code_coverage::analyze_files(&rust_files, workspace_root); // Channel used to communicate errors back to the main thread from the parallel processing // as we process each Rust file diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 4d1ae135c..531a45413 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -65,10 +65,10 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec Vec { .collect() }) .reduce( - || Vec::new(), + Vec::new, |mut acc, mut infos| { acc.append(&mut infos); acc @@ -310,7 +310,7 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) } if let Some((section_mod, section_path)) = - find_matching_pallet_section(file_path, §ion_name) + find_matching_pallet_section(file_path, section_name) { let Some((_, mut section_content)) = section_mod.content else { continue; @@ -337,7 +337,8 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) } } - let pallet = if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { + + if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { Some(pallet) @@ -354,8 +355,7 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) ); custom_println!("[code-coverage]", red, "{}", err); None - }; - pallet + } }) } @@ -396,7 +396,7 @@ fn find_matching_pallet_section( if item_mod.ident != section_name { continue; } - if item_mod.attrs.iter().any(|attr| is_pallet_section(attr)) { + if item_mod.attrs.iter().any(is_pallet_section) { // can't move ItemMod across thread boundaries return Some((item_mod.to_token_stream().to_string(), path.to_path_buf())); } From 56bb900c15968e8635b4284ffa3b392347b861f9 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 9 Oct 2024 12:48:05 -0400 Subject: [PATCH 40/45] cargo fmt --- support/code-coverage/src/lib.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 531a45413..c69c3001a 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -67,13 +67,10 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec { }) .collect() }) - .reduce( - Vec::new, - |mut acc, mut infos| { - acc.append(&mut infos); - acc - }, - ) + .reduce(Vec::new, |mut acc, mut infos| { + acc.append(&mut infos); + acc + }) } pub struct CallVisitor<'a> { @@ -337,7 +331,6 @@ pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) } } - if let Ok(pallet) = Def::try_from(item_mod.clone(), false) { Some(pallet) } else if let Ok(pallet) = Def::try_from(item_mod.clone(), true) { From f2461d9bcc4efe930d8324b4f93f557ec4f8e382 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 9 Oct 2024 12:57:09 -0400 Subject: [PATCH 41/45] cargo update --- Cargo.lock | 541 +++++++++++++++++++++++++++++------------------------ 1 file changed, 300 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e8c0cddd..b272f1327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,11 +23,11 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli 0.31.0", + "gimli 0.31.1", ] [[package]] @@ -200,7 +200,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -560,7 +560,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "synstructure 0.13.1", ] @@ -583,7 +583,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -629,13 +629,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -670,9 +670,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -680,11 +680,11 @@ version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ - "addr2line 0.24.1", + "addr2line 0.24.2", "cfg-if", "libc", "miniz_oxide", - "object 0.36.4", + "object 0.36.5", "rustc-demangle", "windows-targets 0.52.6", ] @@ -773,7 +773,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -892,9 +892,9 @@ dependencies = [ [[package]] name = "bounded-collections" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32385ecb91a31bddaf908e8dcf4a15aef1bcd3913cc03ebfad02ff6d568abc1" +checksum = "db436177db0d505b1507f03aca56a41442ae6efdf8b6eaa855d73e52c5b078dc" dependencies = [ "log", "parity-scale-codec", @@ -1023,9 +1023,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.21" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "jobserver", "libc", @@ -1170,9 +1170,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -1180,9 +1180,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -1193,14 +1193,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1606,7 +1606,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1633,7 +1633,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1650,7 +1650,7 @@ checksum = "98532a60dedaebc4848cb2cba5023337cc9ea3af16a5b062633fabfd9f18fb60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1674,7 +1674,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1685,7 +1685,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1794,7 +1794,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1807,7 +1807,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1896,7 +1896,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1936,7 +1936,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.77", + "syn 2.0.79", "termcolor", "toml 0.8.19", "walkdir", @@ -2089,7 +2089,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2109,7 +2109,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2170,8 +2170,8 @@ dependencies = [ "fixed-hash", "impl-rlp", "impl-serde", - "primitive-types", - "uint", + "primitive-types 0.12.2", + "uint 0.9.5", ] [[package]] @@ -2222,7 +2222,7 @@ dependencies = [ "prettyplease 0.2.22", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2363,6 +2363,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -2588,7 +2594,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2601,7 +2607,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2613,7 +2619,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2624,7 +2630,7 @@ checksum = "68672b9ec6fe72d259d3879dc212c5e42e977588cdac830c76f54d9f492aeb58" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2634,7 +2640,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1#a42 dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2719,9 +2725,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -2744,9 +2750,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -2754,15 +2760,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -2772,9 +2778,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -2788,13 +2794,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2809,15 +2815,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -2827,9 +2833,9 @@ checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -2936,9 +2942,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" @@ -2989,7 +2995,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -3008,7 +3014,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -3072,6 +3078,17 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] + [[package]] name = "hashlink" version = "0.8.4" @@ -3240,9 +3257,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" @@ -3318,9 +3335,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-util", @@ -3329,7 +3346,6 @@ dependencies = [ "hyper 1.4.1", "pin-project-lite", "tokio", - "tower", "tower-service", ] @@ -3450,6 +3466,26 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "impl-codec" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-num-traits" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "803d15461ab0dcc56706adf266158acbc44ccf719bf7d0af30705f58b90a4b8c" +dependencies = [ + "integer-sqrt", + "num-traits", + "uint 0.10.0", +] + [[package]] name = "impl-rlp" version = "0.3.0" @@ -3511,12 +3547,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -3577,9 +3613,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "is-terminal" @@ -3651,9 +3687,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.24.4" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd1ead9fb95614e8dc5556d12a8681c2f6d352d0c1d3efc8708c7ccbba47bc6" +checksum = "02f01f48e04e0d7da72280ab787c9943695699c9b32b99158ece105e8ad0afea" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -3665,9 +3701,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.4" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff79651479f69ada7bda604ef2acf3f1aa50755d97cc36d25ff04c2664f9d96f" +checksum = "3c2709a32915d816a6e8f625bf72cf74523ebe5d8829f895d6b041b1d3137818" dependencies = [ "async-trait", "bytes", @@ -3688,22 +3724,22 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.4" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d4c6bec4909c966f59f52db3655c0e9d4685faae8b49185973d9d7389bb884" +checksum = "3a9a4b2eaba8cc928f49c4ccf4fcfa65b690a73997682da99ed08f3393b51f07" dependencies = [ "heck 0.5.0", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "jsonrpsee-server" -version = "0.24.4" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebe2198e5fd96cf2153ecc123364f699b6e2151317ea09c7bf799c43c2fe1415" +checksum = "e30110d0f2d7866c8cc6c86483bdab2eb9f4d2f0e20db55518b2bca84651ba8e" dependencies = [ "futures-util", "http 1.1.0", @@ -3728,9 +3764,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.4" +version = "0.24.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531e386460425e49679587871a056f2895a47dade21457324ad1262cd78ef6d9" +checksum = "1ca331cd7b3fe95b33432825c2d4c9f5a43963e207fdc01ae67f9fd80ab0930f" dependencies = [ "http 1.1.0", "serde", @@ -3740,9 +3776,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -3814,9 +3850,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" @@ -3865,7 +3901,7 @@ dependencies = [ "libp2p-wasm-ext", "libp2p-websocket", "libp2p-yamux", - "multiaddr 0.18.1", + "multiaddr 0.18.2", "pin-project", "rw-stream-sink", "thiserror", @@ -3908,7 +3944,7 @@ dependencies = [ "instant", "libp2p-identity", "log", - "multiaddr 0.18.1", + "multiaddr 0.18.2", "multihash 0.19.1", "multistream-select", "once_cell", @@ -3954,7 +3990,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "lru 0.12.4", + "lru 0.12.5", "quick-protobuf", "quick-protobuf-codec", "smallvec", @@ -4004,7 +4040,7 @@ dependencies = [ "sha2 0.10.8", "smallvec", "thiserror", - "uint", + "uint 0.9.5", "unsigned-varint 0.7.2", "void", ] @@ -4059,7 +4095,7 @@ dependencies = [ "libp2p-core", "libp2p-identity", "log", - "multiaddr 0.18.1", + "multiaddr 0.18.2", "multihash 0.19.1", "once_cell", "quick-protobuf", @@ -4165,7 +4201,7 @@ dependencies = [ "proc-macro-warning 0.4.2", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4276,7 +4312,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.6.0", "libc", - "redox_syscall 0.5.4", + "redox_syscall 0.5.7", ] [[package]] @@ -4424,7 +4460,7 @@ dependencies = [ "futures", "futures-timer", "hex-literal", - "indexmap 2.5.0", + "indexmap 2.6.0", "libc", "mockall 0.12.1", "multiaddr 0.17.1", @@ -4455,7 +4491,7 @@ dependencies = [ "tokio-util", "tracing", "trust-dns-resolver", - "uint", + "uint 0.9.5", "unsigned-varint 0.8.0", "url", "webpki", @@ -4492,11 +4528,11 @@ dependencies = [ [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -4510,18 +4546,18 @@ dependencies = [ [[package]] name = "lz4" -version = "1.27.0" +version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a231296ca742e418c43660cb68e082486ff2538e8db432bc818580f3965025ed" +checksum = "4d1febb2b4a79ddd1980eede06a8f7902197960aa0383ffcfdd62fe723036725" dependencies = [ "lz4-sys", ] [[package]] name = "lz4-sys" -version = "1.11.0" +version = "1.11.1+lz4-1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb44a01837a858d47e5a630d2ccf304c8efcc4b83b8f9f75b7a9ee4fcc6e57d" +checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6" dependencies = [ "cc", "libc", @@ -4545,7 +4581,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4559,7 +4595,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4570,7 +4606,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4581,7 +4617,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4795,7 +4831,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4819,9 +4855,9 @@ dependencies = [ [[package]] name = "multiaddr" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b852bc02a2da5feed68cd14fa50d0774b92790a5bdbfa932a813926c8472070" +checksum = "fe6351f60b488e04c1d21bc69e56b89cb3f5e8f5d22557d6e8031bdfd79b6961" dependencies = [ "arrayref", "byteorder", @@ -4832,7 +4868,7 @@ dependencies = [ "percent-encoding", "serde", "static_assertions", - "unsigned-varint 0.7.2", + "unsigned-varint 0.8.0", "url", ] @@ -4955,7 +4991,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5330,9 +5366,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] @@ -5357,9 +5393,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" @@ -5396,7 +5432,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5915,7 +5951,7 @@ dependencies = [ "lru 0.8.1", "parity-util-mem-derive", "parking_lot 0.12.3", - "primitive-types", + "primitive-types 0.12.2", "smallvec", "winapi", ] @@ -5986,7 +6022,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.4", + "redox_syscall 0.5.7", "smallvec", "windows-targets 0.52.6", ] @@ -6047,9 +6083,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea" +checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", "thiserror", @@ -6058,9 +6094,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d" +checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0" dependencies = [ "pest", "pest_generator", @@ -6068,22 +6104,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe" +checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "pest_meta" -version = "2.7.12" +version = "2.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174" +checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f" dependencies = [ "once_cell", "pest", @@ -6097,27 +6133,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.5.0", + "indexmap 2.6.0", ] [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6144,9 +6180,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polkavm" @@ -6197,7 +6233,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6207,7 +6243,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6271,9 +6307,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.7.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "powerfmt" @@ -6347,7 +6383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6357,11 +6393,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", - "impl-codec", + "impl-codec 0.6.0", "impl-rlp", "impl-serde", "scale-info", - "uint", + "uint 0.9.5", +] + +[[package]] +name = "primitive-types" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" +dependencies = [ + "fixed-hash", + "impl-codec 0.7.0", + "impl-num-traits", + "uint 0.10.0", ] [[package]] @@ -6415,7 +6463,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6426,14 +6474,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -6454,7 +6502,7 @@ dependencies = [ "quote", "regex", "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6491,7 +6539,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6553,7 +6601,7 @@ dependencies = [ "prost 0.12.6", "prost-types 0.12.6", "regex", - "syn 2.0.77", + "syn 2.0.79", "tempfile", ] @@ -6580,7 +6628,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6816,9 +6864,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.1.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ "bitflags 2.6.0", ] @@ -6872,9 +6920,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -6907,7 +6955,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -6937,14 +6985,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", ] [[package]] @@ -6958,13 +7006,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax 0.8.5", ] [[package]] @@ -6975,9 +7023,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "resolv-conf" @@ -7373,7 +7421,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -7719,7 +7767,7 @@ dependencies = [ "futures-timer", "log", "mixnet", - "multiaddr 0.18.1", + "multiaddr 0.18.2", "parity-scale-codec", "parking_lot 0.12.3", "sc-client-api", @@ -7910,7 +7958,7 @@ dependencies = [ "libp2p-identity", "litep2p", "log", - "multiaddr 0.18.1", + "multiaddr 0.18.2", "multihash 0.19.1", "rand", "thiserror", @@ -8221,7 +8269,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -8339,9 +8387,9 @@ checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -8470,9 +8518,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -8552,7 +8600,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -8569,9 +8617,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -8601,7 +8649,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -8861,7 +8909,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9022,7 +9070,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "paste", - "primitive-types", + "primitive-types 0.12.2", "rand", "scale-info", "schnorrkel", @@ -9046,7 +9094,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -9097,7 +9145,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1#a42 dependencies = [ "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9116,17 +9164,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1#a42 dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9142,7 +9190,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "environmental", "parity-scale-codec", @@ -9316,7 +9364,7 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "polkavm-derive", - "primitive-types", + "primitive-types 0.12.2", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1)", @@ -9329,13 +9377,13 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec", "polkavm-derive", - "primitive-types", + "primitive-types 0.13.1", "sp-externalities 0.25.0 (git+https://github.com/paritytech/polkadot-sdk)", "sp-runtime-interface-proc-macro 17.0.0 (git+https://github.com/paritytech/polkadot-sdk)", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", @@ -9355,20 +9403,20 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "Inflector", "expander", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9450,7 +9498,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=v1.16.0-rc1#a42 [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" [[package]] name = "sp-storage" @@ -9467,7 +9515,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "impl-serde", "parity-scale-codec", @@ -9502,7 +9550,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "parity-scale-codec", "tracing", @@ -9581,7 +9629,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9599,7 +9647,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#310ef5ce1086affdc522c4d1736211de2a7dd99e" +source = "git+https://github.com/paritytech/polkadot-sdk#90ff47d989b0498e4e88366b432486e06b1398d8" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -9654,9 +9702,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.50.0" +version = "1.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43fce22ed1df64d04b262351c8f9d5c6da4f76f79f25ad15529792f893fad25d" +checksum = "19409f13998e55816d1c728395af0b52ec066206341d939e22e7766df9b494b8" dependencies = [ "Inflector", "num-format", @@ -9771,7 +9819,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9877,7 +9925,7 @@ dependencies = [ "rayon", "subtensor-code-coverage", "subtensor-linting", - "syn 2.0.77", + "syn 2.0.79", "walkdir", ] @@ -9890,7 +9938,7 @@ dependencies = [ "procedural-fork", "quote", "rayon", - "syn 2.0.77", + "syn 2.0.79", "walkdir", ] @@ -9926,7 +9974,7 @@ dependencies = [ "proc-macro2", "procedural-fork", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9936,7 +9984,7 @@ dependencies = [ "ahash 0.8.11", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -9974,9 +10022,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -10003,7 +10051,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -10041,9 +10089,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -10063,12 +10111,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" dependencies = [ "rustix 0.38.37", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -10079,22 +10127,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -10213,7 +10261,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -10299,11 +10347,11 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.21" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", @@ -10320,7 +10368,6 @@ dependencies = [ "futures-util", "pin-project", "pin-project-lite", - "tokio", "tower-layer", "tower-service", "tracing", @@ -10374,7 +10421,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -10582,9 +10629,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "uint" @@ -10598,11 +10645,23 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uint" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" @@ -10621,15 +10680,15 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unicode-xid" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "universal-hash" @@ -10793,7 +10852,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -10827,7 +10886,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -11451,9 +11510,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -11580,7 +11639,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -11600,7 +11659,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] From 867e2520fe2a95ce2d0e60a3708fd87fff7f7fbb Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 10 Oct 2024 17:30:09 +0800 Subject: [PATCH 42/45] Upgrade benchmarking v1 syntax to v2 --- .../src/{benchmarks.rs => benchmarking.rs} | 225 +++++++++++------- pallets/subtensor/src/lib.rs | 2 +- 2 files changed, 134 insertions(+), 93 deletions(-) rename pallets/subtensor/src/{benchmarks.rs => benchmarking.rs} (79%) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarking.rs similarity index 79% rename from pallets/subtensor/src/benchmarks.rs rename to pallets/subtensor/src/benchmarking.rs index 4915bb3ac..8ea02d074 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarking.rs @@ -3,21 +3,22 @@ #![cfg(feature = "runtime-benchmarks")] use crate::Pallet as Subtensor; -use crate::*; -use frame_benchmarking::{account, benchmarks, whitelisted_caller}; +use super::*; +use frame_benchmarking::v2::*; use frame_support::assert_ok; use frame_system::RawOrigin; -pub use pallet::*; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; use sp_std::vec; -benchmarks! { - // Add individual benchmarks here - benchmark_register { +#[benchmarks] +mod benchmarks { + use super::*; + + #[benchmark] + fn register() { let netuid: u16 = 1; //11 is the benchmark network. let tempo: u16 = 1; - let modality: u16 = 0; let hotkey: T::AccountId = account("Alice", 0, 1); let coldkey: T::AccountId = account("Test", 0, 2); @@ -33,16 +34,17 @@ benchmarks! { &hotkey, ); + #[extrinsic_call] + _( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() ); + } - }: register( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() ) - - benchmark_set_weights { + #[benchmark] + fn set_weights() { // This is a whitelisted caller who can make transaction without weights. let netuid: u16 = 1; let version_key: u64 = 1; let tempo: u16 = 1; - let modality: u16 = 0; Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_max_allowed_uids( netuid, 4096 ); @@ -61,11 +63,11 @@ benchmarks! { let coldkey: T::AccountId = account("Test", 0, seed); seed += 1; - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())?; + Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone()).unwrap(); let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); Subtensor::::set_validator_permit_for_uid(netuid, uid, true); @@ -73,17 +75,15 @@ benchmarks! { weights.push(id); } - }: set_weights(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key) - + #[extrinsic_call] + _(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key); + } - benchmark_become_delegate { + #[benchmark] + fn become_delegate() { // This is a whitelisted caller who can make transaction without weights. - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); let netuid: u16 = 1; - let version_key: u64 = 1; let tempo: u16 = 1; - let modality: u16 = 0; let seed : u32 = 1; Subtensor::::init_new_network(netuid, tempo); @@ -100,15 +100,15 @@ benchmarks! { Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: become_delegate(RawOrigin::Signed( coldkey.clone() ), hotkey.clone()) - benchmark_add_stake { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + #[extrinsic_call] + _(RawOrigin::Signed( coldkey.clone() ), hotkey.clone()); + } + + #[benchmark] + fn add_stake() { let netuid: u16 = 1; - let version_key: u64 = 1; let tempo: u16 = 1; - let modality: u16 = 0; let seed : u32 = 1; Subtensor::::set_target_stakes_per_interval(100); @@ -129,15 +129,15 @@ benchmarks! { Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: add_stake(RawOrigin::Signed( coldkey.clone() ), hotkey, amount) - benchmark_remove_stake{ - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + #[extrinsic_call] + _(RawOrigin::Signed( coldkey.clone() ), hotkey, amount); + } + + #[benchmark] + fn remove_stake() { let netuid: u16 = 1; - let version_key: u64 = 1; let tempo: u16 = 1; - let modality: u16 = 0; let seed : u32 = 1; Subtensor::::set_target_stakes_per_interval(100); @@ -168,14 +168,17 @@ benchmarks! { assert_ok!( Subtensor::::add_stake(RawOrigin::Signed( coldkey.clone() ).into() , hotkey.clone(), u64_staked_amt)); let amount_unstaked: u64 = u64_staked_amt - 1; - }: remove_stake(RawOrigin::Signed( coldkey.clone() ), hotkey.clone(), amount_unstaked) - benchmark_serve_axon{ + #[extrinsic_call] + _(RawOrigin::Signed( coldkey.clone() ), hotkey.clone(), amount_unstaked); + } + + #[benchmark] + fn serve_axon() { let caller: T::AccountId = whitelisted_caller::>(); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); let netuid: u16 = 1; let tempo: u16 = 1; - let modality: u16 = 0; let version: u32 = 2; let ip: u128 = 1676056785; @@ -197,14 +200,16 @@ benchmarks! { Subtensor::::set_serving_rate_limit(netuid, 0); - }: serve_axon(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type, protocol, placeholder1, placeholder2) + #[extrinsic_call] + _(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type, protocol, placeholder1, placeholder2); + } - benchmark_serve_prometheus { + #[benchmark] + fn serve_prometheus() { let caller: T::AccountId = whitelisted_caller::>(); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); let netuid: u16 = 1; let tempo: u16 = 1; - let modality: u16 = 0; let version: u32 = 2; let ip: u128 = 1676056785; @@ -222,7 +227,9 @@ benchmarks! { assert_ok!(Subtensor::::do_burned_registration(caller_origin.clone(), netuid, caller.clone())); Subtensor::::set_serving_rate_limit(netuid, 0); - }: serve_prometheus(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type) + #[extrinsic_call] + _(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type); + } /* benchmark_sudo_register { @@ -248,12 +255,12 @@ benchmarks! { }: sudo_register(RawOrigin::>::Root, netuid, hotkey, coldkey, stake, balance) */ - benchmark_burned_register { + #[benchmark] + fn burned_register() { let netuid: u16 = 1; let seed : u32 = 1; let hotkey: T::AccountId = account("Alice", 0, seed); let coldkey: T::AccountId = account("Test", 0, seed); - let modality: u16 = 0; let tempo: u16 = 1; Subtensor::::init_new_network(netuid, tempo); @@ -262,12 +269,13 @@ benchmarks! { let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - }: burned_register(RawOrigin::Signed( coldkey.clone() ), netuid, hotkey) - + #[extrinsic_call] + _(RawOrigin::Signed( coldkey.clone() ), netuid, hotkey); + } - benchmark_root_register { + #[benchmark] + fn root_register() { let netuid: u16 = 1; - let version_key: u64 = 1; let tempo: u16 = 1; let seed : u32 = 1; @@ -282,38 +290,45 @@ benchmarks! { let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); - let amount: u64 = 1; let amount_to_be_staked = 100_000_000_000_000u64; Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - }: root_register(RawOrigin::Signed(coldkey), hotkey) - benchmark_register_network { + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey); + } + + #[benchmark] + fn register_network() { let seed : u32 = 1; let coldkey: T::AccountId = account("Test", 0, seed); Subtensor::::set_network_rate_limit(1); - let amount: u64 = 1; let amount_to_be_staked = 100_000_000_000_000u64; Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - }: register_network(RawOrigin::Signed(coldkey)) - benchmark_dissolve_network { + #[extrinsic_call] + _(RawOrigin::Signed(coldkey)); + } + + #[benchmark] + fn dissolve_network() { let seed : u32 = 1; let coldkey: T::AccountId = account("Test", 0, seed); Subtensor::::set_network_rate_limit(0); - let amount: u64 = 1; let amount_to_be_staked = 100_000_000_000_000u64; Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); assert_ok!(Subtensor::::register_network(RawOrigin::Signed(coldkey.clone()).into())); - }: dissolve_network(RawOrigin::Root, coldkey.clone(), 1) + #[extrinsic_call] + _(RawOrigin::Root, coldkey.clone(), 1); + } // swap_hotkey { // let seed: u32 = 1; @@ -343,7 +358,8 @@ benchmarks! { // } // }: _(RawOrigin::Signed(coldkey), old_hotkey, new_hotkey) - commit_weights { + #[benchmark] + fn commit_weights() { let tempo: u16 = 1; let netuid: u16 = 1; let version_key: u64 = 0; @@ -370,7 +386,7 @@ benchmarks! { start_nonce, &hotkey, ); - let result = Subtensor::::register( + Subtensor::::register( ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, block_number, @@ -378,12 +394,16 @@ benchmarks! { work, hotkey.clone(), coldkey, - ); + ) + .unwrap(); Subtensor::::set_validator_permit_for_uid(netuid, 0, true); -}: commit_weights(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash) + #[extrinsic_call] + _(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash); + } -reveal_weights { + #[benchmark] + fn reveal_weights() { let tempo: u16 = 0; let netuid: u16 = 1; let version_key: u64 = 0; @@ -425,46 +445,66 @@ reveal_weights { weight_values.clone(), salt.clone(), version_key, - )); + )); let _ = Subtensor::::commit_weights(::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash); - }: reveal_weights(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key) + #[extrinsic_call] + _(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key); + } - schedule_swap_coldkey { + #[benchmark] + fn schedule_swap_coldkey() { let old_coldkey: T::AccountId = account("old_cold", 0, 1); let new_coldkey: T::AccountId = account("new_cold", 1, 2); - }: schedule_swap_coldkey(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()) - schedule_dissolve_network { - let coldkey: T::AccountId = account("coldkey", 0, 1); - let netuid = 1; - }: schedule_dissolve_network(RawOrigin::Signed(coldkey.clone()), netuid) - benchmark_sudo_set_tx_childkey_take_rate_limit { + #[extrinsic_call] + _(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()); + } + + #[benchmark] + fn schedule_dissolve_network() { + let coldkey: T::AccountId = account("coldkey", 0, 1); + let netuid = 1; + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), netuid); + } + + #[benchmark] + fn sudo_set_tx_childkey_take_rate_limit() { // We don't need to set up any initial state for this benchmark // as it's a simple setter function that only requires root origin let new_rate_limit: u64 = 100; -}: sudo_set_tx_childkey_take_rate_limit(RawOrigin::Root, new_rate_limit) - - benchmark_set_childkey_take { - // Setup - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed: u32 = 1; - let coldkey: T::AccountId = account("Cold", 0, seed); - let hotkey: T::AccountId = account("Hot", 0, seed); - let take: u16 = 1000; // 10% in basis points - - // Initialize the network - Subtensor::::init_new_network(netuid, tempo); - - // Register the hotkey - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1_000_000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); -}: set_childkey_take(RawOrigin::Signed(coldkey), hotkey, netuid, take) - - swap_coldkey { + + #[extrinsic_call] + _(RawOrigin::Root, new_rate_limit); + } + + #[benchmark] + fn set_childkey_take() { + // Setup + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + let coldkey: T::AccountId = account("Cold", 0, seed); + let hotkey: T::AccountId = account("Hot", 0, seed); + let take: u16 = 1000; // 10% in basis points + + // Initialize the network + Subtensor::::init_new_network(netuid, tempo); + + // Register the hotkey + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1_000_000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); + assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey, netuid, take); + } + + #[benchmark] + fn swap_coldkey() { // Set up initial state let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); @@ -519,6 +559,7 @@ reveal_weights { Identities::::insert(&old_coldkey, identity); // Benchmark setup complete, now execute the extrinsic -}: swap_coldkey(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()) - + #[extrinsic_call] + _(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()); + } } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index cc3d7d025..ebd3baefd 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -31,7 +31,7 @@ use sp_std::marker::PhantomData; // ============================ // ==== Benchmark Imports ===== // ============================ -mod benchmarks; +mod benchmarking; // ========================= // ==== Pallet Imports ===== From bdeb29e0551fc10592d378e228ca5ca90a35e977 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 11 Oct 2024 21:59:27 +0800 Subject: [PATCH 43/45] Disallow V1 benchmarks syntax --- build.rs | 1 + pallets/subtensor/src/benchmarking.rs | 1080 +++++++++-------- support/linting/src/disallow_v1_benchmarks.rs | 72 ++ support/linting/src/lib.rs | 2 + 4 files changed, 655 insertions(+), 500 deletions(-) create mode 100644 support/linting/src/disallow_v1_benchmarks.rs diff --git a/build.rs b/build.rs index 28e69f49c..2ec841980 100644 --- a/build.rs +++ b/build.rs @@ -55,6 +55,7 @@ fn main() { } }; + track_lint(DisallowV1Benchmarks::lint(&parsed_file)); track_lint(RequireFreezeStruct::lint(&parsed_file)); track_lint(RequireExplicitPalletIndex::lint(&parsed_file)); }); diff --git a/pallets/subtensor/src/benchmarking.rs b/pallets/subtensor/src/benchmarking.rs index 8ea02d074..7f0fbc370 100644 --- a/pallets/subtensor/src/benchmarking.rs +++ b/pallets/subtensor/src/benchmarking.rs @@ -2,8 +2,8 @@ #![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] #![cfg(feature = "runtime-benchmarks")] -use crate::Pallet as Subtensor; use super::*; +use crate::Pallet as Subtensor; use frame_benchmarking::v2::*; use frame_support::assert_ok; use frame_system::RawOrigin; @@ -13,553 +13,633 @@ use sp_std::vec; #[benchmarks] mod benchmarks { - use super::*; - - #[benchmark] - fn register() { - let netuid: u16 = 1; //11 is the benchmark network. - let tempo: u16 = 1; - let hotkey: T::AccountId = account("Alice", 0, 1); - let coldkey: T::AccountId = account("Test", 0, 2); - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey, - ); - - #[extrinsic_call] - _( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() ); - } - - #[benchmark] - fn set_weights() { - - // This is a whitelisted caller who can make transaction without weights. - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - - Subtensor::::set_network_registration_allowed( netuid, true ); - Subtensor::::set_max_registrations_per_block( netuid, 4096 ); - Subtensor::::set_target_registrations_per_interval( netuid, 4096 ); - - let mut seed : u32 = 1; - let mut dests: Vec = vec![]; - let mut weights: Vec = vec![]; - let signer : T::AccountId = account("Alice", 0, seed); - - for id in 0..4096_u16 { - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - seed += 1; + use super::*; + + #[benchmark] + fn register() { + let netuid: u16 = 1; //11 is the benchmark network. + let tempo: u16 = 1; + let hotkey: T::AccountId = account("Alice", 0, 1); + let coldkey: T::AccountId = account("Test", 0, 2); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey); + + #[extrinsic_call] + _( + RawOrigin::Signed(hotkey.clone()), + netuid, + block_number, + nonce, + work, + hotkey.clone(), + coldkey.clone(), + ); + } - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + #[benchmark] + fn set_weights() { + // This is a whitelisted caller who can make transaction without weights. + let netuid: u16 = 1; + let version_key: u64 = 1; + let tempo: u16 = 1; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_max_registrations_per_block(netuid, 4096); + Subtensor::::set_target_registrations_per_interval(netuid, 4096); + + let mut seed: u32 = 1; + let mut dests: Vec = vec![]; + let mut weights: Vec = vec![]; + let signer: T::AccountId = account("Alice", 0, seed); + + for id in 0..4096_u16 { + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); + seed += 1; + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + + Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone(), + ) + .unwrap(); + + let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); + Subtensor::::set_validator_permit_for_uid(netuid, uid, true); + dests.push(id); + weights.push(id); + } + + #[extrinsic_call] + _( + RawOrigin::Signed(signer.clone()), + netuid, + dests, + weights, + version_key, + ); + } - Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone()).unwrap(); + #[benchmark] + fn become_delegate() { + // This is a whitelisted caller who can make transaction without weights. + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; - let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); - Subtensor::::set_validator_permit_for_uid(netuid, uid, true); - dests.push(id); - weights.push(id); - } + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_max_allowed_uids(netuid, 4096); - #[extrinsic_call] - _(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key); - } + Subtensor::::set_network_registration_allowed(netuid, true); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - #[benchmark] - fn become_delegate() { - // This is a whitelisted caller who can make transaction without weights. - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed : u32 = 1; + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); + let amount_to_be_staked = 1000000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - Subtensor::::set_network_registration_allowed( netuid, true); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), hotkey.clone()); + } - let amount_to_be_staked = 1000000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + #[benchmark] + fn add_stake() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); + Subtensor::::set_target_stakes_per_interval(100); - #[extrinsic_call] - _(RawOrigin::Signed( coldkey.clone() ), hotkey.clone()); - } + Subtensor::::init_new_network(netuid, tempo); - #[benchmark] - fn add_stake() { - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed : u32 = 1; + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_target_stakes_per_interval(100); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - Subtensor::::init_new_network(netuid, tempo); + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_network_registration_allowed( netuid, true ); + let amount: u64 = 1; + let amount_to_be_staked = 1000000000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), hotkey, amount); + } - let amount: u64 = 1; - let amount_to_be_staked = 1000000000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + #[benchmark] + fn remove_stake() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + + Subtensor::::set_target_stakes_per_interval(100); + + // Set our total stake to 1000 TAO + Subtensor::::increase_total_stake(1_000_000_000_000); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); + Subtensor::::set_burn(netuid, 1); + + let wallet_bal = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); + + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + assert_ok!(Subtensor::::do_become_delegate( + RawOrigin::Signed(coldkey.clone()).into(), + hotkey.clone(), + Subtensor::::get_default_delegate_take() + )); + + // Stake 10% of our current total staked TAO + let u64_staked_amt = 100_000_000_000; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), u64_staked_amt); + + assert_ok!(Subtensor::::add_stake( + RawOrigin::Signed(coldkey.clone()).into(), + hotkey.clone(), + u64_staked_amt + )); + + let amount_unstaked: u64 = u64_staked_amt - 1; + + #[extrinsic_call] + _( + RawOrigin::Signed(coldkey.clone()), + hotkey.clone(), + amount_unstaked, + ); + } - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); + #[benchmark] + fn serve_axon() { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 1; + + let version: u32 = 2; + let ip: u128 = 1676056785; + let port: u16 = 128; + let ip_type: u8 = 4; + let protocol: u8 = 0; + let placeholder1: u8 = 0; + let placeholder2: u8 = 0; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + caller_origin.clone(), + netuid, + caller.clone() + )); + + Subtensor::::set_serving_rate_limit(netuid, 0); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + netuid, + version, + ip, + port, + ip_type, + protocol, + placeholder1, + placeholder2, + ); + } - #[extrinsic_call] - _(RawOrigin::Signed( coldkey.clone() ), hotkey, amount); - } + #[benchmark] + fn serve_prometheus() { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = + ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 1; + + let version: u32 = 2; + let ip: u128 = 1676056785; + let port: u16 = 128; + let ip_type: u8 = 4; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + + assert_ok!(Subtensor::::do_burned_registration( + caller_origin.clone(), + netuid, + caller.clone() + )); + Subtensor::::set_serving_rate_limit(netuid, 0); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller.clone()), + netuid, + version, + ip, + port, + ip_type, + ); + } - #[benchmark] - fn remove_stake() { - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed : u32 = 1; + /* + benchmark_sudo_register { + let caller: T::AccountId = whitelisted_caller::>(); + let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + let netuid: u16 = 1; + let tempo: u16 = 0; + let modality: u16 = 0; + let stake: u64 = 10; + let balance: u64 = 1000000000; + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_max_allowed_uids( netuid, 4096 ); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + + let seed : u32 = 1; + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); - Subtensor::::set_target_stakes_per_interval(100); + let amount_to_be_staked = balance.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - // Set our total stake to 1000 TAO - Subtensor::::increase_total_stake(1_000_000_000_000); + }: sudo_register(RawOrigin::>::Root, netuid, hotkey, coldkey, stake, balance) + */ + #[benchmark] + fn burned_register() { + let netuid: u16 = 1; + let seed: u32 = 1; + let hotkey: T::AccountId = account("Alice", 0, seed); + let coldkey: T::AccountId = account("Test", 0, seed); + let tempo: u16 = 1; - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed( netuid, true ); + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_burn(netuid, 1); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + let amount_to_be_staked = 1000000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - Subtensor::::set_burn(netuid, 1); + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), netuid, hotkey); + } - let wallet_bal = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); + #[benchmark] + fn root_register() { + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - assert_ok!(Subtensor::::do_become_delegate(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone(), Subtensor::::get_default_delegate_take())); + Subtensor::::init_new_network(netuid, tempo); - // Stake 10% of our current total staked TAO - let u64_staked_amt = 100_000_000_000; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), u64_staked_amt); + Subtensor::::set_burn(netuid, 1); + Subtensor::::set_network_registration_allowed(netuid, true); - assert_ok!( Subtensor::::add_stake(RawOrigin::Signed( coldkey.clone() ).into() , hotkey.clone(), u64_staked_amt)); + Subtensor::::set_max_allowed_uids(netuid, 4096); + assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - let amount_unstaked: u64 = u64_staked_amt - 1; + let coldkey: T::AccountId = account("Test", 0, seed); + let hotkey: T::AccountId = account("Alice", 0, seed); - #[extrinsic_call] - _(RawOrigin::Signed( coldkey.clone() ), hotkey.clone(), amount_unstaked); - } + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - #[benchmark] - fn serve_axon() { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 1; + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); - let version: u32 = 2; - let ip: u128 = 1676056785; - let port: u16 = 128; - let ip_type: u8 = 4; - let protocol: u8 = 0; - let placeholder1: u8 = 0; - let placeholder2: u8 = 0; + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey); + } - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + #[benchmark] + fn register_network() { + let seed: u32 = 1; - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + let coldkey: T::AccountId = account("Test", 0, seed); - assert_ok!(Subtensor::::do_burned_registration(caller_origin.clone(), netuid, caller.clone())); + Subtensor::::set_network_rate_limit(1); - Subtensor::::set_serving_rate_limit(netuid, 0); + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - #[extrinsic_call] - _(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type, protocol, placeholder1, placeholder2); - } + #[extrinsic_call] + _(RawOrigin::Signed(coldkey)); + } - #[benchmark] - fn serve_prometheus() { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 1; + #[benchmark] + fn dissolve_network() { + let seed: u32 = 1; - let version: u32 = 2; - let ip: u128 = 1676056785; - let port: u16 = 128; - let ip_type: u8 = 4; + let coldkey: T::AccountId = account("Test", 0, seed); - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + Subtensor::::set_network_rate_limit(0); - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); + let amount_to_be_staked = 100_000_000_000_000u64; + Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + assert_ok!(Subtensor::::register_network( + RawOrigin::Signed(coldkey.clone()).into() + )); - assert_ok!(Subtensor::::do_burned_registration(caller_origin.clone(), netuid, caller.clone())); - Subtensor::::set_serving_rate_limit(netuid, 0); + #[extrinsic_call] + _(RawOrigin::Root, coldkey.clone(), 1); + } - #[extrinsic_call] - _(RawOrigin::Signed( caller.clone() ), netuid, version, ip, port, ip_type); - } + // swap_hotkey { + // let seed: u32 = 1; + // let coldkey: T::AccountId = account("Alice", 0, seed); + // let old_hotkey: T::AccountId = account("Bob", 0, seed); + // let new_hotkey: T::AccountId = account("Charlie", 0, seed); + + // let netuid = 1u16; + // Subtensor::::init_new_network(netuid, 100); + // Subtensor::::set_min_burn(netuid, 1); + // Subtensor::::set_max_burn(netuid, 1); + // Subtensor::::set_target_registrations_per_interval(netuid, 256); + // Subtensor::::set_max_registrations_per_block(netuid, 256); + + // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); + // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, old_hotkey.clone())); + // assert_ok!(Subtensor::::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), old_hotkey.clone())); + + // let max_uids = Subtensor::::get_max_allowed_uids(netuid) as u32; + // for i in 0..max_uids - 1 { + // let coldkey: T::AccountId = account("Axon", 0, i); + // let hotkey: T::AccountId = account("Hotkey", 0, i); + + // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); + // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey)); + // assert_ok!(Subtensor::::add_stake(RawOrigin::Signed(coldkey).into(), old_hotkey.clone(), 1_000_000_000)); + // } + // }: _(RawOrigin::Signed(coldkey), old_hotkey, new_hotkey) + + #[benchmark] + fn commit_weights() { + let tempo: u16 = 1; + let netuid: u16 = 1; + let version_key: u64 = 0; + let uids: Vec = vec![0]; + let weight_values: Vec = vec![10]; + let hotkey: T::AccountId = account("hot", 0, 1); + let coldkey: T::AccountId = account("cold", 0, 2); + let start_nonce = 300000; + + let commit_hash: H256 = BlakeTwo256::hash_of(&( + hotkey.clone(), + netuid, + uids.clone(), + weight_values.clone(), + version_key, + )); + + Subtensor::::init_new_network(netuid, tempo); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( + netuid, + block_number, + start_nonce, + &hotkey, + ); + Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + block_number, + nonce, + work, + hotkey.clone(), + coldkey, + ) + .unwrap(); + Subtensor::::set_validator_permit_for_uid(netuid, 0, true); + + #[extrinsic_call] + _(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash); + } - /* - benchmark_sudo_register { - let caller: T::AccountId = whitelisted_caller::>(); - let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - let netuid: u16 = 1; - let tempo: u16 = 0; - let modality: u16 = 0; - let stake: u64 = 10; - let balance: u64 = 1000000000; + #[benchmark] + fn reveal_weights() { + let tempo: u16 = 0; + let netuid: u16 = 1; + let version_key: u64 = 0; + let uids: Vec = vec![0]; + let weight_values: Vec = vec![10]; + let salt: Vec = vec![8]; + let hotkey: T::AccountId = account("hot", 0, 1); + let coldkey: T::AccountId = account("cold", 1, 2); + + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey); + + let _ = Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + block_number, + nonce, + work.clone(), + hotkey.clone(), + coldkey.clone(), + ); + + Subtensor::::set_validator_permit_for_uid(netuid, 0, true); + Subtensor::::set_commit_reveal_weights_interval(netuid, 0); + + let commit_hash: H256 = BlakeTwo256::hash_of(&( + hotkey.clone(), + netuid, + uids.clone(), + weight_values.clone(), + salt.clone(), + version_key, + )); + let _ = Subtensor::::commit_weights( + ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), + netuid, + commit_hash, + ); + + #[extrinsic_call] + _( + RawOrigin::Signed(hotkey.clone()), + netuid, + uids, + weight_values, + salt, + version_key, + ); + } - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + #[benchmark] + fn schedule_swap_coldkey() { + let old_coldkey: T::AccountId = account("old_cold", 0, 1); + let new_coldkey: T::AccountId = account("new_cold", 1, 2); - let seed : u32 = 1; - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); + #[extrinsic_call] + _(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()); + } - let amount_to_be_staked = balance.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); + #[benchmark] + fn schedule_dissolve_network() { + let coldkey: T::AccountId = account("coldkey", 0, 1); + let netuid = 1; - }: sudo_register(RawOrigin::>::Root, netuid, hotkey, coldkey, stake, balance) - */ - #[benchmark] - fn burned_register() { - let netuid: u16 = 1; - let seed : u32 = 1; - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - let tempo: u16 = 1; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); - - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - #[extrinsic_call] - _(RawOrigin::Signed( coldkey.clone() ), netuid, hotkey); - } - - #[benchmark] - fn root_register() { - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed : u32 = 1; - - Subtensor::::init_new_network(netuid, tempo); - - Subtensor::::set_burn(netuid, 1); - Subtensor::::set_network_registration_allowed( netuid, true); - - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); - - let coldkey: T::AccountId = account("Test", 0, seed); - let hotkey: T::AccountId = account("Alice", 0, seed); - - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - - #[extrinsic_call] - _(RawOrigin::Signed(coldkey), hotkey); - } - - #[benchmark] - fn register_network() { - let seed : u32 = 1; - - let coldkey: T::AccountId = account("Test", 0, seed); - - Subtensor::::set_network_rate_limit(1); - - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - #[extrinsic_call] - _(RawOrigin::Signed(coldkey)); - } - - #[benchmark] - fn dissolve_network() { - let seed : u32 = 1; - - let coldkey: T::AccountId = account("Test", 0, seed); - - Subtensor::::set_network_rate_limit(0); - - let amount_to_be_staked = 100_000_000_000_000u64; - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - assert_ok!(Subtensor::::register_network(RawOrigin::Signed(coldkey.clone()).into())); - - #[extrinsic_call] - _(RawOrigin::Root, coldkey.clone(), 1); - } - - // swap_hotkey { - // let seed: u32 = 1; - // let coldkey: T::AccountId = account("Alice", 0, seed); - // let old_hotkey: T::AccountId = account("Bob", 0, seed); - // let new_hotkey: T::AccountId = account("Charlie", 0, seed); - - // let netuid = 1u16; - // Subtensor::::init_new_network(netuid, 100); - // Subtensor::::set_min_burn(netuid, 1); - // Subtensor::::set_max_burn(netuid, 1); - // Subtensor::::set_target_registrations_per_interval(netuid, 256); - // Subtensor::::set_max_registrations_per_block(netuid, 256); - - // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); - // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, old_hotkey.clone())); - // assert_ok!(Subtensor::::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), old_hotkey.clone())); - - // let max_uids = Subtensor::::get_max_allowed_uids(netuid) as u32; - // for i in 0..max_uids - 1 { - // let coldkey: T::AccountId = account("Axon", 0, i); - // let hotkey: T::AccountId = account("Hotkey", 0, i); - - // Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), 10_000_000_000u64); - // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey)); - // assert_ok!(Subtensor::::add_stake(RawOrigin::Signed(coldkey).into(), old_hotkey.clone(), 1_000_000_000)); - // } - // }: _(RawOrigin::Signed(coldkey), old_hotkey, new_hotkey) - - #[benchmark] - fn commit_weights() { - let tempo: u16 = 1; - let netuid: u16 = 1; - let version_key: u64 = 0; - let uids: Vec = vec![0]; - let weight_values: Vec = vec![10]; - let hotkey: T::AccountId = account("hot", 0, 1); - let coldkey: T::AccountId = account("cold", 0, 2); - let start_nonce = 300000; - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey.clone(), - netuid, - uids.clone(), - weight_values.clone(), - version_key, - )); - - Subtensor::::init_new_network(netuid, tempo); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - start_nonce, - &hotkey, - ); - Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), - netuid, - block_number, - nonce, - work, - hotkey.clone(), - coldkey, - ) - .unwrap(); - Subtensor::::set_validator_permit_for_uid(netuid, 0, true); - - #[extrinsic_call] - _(RawOrigin::Signed(hotkey.clone()), netuid, commit_hash); - } - - #[benchmark] - fn reveal_weights() { - let tempo: u16 = 0; - let netuid: u16 = 1; - let version_key: u64 = 0; - let uids: Vec = vec![0]; - let weight_values: Vec = vec![10]; - let salt: Vec = vec![8]; - let hotkey: T::AccountId = account("hot", 0, 1); - let coldkey: T::AccountId = account("cold", 1, 2); - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey, - ); - - let _ = Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), - netuid, - block_number, - nonce, - work.clone(), - hotkey.clone(), - coldkey.clone(), - ); - - Subtensor::::set_validator_permit_for_uid(netuid, 0, true); - Subtensor::::set_commit_reveal_weights_interval(netuid, 0); - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey.clone(), - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - let _ = Subtensor::::commit_weights(::RuntimeOrigin::from(RawOrigin::Signed(hotkey.clone())), netuid, commit_hash); - - #[extrinsic_call] - _(RawOrigin::Signed(hotkey.clone()), netuid, uids, weight_values, salt, version_key); - } - - #[benchmark] - fn schedule_swap_coldkey() { - let old_coldkey: T::AccountId = account("old_cold", 0, 1); - let new_coldkey: T::AccountId = account("new_cold", 1, 2); - - #[extrinsic_call] - _(RawOrigin::Signed(old_coldkey.clone()), new_coldkey.clone()); - } - - #[benchmark] - fn schedule_dissolve_network() { - let coldkey: T::AccountId = account("coldkey", 0, 1); - let netuid = 1; - - #[extrinsic_call] - _(RawOrigin::Signed(coldkey.clone()), netuid); - } - - #[benchmark] - fn sudo_set_tx_childkey_take_rate_limit() { - // We don't need to set up any initial state for this benchmark - // as it's a simple setter function that only requires root origin - let new_rate_limit: u64 = 100; - - #[extrinsic_call] - _(RawOrigin::Root, new_rate_limit); - } - - #[benchmark] - fn set_childkey_take() { - // Setup - let netuid: u16 = 1; - let tempo: u16 = 1; - let seed: u32 = 1; - let coldkey: T::AccountId = account("Cold", 0, seed); - let hotkey: T::AccountId = account("Hot", 0, seed); - let take: u16 = 1000; // 10% in basis points - - // Initialize the network - Subtensor::::init_new_network(netuid, tempo); - - // Register the hotkey - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1_000_000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); - assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - - #[extrinsic_call] - _(RawOrigin::Signed(coldkey), hotkey, netuid, take); - } - - #[benchmark] - fn swap_coldkey() { - // Set up initial state - let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); - let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); - let hotkey1: T::AccountId = account("hotkey1", 0, 0); - let netuid = 1u16; - let stake_amount1 = 1000u64; - let stake_amount2 = 2000u64; - let swap_cost = Subtensor::::get_key_swap_cost(); - let free_balance_old = 12345u64 + swap_cost; - let tempo: u16 = 1; - - // Setup initial state - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_network_registration_allowed(netuid, true); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - - let block_number: u64 = Subtensor::::get_current_block_as_u64(); - let (nonce, work): (u64, Vec) = Subtensor::::create_work_for_block_number( - netuid, - block_number, - 3, - &hotkey1, - ); - - let _ = Subtensor::::register( - ::RuntimeOrigin::from(RawOrigin::Signed(old_coldkey.clone())), - netuid, - block_number, - nonce, - work.clone(), - hotkey1.clone(), - old_coldkey.clone(), - ); - - // Add balance to old coldkey - Subtensor::::add_balance_to_coldkey_account( - &old_coldkey, - stake_amount1 + stake_amount2 + free_balance_old, - ); - - // Insert an Identity - let name: Vec = b"The fourth Coolest Identity".to_vec(); - let identity: ChainIdentity = ChainIdentity { - name: name.clone(), - url: vec![], - image: vec![], - discord: vec![], - description: vec![], - additional: vec![], - }; - - Identities::::insert(&old_coldkey, identity); - - // Benchmark setup complete, now execute the extrinsic - #[extrinsic_call] - _(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()); - } + #[extrinsic_call] + _(RawOrigin::Signed(coldkey.clone()), netuid); + } + + #[benchmark] + fn sudo_set_tx_childkey_take_rate_limit() { + // We don't need to set up any initial state for this benchmark + // as it's a simple setter function that only requires root origin + let new_rate_limit: u64 = 100; + + #[extrinsic_call] + _(RawOrigin::Root, new_rate_limit); + } + + #[benchmark] + fn set_childkey_take() { + // Setup + let netuid: u16 = 1; + let tempo: u16 = 1; + let seed: u32 = 1; + let coldkey: T::AccountId = account("Cold", 0, seed); + let hotkey: T::AccountId = account("Hot", 0, seed); + let take: u16 = 1000; // 10% in basis points + + // Initialize the network + Subtensor::::init_new_network(netuid, tempo); + + // Register the hotkey + Subtensor::::set_burn(netuid, 1); + let amount_to_be_staked = 1_000_000u32.into(); + Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); + assert_ok!(Subtensor::::do_burned_registration( + RawOrigin::Signed(coldkey.clone()).into(), + netuid, + hotkey.clone() + )); + + #[extrinsic_call] + _(RawOrigin::Signed(coldkey), hotkey, netuid, take); + } + + #[benchmark] + fn swap_coldkey() { + // Set up initial state + let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); + let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); + let hotkey1: T::AccountId = account("hotkey1", 0, 0); + let netuid = 1u16; + let stake_amount1 = 1000u64; + let stake_amount2 = 2000u64; + let swap_cost = Subtensor::::get_key_swap_cost(); + let free_balance_old = 12345u64 + swap_cost; + let tempo: u16 = 1; + + // Setup initial state + Subtensor::::init_new_network(netuid, tempo); + Subtensor::::set_network_registration_allowed(netuid, true); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + + let block_number: u64 = Subtensor::::get_current_block_as_u64(); + let (nonce, work): (u64, Vec) = + Subtensor::::create_work_for_block_number(netuid, block_number, 3, &hotkey1); + + let _ = Subtensor::::register( + ::RuntimeOrigin::from(RawOrigin::Signed( + old_coldkey.clone(), + )), + netuid, + block_number, + nonce, + work.clone(), + hotkey1.clone(), + old_coldkey.clone(), + ); + + // Add balance to old coldkey + Subtensor::::add_balance_to_coldkey_account( + &old_coldkey, + stake_amount1 + stake_amount2 + free_balance_old, + ); + + // Insert an Identity + let name: Vec = b"The fourth Coolest Identity".to_vec(); + let identity: ChainIdentity = ChainIdentity { + name: name.clone(), + url: vec![], + image: vec![], + discord: vec![], + description: vec![], + additional: vec![], + }; + + Identities::::insert(&old_coldkey, identity); + + // Benchmark setup complete, now execute the extrinsic + #[extrinsic_call] + _(RawOrigin::Root, old_coldkey.clone(), new_coldkey.clone()); + } } diff --git a/support/linting/src/disallow_v1_benchmarks.rs b/support/linting/src/disallow_v1_benchmarks.rs new file mode 100644 index 000000000..593a361f2 --- /dev/null +++ b/support/linting/src/disallow_v1_benchmarks.rs @@ -0,0 +1,72 @@ +use super::*; +use syn::{spanned::Spanned, visit::Visit}; + +pub struct DisallowV1Benchmarks; + +impl Lint for DisallowV1Benchmarks { + fn lint(source: &syn::File) -> Result { + let mut visitor = ExprMacroVisitor::new(); + visitor.visit_file(source); + + if !visitor.errors.is_empty() { + return Err(visitor.errors); + } + + Ok(()) + } +} + +struct ExprMacroVisitor { + errors: Vec, +} + +impl<'ast> syn::visit::Visit<'ast> for ExprMacroVisitor { + fn visit_expr_macro(&mut self, i: &'ast syn::ExprMacro) { + let Some(segment) = i.mac.path.segments.last() else { + return; + }; + + if segment.ident == "benchmarks" { + self.errors.push(syn::Error::new( + segment.span(), + "V1 benchmark syntax is disallowed!".to_owned(), + )); + } + } +} + +impl ExprMacroVisitor { + fn new() -> Self { + Self { errors: Vec::new() } + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used)] +mod tests { + use super::*; + use quote::quote; + + fn lint_macro(input: proc_macro2::TokenStream) -> Result { + let expr_macro: syn::ExprMacro = syn::parse2(input).unwrap(); + let mut visitor = ExprMacroVisitor::new(); + visitor.visit_expr_macro(&expr_macro); + if !visitor.errors.is_empty() { + return Err(visitor.errors); + } + Ok(()) + } + + #[test] + fn test_disallow_benchmarks_v1() { + let input = quote! { + benchmarks! { + benchmark_test { + + }: _(RawOrigin::Root) + } + }; + + lint_macro(input).unwrap_err(); + } +} diff --git a/support/linting/src/lib.rs b/support/linting/src/lib.rs index e5416c1d5..4238bc01c 100644 --- a/support/linting/src/lib.rs +++ b/support/linting/src/lib.rs @@ -1,8 +1,10 @@ pub mod lint; pub use lint::*; +mod disallow_v1_benchmarks; mod pallet_index; mod require_freeze_struct; +pub use disallow_v1_benchmarks::DisallowV1Benchmarks; pub use pallet_index::RequireExplicitPalletIndex; pub use require_freeze_struct::RequireFreezeStruct; From fdd07d5586ccd32c3121443267a0a69939a4147e Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 17 Oct 2024 23:11:58 +0800 Subject: [PATCH 44/45] Collect benchmarks and mark cals inside of them as tested --- support/code-coverage/src/lib.rs | 89 +++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index c69c3001a..979e28b08 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -79,6 +79,7 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec Vec>(); custom_println!("[code-coverage]", green, "found {} tests", tests.len()); + custom_println!("[code-coverage]", green, "found {} benchmarks", benchmarks.len()); custom_println!( "[code-coverage]", @@ -113,6 +115,17 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec>(); coverage.par_sort_by_key(|(_, v)| *v); @@ -207,7 +220,7 @@ pub fn find_tests(rust_files: &[PathBuf]) -> Vec { .into_iter() .map(|f| { let mut method_calls = HashSet::new(); - let mut visitor = CallVisitor { + let mut visitor = MethodCallVisitor { method_calls: &mut method_calls, }; visitor.visit_item_fn(&f); @@ -225,11 +238,65 @@ pub fn find_tests(rust_files: &[PathBuf]) -> Vec { }) } +#[derive(Default, Debug, Clone, PartialEq, Eq)] +pub struct BenchmarkInfo { + pub calls: HashSet, +} + +/// Finds all benchmarks in the given set of rust files, using a parallel map-reduce +pub fn find_benchmarks(rust_files: &[PathBuf]) -> Vec { + rust_files + .par_iter() + .map(|path| { + let Ok(content) = fs::read_to_string(path) else { + return Vec::new(); + }; + let Ok(file) = syn::parse_file(&content) else { + return Vec::new(); + }; + let mut visitor = BenchmarkVisitor { benchmarks: Vec::new() }; + visitor.visit_file(&file); + visitor + .benchmarks + .into_iter() + .map(|f| { + let mut calls = HashSet::new(); + let mut visitor = CallVisitor { + calls: &mut calls, + }; + visitor.visit_item_fn(&f); + BenchmarkInfo { + calls, + } + }) + .collect() + }) + .reduce(Vec::new, |mut acc, mut infos| { + acc.append(&mut infos); + acc + }) +} + pub struct CallVisitor<'a> { - pub method_calls: &'a mut HashSet, + pub calls: &'a mut HashSet, } impl<'ast> Visit<'ast> for CallVisitor<'_> { + fn visit_expr_call(&mut self, i: &'ast syn::ExprCall) { + if let syn::Expr::Path(expr) = &*i.func { + if let Some(seg) = expr.path.segments.last() { + self.calls.insert(seg.ident.to_string()); + } + } + syn::visit::visit_expr_call(self, i); + } +} + +pub struct MethodCallVisitor<'a> { + pub method_calls: &'a mut HashSet, +} + +impl<'ast> Visit<'ast> for MethodCallVisitor<'_> { fn visit_expr_method_call(&mut self, i: &'ast syn::ExprMethodCall) { self.method_calls.insert(i.method.to_string()); syn::visit::visit_expr_method_call(self, i); @@ -260,6 +327,24 @@ impl<'ast> Visit<'ast> for TestVisitor { } } +pub struct BenchmarkVisitor { + pub benchmarks: Vec, +} + +impl<'ast> Visit<'ast> for BenchmarkVisitor { + fn visit_item_fn(&mut self, item_fn: &'ast ItemFn) { + if item_fn.attrs.iter().any(|attr| { + let Some(seg) = attr.path().segments.last() else { + return false; + }; + seg.ident == "benchmark" + }) { + self.benchmarks.push(item_fn.clone()); + } + syn::visit::visit_item_fn(self, item_fn); + } +} + /// Tries to parse a pallet from a module pub fn try_parse_pallet(item_mod: &ItemMod, file_path: &Path, root_path: &Path) -> Option { simulate_manifest_dir("pallets/subtensor", || -> Option { From ba4ed6f18ceb1328df5759abbad404eb468373ed Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 17 Oct 2024 23:24:28 +0800 Subject: [PATCH 45/45] cargo fmt --- support/code-coverage/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/support/code-coverage/src/lib.rs b/support/code-coverage/src/lib.rs index 979e28b08..ee3ab42cd 100644 --- a/support/code-coverage/src/lib.rs +++ b/support/code-coverage/src/lib.rs @@ -87,7 +87,12 @@ pub fn analyze_files(rust_files: &[PathBuf], workspace_root: &Path) -> Vec>(); custom_println!("[code-coverage]", green, "found {} tests", tests.len()); - custom_println!("[code-coverage]", green, "found {} benchmarks", benchmarks.len()); + custom_println!( + "[code-coverage]", + green, + "found {} benchmarks", + benchmarks.len() + ); custom_println!( "[code-coverage]", @@ -254,20 +259,18 @@ pub fn find_benchmarks(rust_files: &[PathBuf]) -> Vec { let Ok(file) = syn::parse_file(&content) else { return Vec::new(); }; - let mut visitor = BenchmarkVisitor { benchmarks: Vec::new() }; + let mut visitor = BenchmarkVisitor { + benchmarks: Vec::new(), + }; visitor.visit_file(&file); visitor .benchmarks .into_iter() .map(|f| { let mut calls = HashSet::new(); - let mut visitor = CallVisitor { - calls: &mut calls, - }; + let mut visitor = CallVisitor { calls: &mut calls }; visitor.visit_item_fn(&f); - BenchmarkInfo { - calls, - } + BenchmarkInfo { calls } }) .collect() })