diff --git a/ethereum-consensus/Cargo.toml b/ethereum-consensus/Cargo.toml index 085638967..1438c071a 100644 --- a/ethereum-consensus/Cargo.toml +++ b/ethereum-consensus/Cargo.toml @@ -9,6 +9,8 @@ license = "MIT OR Apache-2.0" default = ["serde", "async"] serde = ["hex", "serde_json", "serde_yaml"] async = ["tokio", "tokio-stream", "async-stream"] +optimized = ["shuffling"] +shuffling = [] # supports optimized shuffling routines secret-key-debug = [ ] # enable if you want to be able to print `crypto::SecretKey` spec-tests = [] # enable extra features for testing diff --git a/ethereum-consensus/src/phase0/helpers.rs b/ethereum-consensus/src/phase0/helpers.rs index 54244f1b7..57f7ac7b3 100644 --- a/ethereum-consensus/src/phase0/helpers.rs +++ b/ethereum-consensus/src/phase0/helpers.rs @@ -416,14 +416,23 @@ pub fn compute_committee( count: usize, context: &Context, ) -> Result> { - let start = (indices.len() * index) / count; - let end = (indices.len()) * (index + 1) / count; - let mut committee = vec![0usize; end - start]; - for i in start..end { - let index = compute_shuffled_index(i, indices.len(), seed, context)?; - committee[i - start] = indices[index]; + if cfg!(feature = "shuffling") { + let shuffled_indices = compute_shuffled_indices(indices, seed, context); + let index_count = indices.len(); + let start = index_count * index / count; + let end = index_count * (index + 1) / count; + let committee = shuffled_indices[start..end].to_vec(); + Ok(committee) + } else { + let start = indices.len() * index / count; + let end = indices.len() * (index + 1) / count; + let mut committee = vec![0usize; end - start]; + for i in start..end { + let index = compute_shuffled_index(i, indices.len(), seed, context)?; + committee[i - start] = indices[index]; + } + Ok(committee) } - Ok(committee) } pub fn compute_epoch_at_slot(slot: Slot, context: &Context) -> Epoch {