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
+6 -2
View File
@@ -40,6 +40,10 @@ pub fn flaming_fir_config() -> Result<ChainSpec, String> {
ChainSpec::from_embedded(include_bytes!("../res/flaming-fir.json"))
}
fn session_keys(key: ed25519::Public) -> SessionKeys {
SessionKeys { ed25519: key }
}
fn staging_testnet_config_genesis() -> GenesisConfig {
// stash, controller, session-key
// generated with secret:
@@ -112,7 +116,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
.collect::<Vec<_>>(),
}),
session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| (x.1.clone(), SessionKeys(x.2.clone(),x.2.clone()))).collect::<Vec<_>>(),
keys: initial_authorities.iter().map(|x| (x.1.clone(), session_keys(x.2.clone()))).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -239,7 +243,7 @@ pub fn testnet_genesis(
vesting: vec![],
}),
session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone()))).collect::<Vec<_>>(),
keys: initial_authorities.iter().map(|x| (x.1.clone(), session_keys(x.2.clone()))).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
current_era: 0,
+5 -2
View File
@@ -55,7 +55,8 @@ mod tests {
use node_runtime::{
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances, BuildStorage,
GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System, SystemConfig,
GrandpaConfig, IndicesConfig, ContractsConfig, Event, SessionKeys, CENTS, DOLLARS, MILLICENTS
GrandpaConfig, IndicesConfig, ContractsConfig, Event, SessionKeys,
CENTS, DOLLARS, MILLICENTS,
};
use wabt;
use primitives::map;
@@ -290,7 +291,9 @@ mod tests {
}
fn to_session_keys(ring: &AuthorityKeyring) -> SessionKeys {
SessionKeys(ring.to_owned().into(), ring.to_owned().into())
SessionKeys {
ed25519: ring.to_owned().into(),
}
}
fn new_test_ext(code: &[u8], support_changes_trie: bool) -> TestExternalities<Blake2Hasher> {
+1 -1
View File
@@ -26,7 +26,7 @@ executive = { package = "srml-executive", path = "../../srml/executive", default
finality-tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false }
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
indices = { package = "srml-indices", path = "../../srml/indices", default-features = false }
session = { package = "srml-session", path = "../../srml/session", default-features = false }
session = { package = "srml-session", path = "../../srml/session", default-features = false, features = ["historical"] }
staking = { package = "srml-staking", path = "../../srml/staking", default-features = false }
system = { package = "srml-system", path = "../../srml/system", default-features = false }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false }
+17 -4
View File
@@ -34,7 +34,7 @@ use client::{
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
runtime_api as client_api, impl_runtime_apis
};
use runtime_primitives::{ApplyResult, generic, create_runtime_str};
use runtime_primitives::{ApplyResult, impl_opaque_keys, generic, create_runtime_str, key_types};
use runtime_primitives::transaction_validity::TransactionValidity;
use runtime_primitives::traits::{
BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, Convert,
@@ -54,7 +54,7 @@ pub use runtime_primitives::BuildStorage;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use contracts::Gas;
pub use runtime_primitives::{Permill, Perbill, impl_opaque_keys};
pub use runtime_primitives::{Permill, Perbill};
pub use support::StorageValue;
pub use staking::StakerStatus;
@@ -71,7 +71,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 104,
spec_version: 105,
impl_version: 105,
apis: RUNTIME_API_VERSIONS,
};
@@ -181,8 +182,12 @@ parameter_types! {
}
type SessionHandlers = (Grandpa, Aura);
impl_opaque_keys! {
pub struct SessionKeys(grandpa::AuthorityId, AuraId);
pub struct SessionKeys {
#[id(key_types::ED25519)]
pub ed25519: GrandpaId,
}
}
// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
@@ -197,9 +202,16 @@ impl session::Trait for Runtime {
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type Event = Event;
type Keys = SessionKeys;
type ValidatorId = AccountId;
type ValidatorIdOf = staking::StashOf<Self>;
type SelectInitialValidators = Staking;
}
impl session::historical::Trait for Runtime {
type FullIdentification = staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = staking::ExposureOf<Runtime>;
}
parameter_types! {
pub const SessionsPerEra: session::SessionIndex = 6;
pub const BondingDuration: staking::EraIndex = 24 * 28;
@@ -228,6 +240,7 @@ impl staking::Trait for Runtime {
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SessionInterface = Self;
}
parameter_types! {