Move active_validators into own crate
This commit is contained in:
parent
a34266de0a
commit
da25a66196
@ -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",
|
||||
|
7
beacon_chain/utils/active-validators/Cargo.toml
Normal file
7
beacon_chain/utils/active-validators/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "active-validators"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
|
||||
[dependencies]
|
||||
types = { path = "../../types" }
|
@ -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()
|
@ -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" }
|
||||
|
@ -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::{
|
||||
|
@ -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>>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user