Clamp benchmark ranks to respect MaxRank#7720
Conversation
bkchr
left a comment
There was a problem hiding this comment.
The general logic looks good, just some nit improvements to make this better :)
acatangiu
left a comment
There was a problem hiding this comment.
I like the benchmark fix, I personally don’t like the u32->u16 type change because it adds more complexity with some custom converters types and is a breaking change for runtime builders, for no strong reason/benefit.
Not blocking the PR for this, but want to get your opinion on above.
The core fellowship is only used by the collectives chain. The user base of this isn't that big and also given the required change I think that the change is reasonable. |
4bbcf42
resolves paritytech#7517 ### Issues #### 1. Compile-Time vs Runtime Rank Mismatch - **`promote_fast` Benchmark** uses mock runtime's `MaxRank` during benchmark generation while allowing runtime overrides. Creating potential parameter mismatch between benchmark metadata(i.e. generated `r` values) and runtime configuration(i.e. `T::MaxRank`). #### 2. Static Rank Assumptions - **`bump_demote` Benchmark** initialized members at rank 2, making it incompatible with `MaxRank=1` configurations - **`promote` Benchmark** contained hardcoded rank values (1 → 2) which fails for `MaxRank=1` ## Changes #### Dynamic Rank Clamping ```rust // promote_fast // Get target rank for promotion. let max_rank = T::MaxRank::get(); let target_rank = (r as u16).min(max_rank); // promote // Set `to_rank` dynamically based on `max_rank`. let to_rank = (current_rank + 1).min(max_rank); --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
resolves #7517 ### Issues #### 1. Compile-Time vs Runtime Rank Mismatch - **`promote_fast` Benchmark** uses mock runtime's `MaxRank` during benchmark generation while allowing runtime overrides. Creating potential parameter mismatch between benchmark metadata(i.e. generated `r` values) and runtime configuration(i.e. `T::MaxRank`). #### 2. Static Rank Assumptions - **`bump_demote` Benchmark** initialized members at rank 2, making it incompatible with `MaxRank=1` configurations - **`promote` Benchmark** contained hardcoded rank values (1 → 2) which fails for `MaxRank=1` ## Changes #### Dynamic Rank Clamping ```rust // promote_fast // Get target rank for promotion. let max_rank = T::MaxRank::get(); let target_rank = (r as u16).min(max_rank); // promote // Set `to_rank` dynamically based on `max_rank`. let to_rank = (current_rank + 1).min(max_rank); --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
| fn induct() -> Weight; | ||
| fn promote() -> Weight; | ||
| fn promote_fast(r: u32, ) -> Weight; | ||
| fn promote_fast(r: u16, ) -> Weight; |
There was a problem hiding this comment.
@Doordashcon Changed this back to u32 because Linear currently supports only u32. Using u16 here caused a compilation issue when generating weights, more info and fix: #9516.
resolves #7517
Issues
1. Compile-Time vs Runtime Rank Mismatch
promote_fastBenchmark uses mock runtime'sMaxRankduring benchmark generation while allowing runtime overrides. Creating potential parameter mismatch between benchmark metadata(i.e. generatedrvalues) and runtime configuration(i.e.T::MaxRank).2. Static Rank Assumptions
bump_demoteBenchmark initialized members at rank 2, making it incompatible withMaxRank=1configurationspromoteBenchmark contained hardcoded rank values (1 → 2) which fails forMaxRank=1Changes
Dynamic Rank Clamping