mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 14:27:57 +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
@@ -56,12 +56,32 @@ use runtime_primitives::traits::{
|
||||
use system::ensure_inherent;
|
||||
use rstd::{result, ops::{Mul, Div}, vec::Vec};
|
||||
|
||||
/// A trait which is called when the timestamp is set.
|
||||
pub trait OnTimestampSet<Moment> {
|
||||
fn on_timestamp_set(moment: Moment);
|
||||
}
|
||||
|
||||
impl<Moment> OnTimestampSet<Moment> for () {
|
||||
fn on_timestamp_set(_moment: Moment) { }
|
||||
}
|
||||
|
||||
impl<A, B, Moment: Clone> OnTimestampSet<Moment> for (A, B)
|
||||
where A: OnTimestampSet<Moment>, B: OnTimestampSet<Moment>
|
||||
{
|
||||
fn on_timestamp_set(moment: Moment) {
|
||||
A::on_timestamp_set(moment.clone());
|
||||
B::on_timestamp_set(moment);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Trait: consensus::Trait + system::Trait {
|
||||
/// The position of the required timestamp-set extrinsic.
|
||||
const TIMESTAMP_SET_POSITION: u32;
|
||||
|
||||
/// Type used for expressing timestamp.
|
||||
type Moment: Parameter + Default + SimpleArithmetic + Mul<Self::BlockNumber, Output = Self::Moment> + Div<Self::BlockNumber, Output = Self::Moment>;
|
||||
/// Something which can be notified when the timestamp is set. Set this to `()` if not needed.
|
||||
type OnTimestampSet: OnTimestampSet<Self::Moment>;
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@@ -88,8 +108,10 @@ decl_module! {
|
||||
Self::now().is_zero() || now >= Self::now() + Self::block_period(),
|
||||
"Timestamp must increment by at least <BlockPeriod> between sequential blocks"
|
||||
);
|
||||
<Self as Store>::Now::put(now);
|
||||
<Self as Store>::Now::put(now.clone());
|
||||
<Self as Store>::DidUpdate::put(true);
|
||||
|
||||
<T::OnTimestampSet as OnTimestampSet<_>>::on_timestamp_set(now);
|
||||
}
|
||||
|
||||
fn on_finalise() {
|
||||
@@ -192,11 +214,12 @@ mod tests {
|
||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
||||
type Log = DigestItem;
|
||||
type SessionKey = u64;
|
||||
type OnOfflineValidator = ();
|
||||
type InherentOfflineReport = ();
|
||||
}
|
||||
impl Trait for Test {
|
||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
}
|
||||
type Timestamp = Module<Test>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user