From 0366f7b35cbd72aaafcc2e19faa5edf376ac4e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 10 Jul 2019 14:38:07 +0200 Subject: [PATCH] Check that validator set is not empty at genesis (#3083) * Check that the returned validator set is not empty * Move assert to session module * Clean up --- substrate/node/runtime/src/lib.rs | 2 +- substrate/srml/session/src/lib.rs | 2 ++ substrate/srml/staking/src/lib.rs | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index e97959095c..c021703a5a 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -411,8 +411,8 @@ construct_runtime!( Authorship: authorship::{Module, Call, Storage}, Indices: indices, Balances: balances, - Session: session::{Module, Call, Storage, Event, Config}, Staking: staking::{default, OfflineWorker}, + Session: session::{Module, Call, Storage, Event, Config}, Democracy: democracy::{Module, Call, Storage, Config, Event}, Council: collective::::{Module, Call, Storage, Origin, Event, Config}, TechnicalCommittee: collective::::{Module, Call, Storage, Origin, Event, Config}, diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index fe7a959724..1f9f60c76c 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -316,6 +316,8 @@ decl_storage! { let initial_validators = T::SelectInitialValidators::select_initial_validators() .unwrap_or_else(|| config.keys.iter().map(|(ref v, _)| v.clone()).collect()); + assert!(!initial_validators.is_empty(), "Empty validator set in genesis block!"); + let queued_keys: Vec<_> = initial_validators .iter() .cloned() diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index 8f3044daa8..519087aa20 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -599,7 +599,10 @@ decl_storage! { | { with_storage(storage, || { for &(ref stash, ref controller, balance, ref status) in &config.stakers { - assert!(T::Currency::free_balance(&stash) >= balance); + assert!( + T::Currency::free_balance(&stash) >= balance, + "Stash does not have enough balance to bond." + ); let _ = >::bond( T::Origin::from(Some(stash.clone()).into()), T::Lookup::unlookup(controller.clone()),