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:
Robert Habermeier
2018-12-10 18:37:08 +01:00
committed by GitHub
parent dcc38fe45a
commit 6299b42a4d
41 changed files with 1344 additions and 379 deletions
+39 -3
View File
@@ -37,6 +37,7 @@ extern crate parity_codec_derive;
extern crate parity_codec as codec;
extern crate sr_std as rstd;
extern crate srml_aura as aura;
extern crate srml_balances as balances;
extern crate srml_consensus as consensus;
extern crate srml_contract as contract;
@@ -53,6 +54,7 @@ extern crate srml_upgrade_key as upgrade_key;
#[macro_use]
extern crate sr_version as version;
extern crate node_primitives;
extern crate substrate_consensus_aura_primitives as consensus_aura;
use rstd::prelude::*;
use substrate_primitives::u32_trait::{_2, _4};
@@ -76,6 +78,7 @@ use council::seats as council_seats;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
use consensus_aura::api as aura_api;
#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildStorage;
@@ -83,7 +86,6 @@ pub use consensus::Call as ConsensusCall;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use runtime_primitives::{Permill, Perbill};
pub use timestamp::BlockPeriod;
pub use srml_support::{StorageValue, RuntimeMetadata};
const TIMESTAMP_SET_POSITION: u32 = 0;
@@ -121,6 +123,10 @@ impl system::Trait for Runtime {
type Log = Log;
}
impl aura::Trait for Runtime {
type HandleReport = aura::StakingSlasher<Runtime>;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type AccountIndex = AccountIndex;
@@ -133,12 +139,16 @@ impl consensus::Trait for Runtime {
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
type Log = Log;
type SessionKey = SessionKey;
type OnOfflineValidator = Staking;
// the aura module handles offline-reports internally
// rather than using an explicit report system.
type InherentOfflineReport = ();
}
impl timestamp::Trait for Runtime {
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
type Moment = u64;
type OnTimestampSet = Aura;
}
/// Session key conversion.
@@ -208,6 +218,7 @@ construct_runtime!(
InherentData = BasicInherentData
{
System: system::{default, Log(ChangesTrieRoot)},
Aura: aura::{Module},
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
Consensus: consensus::{Module, Call, Storage, Config<T>, Log(AuthoritiesChange), Inherent},
Balances: balances,
@@ -299,7 +310,26 @@ impl_runtime_apis! {
}
fn check_inherents(block: Block, data: BasicInherentData) -> Result<(), CheckInherentError> {
Runtime::check_inherents(block, data)
let expected_slot = data.aura_expected_slot;
// draw timestamp out from extrinsics.
let set_timestamp = block.extrinsics()
.get(TIMESTAMP_SET_POSITION as usize)
.and_then(|xt: &UncheckedExtrinsic| match xt.function {
Call::Timestamp(TimestampCall::set(ref t)) => Some(t.clone()),
_ => None,
})
.ok_or_else(|| CheckInherentError::Other("No valid timestamp in block.".into()))?;
// take the "worse" result of normal verification and the timestamp vs. seal
// check.
CheckInherentError::combine_results(
Runtime::check_inherents(block, data),
|| {
Aura::verify_inherent(set_timestamp.into(), expected_slot)
.map_err(|s| CheckInherentError::Other(s.into()))
},
)
}
fn random_seed() -> <Block as BlockT>::Hash {
@@ -332,4 +362,10 @@ impl_runtime_apis! {
Grandpa::grandpa_authorities()
}
}
impl aura_api::AuraApi<Block> for Runtime {
fn slot_duration() -> u64 {
Aura::slot_duration()
}
}
}