Don't use fixed nominator count for report_equivocation weight calculation (#14471)

* babe: fix report_equivocation weight calculation

* grandpa: fix report_equivocation weight calculation

* beefy: fix report_equivocation weight calculation

* runtime: add missing MaxNominators constant
This commit is contained in:
André Silva
2023-07-18 15:11:00 +01:00
committed by GitHub
parent a3a04c7e4d
commit 50a63c30d9
16 changed files with 59 additions and 36 deletions
+4 -8
View File
@@ -28,15 +28,11 @@ impl crate::WeightInfo for () {
DbWeight::get().writes(1)
}
fn report_equivocation(validator_count: u32) -> Weight {
fn report_equivocation(validator_count: u32, max_nominators_per_validator: u32) -> Weight {
// we take the validator set count from the membership proof to
// calculate the weight but we set a floor of 100 validators.
let validator_count = validator_count.max(100) as u64;
// worst case we are considering is that the given offender
// is backed by 200 nominators
const MAX_NOMINATORS: u64 = 200;
// checking membership proof
Weight::from_parts(35u64 * WEIGHT_REF_TIME_PER_MICROS, 0)
.saturating_add(
@@ -49,10 +45,10 @@ impl crate::WeightInfo for () {
// report offence
.saturating_add(Weight::from_parts(110u64 * WEIGHT_REF_TIME_PER_MICROS, 0))
.saturating_add(Weight::from_parts(
25u64 * WEIGHT_REF_TIME_PER_MICROS * MAX_NOMINATORS,
25u64 * WEIGHT_REF_TIME_PER_MICROS * max_nominators_per_validator as u64,
0,
))
.saturating_add(DbWeight::get().reads(14 + 3 * MAX_NOMINATORS))
.saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS))
.saturating_add(DbWeight::get().reads(14 + 3 * max_nominators_per_validator as u64))
.saturating_add(DbWeight::get().writes(10 + 3 * max_nominators_per_validator as u64))
}
}