diff --git a/resources/weight_analyzer/src/main.rs b/resources/weight_analyzer/src/main.rs index 38b476d97e93f984a2be79de2370be570547c504..cc18295af12dbcfe1a1b99084ad9551c16db8879 100644 --- a/resources/weight_analyzer/src/main.rs +++ b/resources/weight_analyzer/src/main.rs @@ -2,6 +2,7 @@ use glob::glob; use std::path::Path; use subweight_core::parse::overhead::Weight; use subweight_core::parse::pallet::ChromaticExtrinsic; +use subweight_core::parse::pallet::ComponentRange; use subweight_core::parse::storage::Weights; use subweight_core::scope::Scope; use subweight_core::term::Term; @@ -16,10 +17,9 @@ fn main() { scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write); // Test - // TODO Fix subweight-core parser not working with parameters for i in pallet_weights { for j in i { - let (pallet, extrinsic, weight) = evaluate_weight(j, &scope).unwrap(); + let (pallet, extrinsic, weight) = evaluate_weight(j, &mut scope).unwrap(); println!( "Pallet: {:?} ; Extrinsic: {:?} ; Weight: {:?}", pallet, extrinsic, weight @@ -58,8 +58,18 @@ fn read_overhead_weight() -> Weight { fn evaluate_weight( extrinsic: ChromaticExtrinsic, - scope: &Scope<Term<u128>>, + scope: &mut Scope<Term<u128>>, ) -> Result<(String, String, u128), String> { + // Extend the scope with the maximum value of the complexity parameter. + if let Some(params) = extrinsic.comp_ranges { + params + .iter() + .for_each(|(key, val): (&String, &ComponentRange)| { + scope.put_var(key.as_str(), Term::Scalar(val.max.into())); + }); + } + + // Evaluate the weight let weight = extrinsic .term .simplify(subweight_core::Dimension::Time)