diff --git a/beacon_node/lighthouse_network/src/peer_manager/mod.rs b/beacon_node/lighthouse_network/src/peer_manager/mod.rs index 01cc1611058..80ec123c014 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/mod.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/mod.rs @@ -12,6 +12,7 @@ use lru_cache::LRUTimeCache; use peerdb::{BanOperation, BanResult, ScoreUpdateResult}; use rand::seq::SliceRandom; use smallvec::SmallVec; +use std::collections::BTreeSet; use std::{ sync::Arc, time::{Duration, Instant}, @@ -1470,7 +1471,7 @@ impl PeerManager { &self, peer_id: &PeerId, custody_group_count: u64, - ) -> Result, String> { + ) -> Result, String> { // If we don't have a node id, we cannot compute the custody duties anyway let node_id = peer_id_to_node_id(peer_id)?; let spec = &self.network_globals.spec; diff --git a/consensus/types/src/data_column_custody_group.rs b/consensus/types/src/data_column_custody_group.rs index 9e9505da9f1..5966d4728f7 100644 --- a/consensus/types/src/data_column_custody_group.rs +++ b/consensus/types/src/data_column_custody_group.rs @@ -1,9 +1,9 @@ use crate::{ChainSpec, ColumnIndex, DataColumnSubnetId}; use alloy_primitives::U256; use itertools::Itertools; -use maplit::hashset; +use maplit::btreeset; use safe_arith::{ArithError, SafeArith}; -use std::collections::HashSet; +use std::collections::{BTreeSet, HashSet}; pub type CustodyIndex = u64; @@ -24,14 +24,14 @@ pub fn get_custody_groups( raw_node_id: [u8; 32], custody_group_count: u64, spec: &ChainSpec, -) -> Result, DataColumnCustodyGroupError> { +) -> Result, DataColumnCustodyGroupError> { if custody_group_count > spec.number_of_custody_groups { return Err(DataColumnCustodyGroupError::InvalidCustodyGroupCount( custody_group_count, )); } - let mut custody_groups: HashSet = hashset![]; + let mut custody_groups: BTreeSet = btreeset![]; let mut current_id = U256::from_be_slice(&raw_node_id); while custody_groups.len() < custody_group_count as usize { let mut node_id_bytes = [0u8; 32]; @@ -141,4 +141,26 @@ mod test { assert_eq!(subnets.len(), subnets_per_custody_group as usize); } } + + #[test] + fn test_get_custody_groups_sorted() { + let mut spec = ChainSpec::mainnet(); + spec.number_of_custody_groups = 64; + let custody_group_count = 32; + let node_id = [1u8; 32]; + + let custody_groups = get_custody_groups(node_id, custody_group_count, &spec) + .expect("should compute custody groups successfully"); + + let vec = custody_groups.iter().collect::>(); + let sorted_vec = { + let mut temp_vec = vec.clone(); + temp_vec.sort(); + temp_vec + }; + + for (a, b) in sorted_vec.iter().zip(vec.iter()) { + assert_eq!(a, b); + } + } } diff --git a/testing/ef_tests/src/cases/get_custody_groups.rs b/testing/ef_tests/src/cases/get_custody_groups.rs index 1c1294305f3..0dc50ddc54e 100644 --- a/testing/ef_tests/src/cases/get_custody_groups.rs +++ b/testing/ef_tests/src/cases/get_custody_groups.rs @@ -36,7 +36,6 @@ impl Case for GetCustodyGroups { let mut computed = get_custody_groups(raw_node_id, self.custody_group_count, &spec) .map(|set| set.into_iter().collect::>()) .expect("should compute custody groups"); - computed.sort(); let expected = &self.result; if computed == *expected {