diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 255bb4f647416..1b7f7ae248bc1 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -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)?; - // set new value for next session - >::insert(who, key); + if >::get(&key).is_none() { + // set new value for next session + >::insert(who.clone(), key.clone()); + >::insert(key, who); + } } /// Set a new session length. Won't kick in until the next session change (at current length). @@ -216,6 +219,7 @@ decl_storage! { NextKeyFor build(|config: &GenesisConfig| { config.keys.clone() }): map T::AccountId => Option; + KeyFilterMap: map T::SessionKey => Option; /// The next session length. NextSessionLength: Option; } @@ -322,6 +326,10 @@ impl Module { impl OnFreeBalanceZero for Module { fn on_free_balance_zero(who: &T::AccountId) { + let key = >::get(who); + if key.is_some() { + >::remove(&key.unwrap()); + } >::remove(who); } }