Configurable maximum validators (#2586)

* guide: max_validators

* guide: new approach

* restrict validators based on configurable max

* add some tests

* fix wasm build (Vec)

* clean up warnings

* add logging

* set validator indices in tests as well

* fix common tests

* Update runtime/parachains/src/util.rs

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
Robert Habermeier
2021-03-09 12:38:55 -06:00
committed by GitHub
parent 30e4a67f0c
commit 8b4f46d2df
17 changed files with 300 additions and 83 deletions
+19 -1
View File
@@ -17,7 +17,8 @@
//! Utilities that don't belong to any particular module but may draw
//! on all modules.
use primitives::v1::{Id as ParaId, PersistedValidationData, Hash};
use primitives::v1::{Id as ParaId, PersistedValidationData, Hash, ValidatorIndex};
use sp_std::vec::Vec;
use crate::{configuration, paras, hrmp};
@@ -39,3 +40,20 @@ pub fn make_persisted_validation_data<T: paras::Config + hrmp::Config>(
max_pov_size: config.max_pov_size,
})
}
/// Take the active subset of a set containing all validators.
pub fn take_active_subset<T: Clone>(active_validators: &[ValidatorIndex], set: &[T]) -> Vec<T> {
let subset: Vec<_> = active_validators.iter()
.filter_map(|i| set.get(i.0 as usize))
.cloned()
.collect();
if subset.len() != active_validators.len() {
log::warn!(
target: "runtime::parachains",
"Took active validators from set with wrong size",
);
}
subset
}