From 2190197eabc9473d730e5335eac7042160539f6d Mon Sep 17 00:00:00 2001 From: gguoss Date: Mon, 20 May 2019 14:51:17 +0800 Subject: [PATCH 1/2] Fix a bug about duplicate validator key --- srml/session/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 255bb4f647416..a4b91a38b4ab4 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) == 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); } } From e6e5bf632423a957b1c6ec2d95245c07070c2ed4 Mon Sep 17 00:00:00 2001 From: gguoss Date: Wed, 29 May 2019 08:02:22 +0800 Subject: [PATCH 2/2] Update according from review --- srml/session/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index a4b91a38b4ab4..1b7f7ae248bc1 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -165,7 +165,7 @@ decl_module! { /// This doesn't take effect until the next session. fn set_key(origin, key: T::SessionKey) { let who = ensure_signed(origin)?; - if >::get(&key) == None { + if >::get(&key).is_none() { // set new value for next session >::insert(who.clone(), key.clone()); >::insert(key, who);