mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 02:21:04 +00:00
babe: fix report_equivocation weight (#6936)
* babe: fix report_equivocation weight * node: bump spec_version * babe: fix floor in report_equivocation weight calculation Co-authored-by: Gavin Wood <gavin@parity.io> * grandpa: fix floor in report_equivocation weight calculation * babe, grandpa: add test for weight_for::report_equivocation Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -376,7 +376,7 @@ mod weight_for {
|
||||
pub fn report_equivocation<T: super::Trait>(validator_count: 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.min(100) as u64;
|
||||
let validator_count = validator_count.max(100) as u64;
|
||||
|
||||
// worst case we are considering is that the given offender
|
||||
// is backed by 200 nominators
|
||||
|
||||
@@ -842,3 +842,26 @@ fn always_schedules_a_change_on_new_session_when_stalled() {
|
||||
assert_eq!(Grandpa::current_set_id(), 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn report_equivocation_has_valid_weight() {
|
||||
// the weight depends on the size of the validator set,
|
||||
// but there's a lower bound of 100 validators.
|
||||
assert!(
|
||||
(1..=100)
|
||||
.map(weight_for::report_equivocation::<Test>)
|
||||
.collect::<Vec<_>>()
|
||||
.windows(2)
|
||||
.all(|w| w[0] == w[1])
|
||||
);
|
||||
|
||||
// after 100 validators the weight should keep increasing
|
||||
// with every extra validator.
|
||||
assert!(
|
||||
(100..=1000)
|
||||
.map(weight_for::report_equivocation::<Test>)
|
||||
.collect::<Vec<_>>()
|
||||
.windows(2)
|
||||
.all(|w| w[0] < w[1])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user