From bd7a25225ba07d84d706667f17748a12432f7a3f Mon Sep 17 00:00:00 2001 From: Thorkil Vaerge Date: Tue, 21 May 2024 13:05:33 +0200 Subject: [PATCH] PR nits for #145 --- src/models/state/mempool.rs | 2 +- src/util_types/mutator_set/removal_record.rs | 28 +++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/models/state/mempool.rs b/src/models/state/mempool.rs index ffb91237..f65ba1b1 100644 --- a/src/models/state/mempool.rs +++ b/src/models/state/mempool.rs @@ -112,7 +112,7 @@ impl Mempool { self.tx_dictionary.get(&transaction_id) } - /// Returns `Some(txid, transaction)` iff a transcation conflicts with a transaction + /// Returns `Some(txid, transaction)` iff a transaction conflicts with a transaction /// that's already in the mempool. Returns `None` otherwise. fn transaction_conflicts_with( &self, diff --git a/src/util_types/mutator_set/removal_record.rs b/src/util_types/mutator_set/removal_record.rs index 05aa6202..e0436d9a 100644 --- a/src/util_types/mutator_set/removal_record.rs +++ b/src/util_types/mutator_set/removal_record.rs @@ -67,8 +67,8 @@ impl AbsoluteIndexSet { &mut self.0 } - /// Split the [`AbsoluteIndexSet`] into two hash maps, one for chunks in - /// the inactive part of the Bloom filter and another one for chunks in the + /// Split the [`AbsoluteIndexSet`] into two parts, one for chunks in the + /// inactive part of the Bloom filter and another one for chunks in the /// active part of the Bloom filter. /// /// Returns an error if a removal index is a future value, i.e. one that's @@ -78,23 +78,19 @@ impl AbsoluteIndexSet { &self, mutator_set: &MutatorSetAccumulator, ) -> Result<(HashMap>, Vec), MutatorSetError> { - let mut inactive = indices_to_hash_map(&self.0); let (aw_chunk_index_min, aw_chunk_index_max) = mutator_set.active_window_chunk_interval(); - let mut active: Vec<_> = Default::default(); - for (chunk_index, absolute_indices) in inactive.iter() { - if *chunk_index > aw_chunk_index_max { - return Err(MutatorSetError::AbsoluteRemovalIndexIsFutureIndex { - current_max_chunk_index: aw_chunk_index_max, - saw_chunk_index: *chunk_index, - }); - } - - if *chunk_index >= aw_chunk_index_min { - active.extend(absolute_indices); - } + let (inactive, active): (HashMap<_, _>, HashMap<_, _>) = indices_to_hash_map(&self.0) + .into_iter() + .partition(|&(chunk_index, _)| chunk_index < aw_chunk_index_min); + + if let Some(chunk_index) = active.keys().find(|&&k| k > aw_chunk_index_max) { + return Err(MutatorSetError::AbsoluteRemovalIndexIsFutureIndex { + current_max_chunk_index: aw_chunk_index_max, + saw_chunk_index: *chunk_index, + }); } - inactive.retain(|x, _| *x < aw_chunk_index_min); + let active = active.into_values().flatten().collect_vec(); Ok((inactive, active)) }