Move active_validators into own crate
This commit is contained in:
parent
a34266de0a
commit
da25a66196
@ -34,6 +34,7 @@ name = "lighthouse"
|
|||||||
members = [
|
members = [
|
||||||
"beacon_chain/chain",
|
"beacon_chain/chain",
|
||||||
"beacon_chain/types",
|
"beacon_chain/types",
|
||||||
|
"beacon_chain/utils/active-validators",
|
||||||
"beacon_chain/utils/bls",
|
"beacon_chain/utils/bls",
|
||||||
"beacon_chain/utils/boolean-bitfield",
|
"beacon_chain/utils/boolean-bitfield",
|
||||||
"beacon_chain/utils/hashing",
|
"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::{
|
use types::{
|
||||||
ValidatorRecord,
|
ValidatorRecord,
|
||||||
ValidatorStatus,
|
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.
|
/// Returns the indicies of each active validator in a given vec of validators.
|
||||||
pub fn active_validator_indices(validators: &[ValidatorRecord])
|
pub fn active_validator_indices(validators: &[ValidatorRecord])
|
||||||
-> Vec<usize>
|
-> Vec<usize>
|
||||||
@ -10,9 +16,10 @@ pub fn active_validator_indices(validators: &[ValidatorRecord])
|
|||||||
validators.iter()
|
validators.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(i, validator)| {
|
.filter_map(|(i, validator)| {
|
||||||
match validator.status {
|
if validator_is_active(&validator) {
|
||||||
x if x == ValidatorStatus::Active as u8 => Some(i),
|
Some(i)
|
||||||
_ => None
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
active-validators = { path = "../utils/active-validators" }
|
||||||
honey-badger-split = { path = "../utils/honey-badger-split" }
|
honey-badger-split = { path = "../utils/honey-badger-split" }
|
||||||
types = { path = "../types" }
|
types = { path = "../types" }
|
||||||
vec_shuffle = { path = "../utils/vec_shuffle" }
|
vec_shuffle = { path = "../utils/vec_shuffle" }
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
extern crate active_validators;
|
||||||
extern crate honey_badger_split;
|
extern crate honey_badger_split;
|
||||||
extern crate vec_shuffle;
|
extern crate vec_shuffle;
|
||||||
extern crate types;
|
extern crate types;
|
||||||
|
|
||||||
mod active_validator_indices;
|
|
||||||
mod shuffle;
|
mod shuffle;
|
||||||
|
|
||||||
pub use shuffle::{
|
pub use shuffle::{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
|
use active_validators::active_validator_indices;
|
||||||
use honey_badger_split::SplitExt;
|
use honey_badger_split::SplitExt;
|
||||||
use vec_shuffle::{
|
use vec_shuffle::{
|
||||||
shuffle,
|
shuffle,
|
||||||
@ -11,7 +12,6 @@ use types::{
|
|||||||
ChainConfig,
|
ChainConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::active_validator_indices::active_validator_indices;
|
|
||||||
|
|
||||||
type DelegatedCycle = Vec<Vec<ShardAndCommittee>>;
|
type DelegatedCycle = Vec<Vec<ShardAndCommittee>>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user