Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions srml/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ decl_module! {
/// This doesn't take effect until the next session.
fn set_key(origin, key: T::SessionKey) {
let who = ensure_signed(origin)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should remove the current entry for NextKeyFor(who) in KeyFilterMap.

// set new value for next session
<NextKeyFor<T>>::insert(who, key);
if <KeyFilterMap<T>>::get(&key).is_none() {
// set new value for next session
<NextKeyFor<T>>::insert(who.clone(), key.clone());
<KeyFilterMap<T>>::insert(key, who);
}
}

/// Set a new session length. Won't kick in until the next session change (at current length).
Expand Down Expand Up @@ -216,6 +219,7 @@ decl_storage! {
NextKeyFor build(|config: &GenesisConfig<T>| {
config.keys.clone()
}): map T::AccountId => Option<T::SessionKey>;
KeyFilterMap: map T::SessionKey => Option<T::AccountId>;
/// The next session length.
NextSessionLength: Option<T::BlockNumber>;
}
Expand Down Expand Up @@ -322,6 +326,10 @@ impl<T: Trait> Module<T> {

impl<T: Trait> OnFreeBalanceZero<T::AccountId> for Module<T> {
fn on_free_balance_zero(who: &T::AccountId) {
let key = <NextKeyFor<T>>::get(who);
if key.is_some() {
<KeyFilterMap<T>>::remove(&key.unwrap());
}
<NextKeyFor<T>>::remove(who);
}
}
Expand Down