mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 03:25:41 +00:00
Offline/Slashing improvements (#1665)
* Initial logic * Fix tests * Don't punish at all when everyone skipped * Typo * Fix tests. * Update srml/aura/src/lib.rs Co-Authored-By: gavofyork <github@gavwood.com> * Simplification. * Bump runtime verions
This commit is contained in:
@@ -152,28 +152,13 @@ impl AuraReport {
|
||||
pub fn punish<F>(&self, validator_count: usize, mut punish_with: F)
|
||||
where F: FnMut(usize, usize)
|
||||
{
|
||||
let start_slot = self.start_slot % validator_count;
|
||||
|
||||
// the number of times everyone was skipped.
|
||||
let skipped_all = self.skipped / validator_count;
|
||||
// the number of validators who were skipped once after that.
|
||||
let skipped_after = self.skipped % validator_count;
|
||||
|
||||
let iter = (start_slot..validator_count).into_iter()
|
||||
.chain(0..start_slot)
|
||||
.enumerate();
|
||||
|
||||
for (rel_index, actual_index) in iter {
|
||||
let slash_count = skipped_all + if rel_index < skipped_after {
|
||||
1
|
||||
} else {
|
||||
// avoid iterating over all authorities when skipping a couple.
|
||||
if skipped_all == 0 { break }
|
||||
0
|
||||
};
|
||||
|
||||
if slash_count > 0 {
|
||||
punish_with(actual_index, slash_count);
|
||||
// If all validators have been skipped, then it implies some sort of
|
||||
// systematic problem common to all rather than a minority of validators
|
||||
// unfulfilling their specific duties. In this case, it doesn't make
|
||||
// sense to punish anyone, so we guard against it.
|
||||
if self.skipped < validator_count {
|
||||
for index in 0..self.skipped {
|
||||
punish_with((self.start_slot + index) % validator_count, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user