Remove footgun around session keys/handlers (#3949)

* Remove footgun around session keys/handlers

- `OpaqueKeys` now has an associated type `KeyTypeIdProviders`. This can
be used in the runtime as input for `SessionHandler` from the session
trait.
- `impl_opaque_keys` now works with modules and extracts the `KeyTypeId`
from the module directly.
- Added some checks to the `session` storage initialization that checks
that the `SessionHandler` and `Keys` use the same number of keys and
that the order is equal.

* Update core/sr-primitives/src/traits.rs
This commit is contained in:
Bastian Köcher
2019-10-29 00:58:58 +01:00
committed by GitHub
parent 06433c9889
commit 057636fd1f
21 changed files with 150 additions and 100 deletions
+4 -2
View File
@@ -17,12 +17,12 @@
//! Test utilities
use std::{collections::HashSet, cell::RefCell};
use sr_primitives::Perbill;
use sr_primitives::{Perbill, KeyTypeId};
use sr_primitives::curve::PiecewiseLinear;
use sr_primitives::traits::{IdentityLookup, Convert, OpaqueKeys, OnInitialize, SaturatedConversion};
use sr_primitives::testing::{Header, UintAuthorityId};
use sr_staking_primitives::SessionIndex;
use primitives::H256;
use primitives::{H256, crypto::key_types};
use runtime_io;
use support::{assert_ok, impl_outer_origin, parameter_types, StorageLinkedMap};
use support::traits::{Currency, Get, FindAuthor};
@@ -52,6 +52,8 @@ thread_local! {
pub struct TestSessionHandler;
impl session::SessionHandler<AccountId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[key_types::DUMMY];
fn on_genesis_session<Ks: OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
fn on_new_session<Ks: OpaqueKeys>(