Slash and prove membership of prior sessions (#2970)

* skeleton for tracking historical sessions

* refactor OpaqueKeys

* some more skeleton work

* adjust session to new OpaqueKeys API

* further refactoring of key-type-ids

* session gets validator ID parameter

* run up against compiler

* tweak staking to support new session changes

* first run at child storage for deduplication

* Make session use `AccountId` as `ValidatorId`

* run up against child trie issues

* switch to using normal trie but with a fixed prefix

* clear out some println

* add dedup test

* flesh out historical module more

* introduce ExposureOf for staking

* test the historical module

* WASM compiles

* tests all compile

* do some mock change

* fix bulk of tests

* fix staking tests

* test obsolecence mechanic

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* some more style nits

* a couple more nits

* tweak tries

* fix typo thie -> this
This commit is contained in:
Robert Habermeier
2019-07-08 14:36:46 +02:00
committed by GitHub
parent bb7ff32e77
commit 7df8e52cfe
23 changed files with 1188 additions and 341 deletions
+8 -3
View File
@@ -53,7 +53,10 @@ pub use timestamp;
use rstd::{result, prelude::*};
use parity_codec::Encode;
use srml_support::{decl_storage, decl_module, Parameter, storage::StorageValue};
use primitives::{traits::{SaturatedConversion, Saturating, Zero, One, Member}, generic::DigestItem};
use primitives::{
traits::{SaturatedConversion, Saturating, Zero, One, Member, TypedKey},
generic::DigestItem,
};
use timestamp::OnTimestampSet;
#[cfg(feature = "std")]
use timestamp::TimestampInherentData;
@@ -153,7 +156,7 @@ pub trait Trait: timestamp::Trait {
type HandleReport: HandleReport;
/// The identifier type for an authority.
type AuthorityId: Member + Parameter + Default;
type AuthorityId: Member + Parameter + TypedKey + Default;
}
decl_storage! {
@@ -184,6 +187,7 @@ impl<T: Trait> Module<T> {
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = T::AuthorityId;
fn on_new_session<'a, I: 'a>(changed: bool, validators: I)
where I: Iterator<Item=(&'a T::AccountId, T::AuthorityId)>
{
@@ -274,7 +278,8 @@ pub struct StakingSlasher<T>(::rstd::marker::PhantomData<T>);
impl<T: staking::Trait + Trait> HandleReport for StakingSlasher<T> {
fn handle_report(report: AuraReport) {
let validators = session::Module::<T>::validators();
use staking::SessionInterface;
let validators = T::SessionInterface::validators();
report.punish(
validators.len(),
+5 -1
View File
@@ -18,7 +18,11 @@
#![cfg(test)]
use primitives::{traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use primitives::{
KeyTypeId,
traits::IdentityLookup,
testing::{UINT_DUMMY_KEY, Header, UintAuthorityId},
};
use srml_support::impl_outer_origin;
use runtime_io;
use substrate_primitives::{H256, Blake2Hasher};