mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 12:51:05 +00:00
Punish offline validators, aura-style (#1216)
* make offline-reporting infrastructure more generic * add a listener-trait for watching when the timestamp has been set * prevent inclusion of empty offline reports * add test for exclusion * generate aura-offline reports * ability to slash many times for being offline "multiple" times * Logic for punishing validators for missing aura steps * stub tests * pave way for verification of timestamp vs slot * alter aura import queue to wait for timestamp * check timestamp matches seal * do inherent check properly * service compiles * all tests compile * test srml-aura logic * aura tests pass * everything builds * some more final tweaks to block authorship for aura * switch to manual delays before step * restore substrate-consensus-aura to always std and address grumbles * update some state roots in executor tests * node-executor tests pass * get most tests passing * address grumbles
This commit is contained in:
committed by
GitHub
parent
dcc38fe45a
commit
6299b42a4d
@@ -0,0 +1,79 @@
|
||||
// Copyright 2017-2018 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Tests for the module.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use mock::{System, Aura, new_test_ext};
|
||||
use primitives::traits::Header;
|
||||
use runtime_io::with_externalities;
|
||||
use parking_lot::Mutex;
|
||||
use {AuraReport, HandleReport};
|
||||
|
||||
#[test]
|
||||
fn aura_report_gets_skipped_correctly() {
|
||||
let mut report = AuraReport {
|
||||
start_slot: 0,
|
||||
skipped: 30,
|
||||
};
|
||||
|
||||
let mut validators = vec![0; 10];
|
||||
report.punish(10, |idx, count| validators[idx] += count);
|
||||
|
||||
assert_eq!(validators, vec![3; 10]);
|
||||
|
||||
let mut validators = vec![0; 4];
|
||||
report.punish(4, |idx, count| validators[idx] += count);
|
||||
assert_eq!(validators, vec![8, 8, 7, 7]);
|
||||
|
||||
report.start_slot = 2;
|
||||
report.punish(4, |idx, count| validators[idx] += count);
|
||||
assert_eq!(validators, vec![15, 15, 15, 15]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aura_reports_offline() {
|
||||
lazy_static! {
|
||||
static ref SLASH_COUNTS: Mutex<Vec<usize>> = Mutex::new(vec![0; 4]);
|
||||
}
|
||||
|
||||
struct HandleTestReport;
|
||||
impl HandleReport for HandleTestReport {
|
||||
fn handle_report(report: AuraReport) {
|
||||
let mut counts = SLASH_COUNTS.lock();
|
||||
report.punish(counts.len(), |idx, count| counts[idx] += count);
|
||||
}
|
||||
}
|
||||
|
||||
with_externalities(&mut new_test_ext(vec![0, 1, 2, 3]), || {
|
||||
System::initialise(&1, &Default::default(), &Default::default());
|
||||
let slot_duration = Aura::slot_duration();
|
||||
|
||||
Aura::on_timestamp_set::<HandleTestReport>(5 * slot_duration, slot_duration);
|
||||
let header = System::finalise();
|
||||
|
||||
// no slashing when last step was 0.
|
||||
assert_eq!(SLASH_COUNTS.lock().as_slice(), &[0, 0, 0, 0]);
|
||||
|
||||
System::initialise(&2, &header.hash(), &Default::default());
|
||||
Aura::on_timestamp_set::<HandleTestReport>(8 * slot_duration, slot_duration);
|
||||
let _header = System::finalise();
|
||||
|
||||
// Steps 6 and 7 were skipped.
|
||||
assert_eq!(SLASH_COUNTS.lock().as_slice(), &[0, 0, 1, 1]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user