Skip to content

Commit

Permalink
Improve weight checker
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <xavier@inv.cafe>
  • Loading branch information
AurevoirXavier committed Aug 31, 2023
1 parent 336c98a commit b15e2fa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions runtime/crab/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Scheduler>();
StorageVersion::new(3).put::<XcmpQueue>();
StorageVersion::new(1).put::<PolkadotXcm>();
StorageVersion::new(2).put::<DmpQueue>();

// frame_support::weights::Weight::zero()
// RuntimeBlockWeights::get().max_block
// <Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 0)
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 4)
}
32 changes: 19 additions & 13 deletions tool/weight-checker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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"
))
);
}
});
}
Expand Down

0 comments on commit b15e2fa

Please sign in to comment.