From 2e96e9769b99d1c07cd6c3045e92d48769746939 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 22 May 2025 12:14:46 +1000 Subject: [PATCH] Use slice.is_sorted now that it's stable (#7507) Use slice.is_sorted which was stabilised in Rust 1.82.0 I thought there would be more places we could use this, but it seems we often want to check strict monotonicity (i.e. sorted + no duplicates) --- beacon_node/beacon_chain/src/test_utils.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index ca083f0572..5248f73311 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -2671,10 +2671,7 @@ where mut latest_block_hash: Option, sync_committee_strategy: SyncCommitteeStrategy, ) -> AddBlocksResult { - assert!( - slots.windows(2).all(|w| w[0] <= w[1]), - "Slots have to be sorted" - ); // slice.is_sorted() isn't stabilized at the moment of writing this + assert!(slots.is_sorted(), "Slots have to be in ascending order"); let mut block_hash_from_slot: HashMap = HashMap::new(); let mut state_hash_from_slot: HashMap = HashMap::new(); for slot in slots { @@ -2714,10 +2711,7 @@ where mut latest_block_hash: Option, sync_committee_strategy: SyncCommitteeStrategy, ) -> AddBlocksResult { - assert!( - slots.windows(2).all(|w| w[0] <= w[1]), - "Slots have to be sorted" - ); // slice.is_sorted() isn't stabilized at the moment of writing this + assert!(slots.is_sorted(), "Slots have to be in ascending order"); let mut block_hash_from_slot: HashMap = HashMap::new(); let mut state_hash_from_slot: HashMap = HashMap::new(); for slot in slots {