Skip to content

Commit

Permalink
PR nits for #145
Browse files Browse the repository at this point in the history
  • Loading branch information
Sword-Smith committed May 21, 2024
1 parent f97a4c8 commit bd7a252
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/models/state/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 12 additions & 16 deletions src/util_types/mutator_set/removal_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,23 +78,19 @@ impl AbsoluteIndexSet {
&self,
mutator_set: &MutatorSetAccumulator,
) -> Result<(HashMap<u64, Vec<u128>>, Vec<u128>), 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))
}
Expand Down

0 comments on commit bd7a252

Please sign in to comment.