mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +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
@@ -333,6 +333,11 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the current validators.
|
||||
pub fn validators() -> Vec<T::AccountId> {
|
||||
session::Module::<T>::validators()
|
||||
}
|
||||
|
||||
// PUBLIC MUTABLES (DANGEROUS)
|
||||
|
||||
/// Slash a given validator by a specific amount. Removes the slash from their balance by preference,
|
||||
@@ -490,6 +495,38 @@ impl<T: Trait> Module<T> {
|
||||
<CurrentOfflineSlash<T>>::put(Self::offline_slash().times(stake_range.1));
|
||||
<CurrentSessionReward<T>>::put(Self::session_reward().times(stake_range.1));
|
||||
}
|
||||
|
||||
/// Call when a validator is determined to be offline. `count` is the
|
||||
/// number of offences the validator has committed.
|
||||
pub fn on_offline_validator(v: T::AccountId, count: usize) {
|
||||
for _ in 0..count {
|
||||
let slash_count = Self::slash_count(&v);
|
||||
<SlashCount<T>>::insert(v.clone(), slash_count + 1);
|
||||
let grace = Self::offline_slash_grace();
|
||||
|
||||
let event = if slash_count >= grace {
|
||||
let instances = slash_count - grace;
|
||||
let slash = Self::current_offline_slash() << instances;
|
||||
let next_slash = slash << 1u32;
|
||||
let _ = Self::slash_validator(&v, slash);
|
||||
if instances >= Self::validator_preferences(&v).unstake_threshold
|
||||
|| Self::slashable_balance(&v) < next_slash
|
||||
{
|
||||
if let Some(pos) = Self::intentions().into_iter().position(|x| &x == &v) {
|
||||
Self::apply_unstake(&v, pos)
|
||||
.expect("pos derived correctly from Self::intentions(); \
|
||||
apply_unstake can only fail if pos wrong; \
|
||||
Self::intentions() doesn't change; qed");
|
||||
}
|
||||
let _ = Self::apply_force_new_era(false);
|
||||
}
|
||||
RawEvent::OfflineSlash(v.clone(), slash)
|
||||
} else {
|
||||
RawEvent::OfflineWarning(v.clone(), slash_count)
|
||||
};
|
||||
Self::deposit_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> OnSessionChange<T::Moment> for Module<T> {
|
||||
@@ -514,33 +551,11 @@ impl<T: Trait> balances::OnFreeBalanceZero<T::AccountId> for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> consensus::OnOfflineValidator for Module<T> {
|
||||
fn on_offline_validator(validator_index: usize) {
|
||||
let v = <session::Module<T>>::validators()[validator_index].clone();
|
||||
let slash_count = Self::slash_count(&v);
|
||||
<SlashCount<T>>::insert(v.clone(), slash_count + 1);
|
||||
let grace = Self::offline_slash_grace();
|
||||
|
||||
let event = if slash_count >= grace {
|
||||
let instances = slash_count - grace;
|
||||
let slash = Self::current_offline_slash() << instances;
|
||||
let next_slash = slash << 1u32;
|
||||
let _ = Self::slash_validator(&v, slash);
|
||||
if instances >= Self::validator_preferences(&v).unstake_threshold
|
||||
|| Self::slashable_balance(&v) < next_slash
|
||||
{
|
||||
if let Some(pos) = Self::intentions().into_iter().position(|x| &x == &v) {
|
||||
Self::apply_unstake(&v, pos)
|
||||
.expect("pos derived correctly from Self::intentions(); \
|
||||
apply_unstake can only fail if pos wrong; \
|
||||
Self::intentions() doesn't change; qed");
|
||||
}
|
||||
let _ = Self::apply_force_new_era(false);
|
||||
}
|
||||
RawEvent::OfflineSlash(v, slash)
|
||||
} else {
|
||||
RawEvent::OfflineWarning(v, slash_count)
|
||||
};
|
||||
Self::deposit_event(event);
|
||||
impl<T: Trait> consensus::OnOfflineReport<Vec<u32>> for Module<T> {
|
||||
fn handle_report(reported_indices: Vec<u32>) {
|
||||
for validator_index in reported_indices {
|
||||
let v = <session::Module<T>>::validators()[validator_index as usize].clone();
|
||||
Self::on_offline_validator(v, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user