Pallet session new API (#4609)

* Initial work

* Fix most things

* fix test

* fix old comment

* migration

* fix

* remove useless stuff

* fix

* less spaghetti implementation

* fix initial session

* fix
This commit is contained in:
thiolliere
2020-01-20 17:26:53 +01:00
committed by Gavin Wood
parent b0d1a7183a
commit 164dec95e5
10 changed files with 159 additions and 195 deletions
+12 -13
View File
@@ -88,9 +88,10 @@ impl SessionHandler<u64> for TestSessionHandler {
}
}
pub struct TestOnSessionEnding;
impl OnSessionEnding<u64> for TestOnSessionEnding {
fn on_session_ending(_: SessionIndex, _: SessionIndex) -> Option<Vec<u64>> {
pub struct TestSessionManager;
impl SessionManager<u64> for TestSessionManager {
fn end_session(_: SessionIndex) {}
fn new_session(_: SessionIndex) -> Option<Vec<u64>> {
if !TEST_SESSION_CHANGED.with(|l| *l.borrow()) {
VALIDATORS.with(|v| {
let mut v = v.borrow_mut();
@@ -108,14 +109,13 @@ impl OnSessionEnding<u64> for TestOnSessionEnding {
}
#[cfg(feature = "historical")]
impl crate::historical::OnSessionEnding<u64, u64> for TestOnSessionEnding {
fn on_session_ending(ending_index: SessionIndex, will_apply_at: SessionIndex)
-> Option<(Vec<u64>, Vec<(u64, u64)>)>
impl crate::historical::SessionManager<u64, u64> for TestSessionManager {
fn end_session(_: SessionIndex) {}
fn new_session(new_index: SessionIndex)
-> Option<Vec<(u64, u64)>>
{
let pair_with_ids = |vals: &[u64]| vals.iter().map(|&v| (v, v)).collect::<Vec<_>>();
<Self as OnSessionEnding<_>>::on_session_ending(ending_index, will_apply_at)
.map(|vals| (pair_with_ids(&vals), vals))
.map(|(ids, vals)| (vals, ids))
<Self as SessionManager<_>>::new_session(new_index)
.map(|vals| vals.into_iter().map(|val| (val, val)).collect())
}
}
@@ -190,15 +190,14 @@ parameter_types! {
impl Trait for Test {
type ShouldEndSession = TestShouldEndSession;
#[cfg(feature = "historical")]
type OnSessionEnding = crate::historical::NoteHistoricalRoot<Test, TestOnSessionEnding>;
type SessionManager = crate::historical::NoteHistoricalRoot<Test, TestSessionManager>;
#[cfg(not(feature = "historical"))]
type OnSessionEnding = TestOnSessionEnding;
type SessionManager = TestSessionManager;
type SessionHandler = TestSessionHandler;
type ValidatorId = u64;
type ValidatorIdOf = ConvertInto;
type Keys = MockSessionKeys;
type Event = ();
type SelectInitialValidators = ();
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
}