Skip to content
Snippets Groups Projects
Unverified Commit b9da1a76 authored by bgallois's avatar bgallois
Browse files

fix weight evaluation with complexity parameters

parent f5419851
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !222. Comments created here will be created in the context of that merge request.
...@@ -2,6 +2,7 @@ use glob::glob; ...@@ -2,6 +2,7 @@ use glob::glob;
use std::path::Path; use std::path::Path;
use subweight_core::parse::overhead::Weight; use subweight_core::parse::overhead::Weight;
use subweight_core::parse::pallet::ChromaticExtrinsic; use subweight_core::parse::pallet::ChromaticExtrinsic;
use subweight_core::parse::pallet::ComponentRange;
use subweight_core::parse::storage::Weights; use subweight_core::parse::storage::Weights;
use subweight_core::scope::Scope; use subweight_core::scope::Scope;
use subweight_core::term::Term; use subweight_core::term::Term;
...@@ -16,10 +17,9 @@ fn main() { ...@@ -16,10 +17,9 @@ fn main() {
scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write); scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write);
// Test // Test
// TODO Fix subweight-core parser not working with parameters
for i in pallet_weights { for i in pallet_weights {
for j in i { for j in i {
let (pallet, extrinsic, weight) = evaluate_weight(j, &scope).unwrap(); let (pallet, extrinsic, weight) = evaluate_weight(j, &mut scope).unwrap();
println!( println!(
"Pallet: {:?} ; Extrinsic: {:?} ; Weight: {:?}", "Pallet: {:?} ; Extrinsic: {:?} ; Weight: {:?}",
pallet, extrinsic, weight pallet, extrinsic, weight
...@@ -58,8 +58,18 @@ fn read_overhead_weight() -> Weight { ...@@ -58,8 +58,18 @@ fn read_overhead_weight() -> Weight {
fn evaluate_weight( fn evaluate_weight(
extrinsic: ChromaticExtrinsic, extrinsic: ChromaticExtrinsic,
scope: &Scope<Term<u128>>, scope: &mut Scope<Term<u128>>,
) -> Result<(String, String, u128), String> { ) -> 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 let weight = extrinsic
.term .term
.simplify(subweight_core::Dimension::Time) .simplify(subweight_core::Dimension::Time)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment