From 996107ee28296e6f5dd9f8b9bb6007ad14064860 Mon Sep 17 00:00:00 2001
From: Gavin Wood <gavin@parity.io>
Date: Sat, 29 May 2021 11:17:26 +0100
Subject: [PATCH] Session key should be settable at genesis even for
 non-endowed accounts (#8942)

* Session key should be settable at genesis even for non-endowed accounts

* Docs
---
 substrate/frame/session/src/lib.rs | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs
index cbe70598a91..8574979ef2f 100644
--- a/substrate/frame/session/src/lib.rs
+++ b/substrate/frame/session/src/lib.rs
@@ -442,11 +442,13 @@ decl_storage! {
 			for (account, val, keys) in config.keys.iter().cloned() {
 				<Module<T>>::inner_set_keys(&val, keys)
 					.expect("genesis config must not contain duplicates; qed");
-				assert!(
-					frame_system::Pallet::<T>::inc_consumers(&account).is_ok(),
-					"Account ({:?}) does not exist at genesis to set key. Account not endowed?",
-					account,
-				);
+				if frame_system::Pallet::<T>::inc_consumers(&account).is_err() {
+					// This will leak a provider reference, however it only happens once (at
+					// genesis) so it's really not a big deal and we assume that the user wants to
+					// do this since it's the only way a non-endowed account can contain a session
+					// key.
+					frame_system::Pallet::<T>::inc_providers(&account);
+				}
 			}
 
 			let initial_validators_0 = T::SessionManager::new_session(0)
-- 
GitLab