From b15e2fa58c3a67cf5840595fc0ab2b07dadf8351 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 31 Aug 2023 08:46:18 +0800 Subject: [PATCH] Improve weight checker Signed-off-by: Xavier Lau --- Cargo.lock | 44 ++++++++++++++++----------------- Cargo.toml | 2 +- runtime/crab/src/migration.rs | 15 +++++++++-- tool/weight-checker/src/main.rs | 32 ++++++++++++++---------- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 182242e2d..6da409c6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "crab-runtime" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "bp-darwinia-core", @@ -2500,7 +2500,7 @@ dependencies = [ [[package]] name = "darwinia" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "async-trait", @@ -2578,7 +2578,7 @@ dependencies = [ [[package]] name = "darwinia-account-migration" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "darwinia-deposit", @@ -2603,7 +2603,7 @@ dependencies = [ [[package]] name = "darwinia-asset-limit" -version = "6.3.4" +version = "6.4.0" dependencies = [ "frame-support", "frame-system", @@ -2614,7 +2614,7 @@ dependencies = [ [[package]] name = "darwinia-common-runtime" -version = "6.3.4" +version = "6.4.0" dependencies = [ "bp-darwinia-core", "darwinia-precompile-assets", @@ -2641,7 +2641,7 @@ dependencies = [ [[package]] name = "darwinia-deposit" -version = "6.3.4" +version = "6.4.0" dependencies = [ "darwinia-staking-traits", "dc-inflation", @@ -2662,7 +2662,7 @@ dependencies = [ [[package]] name = "darwinia-ecdsa-authority" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "dc-primitives", @@ -2682,7 +2682,7 @@ dependencies = [ [[package]] name = "darwinia-message-gadget" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "frame-support", @@ -2700,7 +2700,7 @@ dependencies = [ [[package]] name = "darwinia-message-transact" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "bp-message-dispatch", @@ -2729,7 +2729,7 @@ dependencies = [ [[package]] name = "darwinia-precompile-assets" -version = "6.3.4" +version = "6.4.0" dependencies = [ "fp-evm", "frame-support", @@ -2750,7 +2750,7 @@ dependencies = [ [[package]] name = "darwinia-precompile-bls12-381" -version = "6.3.4" +version = "6.4.0" dependencies = [ "ark-bls12-381", "ark-ec", @@ -2768,7 +2768,7 @@ dependencies = [ [[package]] name = "darwinia-precompile-deposit" -version = "6.3.4" +version = "6.4.0" dependencies = [ "darwinia-deposit", "fp-evm", @@ -2788,7 +2788,7 @@ dependencies = [ [[package]] name = "darwinia-precompile-staking" -version = "6.3.4" +version = "6.4.0" dependencies = [ "darwinia-deposit", "darwinia-staking", @@ -2809,7 +2809,7 @@ dependencies = [ [[package]] name = "darwinia-precompile-state-storage" -version = "6.3.4" +version = "6.4.0" dependencies = [ "fp-evm", "frame-support", @@ -2828,7 +2828,7 @@ dependencies = [ [[package]] name = "darwinia-runtime" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "bp-darwinia-core", @@ -2935,7 +2935,7 @@ dependencies = [ [[package]] name = "darwinia-staking" -version = "6.3.4" +version = "6.4.0" dependencies = [ "darwinia-deposit", "darwinia-staking-traits", @@ -2961,7 +2961,7 @@ dependencies = [ [[package]] name = "darwinia-staking-traits" -version = "6.3.4" +version = "6.4.0" dependencies = [ "parity-scale-codec", "scale-info", @@ -3009,7 +3009,7 @@ dependencies = [ [[package]] name = "dc-inflation" -version = "6.3.4" +version = "6.4.0" dependencies = [ "dc-types", "primitive-types", @@ -3019,7 +3019,7 @@ dependencies = [ [[package]] name = "dc-primitives" -version = "6.3.4" +version = "6.4.0" dependencies = [ "dc-types", "fp-account", @@ -3029,7 +3029,7 @@ dependencies = [ [[package]] name = "dc-types" -version = "6.3.4" +version = "6.4.0" [[package]] name = "der" @@ -8733,7 +8733,7 @@ dependencies = [ [[package]] name = "pangolin-runtime" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "bp-darwinia-core", @@ -8844,7 +8844,7 @@ dependencies = [ [[package]] name = "pangoro-runtime" -version = "6.3.4" +version = "6.4.0" dependencies = [ "array-bytes 6.1.0", "bp-darwinia-core", diff --git a/Cargo.toml b/Cargo.toml index bf5ef2134..57cd894d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ edition = "2021" homepage = "https://darwinia.network" license = "GPL-3.0" repository = "https://github.com/darwinia-network/darwinia" -version = "6.3.4" +version = "6.4.0" [workspace.dependencies] # crates.io diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index b12f5bda3..3e45a6ea6 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -41,7 +41,18 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - frame_support::weights::Weight::zero() + // substrate + use frame_support::traits::StorageVersion; + + // Some pallets ere added on chain after the migration. + // Thus, they never required the migration and we just missed to set the correct + // `StorageVersion`. + StorageVersion::new(4).put::(); + StorageVersion::new(3).put::(); + StorageVersion::new(1).put::(); + StorageVersion::new(2).put::(); + + // frame_support::weights::Weight::zero() // RuntimeBlockWeights::get().max_block - // ::DbWeight::get().reads_writes(0, 0) + ::DbWeight::get().reads_writes(0, 4) } diff --git a/tool/weight-checker/src/main.rs b/tool/weight-checker/src/main.rs index f0305e068..d75133ceb 100644 --- a/tool/weight-checker/src/main.rs +++ b/tool/weight-checker/src/main.rs @@ -4,6 +4,9 @@ use std::{fs, path::PathBuf}; use clap::Parser; use regex::Regex; +const ON_CHAIN_REF_TIME: u128 = 349_900_160_000; +const ON_CHAIN_PROOF_SIZE: u128 = 3_670_016; + fn main() { let Cli { paths } = Cli::parse(); @@ -14,26 +17,29 @@ fn main() { panic!("invalid path"); } - let (on_chain_ref_time, on_chain_proof_size) = (349_900_160_000, 3_670_016); - let (mut ref_time, mut proof_size) = (0, 0); + println!("Max on-chain `ref_time`: {ON_CHAIN_REF_TIME}"); + println!("Max on-chain `proof_size`: {ON_CHAIN_PROOF_SIZE}"); + + let mut problems = Vec::new(); fs::read_dir(p).unwrap().for_each(|e| { let e = e.unwrap(); let p = e.path(); - let t = fs::read_to_string(p).unwrap(); - let (ref_time_, proof_size_) = R::new().captures_max(&t); + let t = fs::read_to_string(&p).unwrap(); + let (ref_time, proof_size) = R::new().captures_max(&t); - ref_time = ref_time.max(ref_time_); - proof_size = proof_size.max(proof_size_); + if ref_time >= ON_CHAIN_REF_TIME || proof_size >= ON_CHAIN_PROOF_SIZE { + problems.push((ref_time, proof_size, p.display().to_string())); + } }); - println!("Max `ref_time`: {ref_time}"); - println!("Max on-chain `ref_time`: {on_chain_ref_time}"); - println!("Max `proof_size`: {proof_size}"); - println!("Max on-chain `proof_size`: {on_chain_proof_size}"); - - if ref_time >= on_chain_ref_time || proof_size >= on_chain_proof_size { - panic!("exceeded on-chain limit"); + if !problems.is_empty() { + panic!( + "{}", + problems.into_iter().fold(String::new(), |acc, (t, ps, p)| format!( + "{acc}ref_time({t}) proof_size({ps}) path({p})\n" + )) + ); } }); }