Move active_validators into own crate

This commit is contained in:
Paul Hauner 2018-10-23 23:42:01 +02:00
parent a34266de0a
commit da25a66196
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
6 changed files with 21 additions and 5 deletions

View File

@ -34,6 +34,7 @@ name = "lighthouse"
members = [
"beacon_chain/chain",
"beacon_chain/types",
"beacon_chain/utils/active-validators",
"beacon_chain/utils/bls",
"beacon_chain/utils/boolean-bitfield",
"beacon_chain/utils/hashing",

View File

@ -0,0 +1,7 @@
[package]
name = "active-validators"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
[dependencies]
types = { path = "../../types" }

View File

@ -1,8 +1,14 @@
extern crate types;
use types::{
ValidatorRecord,
ValidatorStatus,
};
pub fn validator_is_active(v: &ValidatorRecord) -> bool {
v.status == ValidatorStatus::Active as u8
}
/// Returns the indicies of each active validator in a given vec of validators.
pub fn active_validator_indices(validators: &[ValidatorRecord])
-> Vec<usize>
@ -10,9 +16,10 @@ pub fn active_validator_indices(validators: &[ValidatorRecord])
validators.iter()
.enumerate()
.filter_map(|(i, validator)| {
match validator.status {
x if x == ValidatorStatus::Active as u8 => Some(i),
_ => None
if validator_is_active(&validator) {
Some(i)
} else {
None
}
})
.collect()

View File

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
[dependencies]
active-validators = { path = "../utils/active-validators" }
honey-badger-split = { path = "../utils/honey-badger-split" }
types = { path = "../types" }
vec_shuffle = { path = "../utils/vec_shuffle" }

View File

@ -1,8 +1,8 @@
extern crate active_validators;
extern crate honey_badger_split;
extern crate vec_shuffle;
extern crate types;
mod active_validator_indices;
mod shuffle;
pub use shuffle::{

View File

@ -1,5 +1,6 @@
use std::cmp::min;
use active_validators::active_validator_indices;
use honey_badger_split::SplitExt;
use vec_shuffle::{
shuffle,
@ -11,7 +12,6 @@ use types::{
ChainConfig,
};
use super::active_validator_indices::active_validator_indices;
type DelegatedCycle = Vec<Vec<ShardAndCommittee>>;