diff --git a/eth2/state_processing/src/per_epoch_processing/get_attesting_indices.rs b/eth2/state_processing/src/common/get_attesting_indices.rs similarity index 63% rename from eth2/state_processing/src/per_epoch_processing/get_attesting_indices.rs rename to eth2/state_processing/src/common/get_attesting_indices.rs index 1526c54be..a45eeb881 100644 --- a/eth2/state_processing/src/per_epoch_processing/get_attesting_indices.rs +++ b/eth2/state_processing/src/common/get_attesting_indices.rs @@ -1,7 +1,22 @@ use crate::common::verify_bitfield_length; use types::*; -/// Returns validator indices which participated in the attestation. +/// Returns validator indices which participated in the attestation, sorted by increasing index. +/// +/// Spec v0.6.1 +pub fn get_attesting_indices( + state: &BeaconState, + attestation_data: &AttestationData, + bitfield: &Bitfield, +) -> Result, BeaconStateError> { + get_attesting_indices_unsorted(state, attestation_data, bitfield).map(|mut indices| { + // Fast unstable sort is safe because validator indices are unique + indices.sort_unstable(); + indices + }) +} + +/// Returns validator indices which participated in the attestation, unsorted. /// /// Spec v0.6.1 pub fn get_attesting_indices_unsorted( diff --git a/eth2/state_processing/src/common/mod.rs b/eth2/state_processing/src/common/mod.rs index 896dfad0d..09c9d265f 100644 --- a/eth2/state_processing/src/common/mod.rs +++ b/eth2/state_processing/src/common/mod.rs @@ -1,7 +1,9 @@ mod exit; +mod get_attesting_indices; mod slash_validator; mod verify_bitfield; pub use exit::initiate_validator_exit; +pub use get_attesting_indices::{get_attesting_indices, get_attesting_indices_unsorted}; pub use slash_validator::slash_validator; pub use verify_bitfield::verify_bitfield_length; diff --git a/eth2/state_processing/src/per_epoch_processing.rs b/eth2/state_processing/src/per_epoch_processing.rs index 69ee565fb..5253cd95c 100644 --- a/eth2/state_processing/src/per_epoch_processing.rs +++ b/eth2/state_processing/src/per_epoch_processing.rs @@ -10,7 +10,6 @@ use winning_root::{winning_root, WinningRoot}; pub mod apply_rewards; pub mod errors; -pub mod get_attesting_indices; pub mod inclusion_distance; pub mod process_slashings; pub mod registry_updates; diff --git a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs index 169007154..a4062b988 100644 --- a/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs +++ b/eth2/state_processing/src/per_epoch_processing/validator_statuses.rs @@ -1,5 +1,5 @@ -use super::get_attesting_indices::get_attesting_indices_unsorted; use super::WinningRootHashSet; +use crate::common::get_attesting_indices_unsorted; use types::*; /// Sets the boolean `var` on `self` to be true if it is true on `other`. Otherwise leaves `self` diff --git a/eth2/state_processing/src/per_epoch_processing/winning_root.rs b/eth2/state_processing/src/per_epoch_processing/winning_root.rs index 9a1da14d3..550e1eaf4 100644 --- a/eth2/state_processing/src/per_epoch_processing/winning_root.rs +++ b/eth2/state_processing/src/per_epoch_processing/winning_root.rs @@ -1,4 +1,4 @@ -use super::get_attesting_indices::get_attesting_indices_unsorted; +use crate::common::get_attesting_indices_unsorted; use std::collections::{HashMap, HashSet}; use tree_hash::TreeHash; use types::*;