Skip to content

Commit

Permalink
chore: fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Feb 3, 2025
1 parent 793316d commit 56a51cc
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 621 deletions.
708 changes: 108 additions & 600 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ primitive-types = "0.12"
rand = "0.8"
crypto-bigint = "0.5.5"
ahash = "0.8"
twox-hash = "2.1"

# Std extensions
lazy_static = { version = "1.4", default-features = false }
Expand All @@ -255,6 +256,7 @@ httpmock = "0.7.0"
mockall = "0.13.0"
fdlimit = "0.3.0"
assert_matches = "1.5"
criterion = { version = "0.5", features = ["html_reports"] }

# Macros
indoc = "2"
Expand Down
6 changes: 6 additions & 0 deletions crates/madara/client/block_production/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ mod tests {
},
pending_state_diff.clone(),
converted_classes.clone(),
None,
Some(visited_segments.clone()),
Some(bouncer_weights),
)
Expand Down Expand Up @@ -1195,6 +1196,7 @@ mod tests {
},
ready_state_diff.clone(),
ready_converted_classes.clone(),
None,
Some(visited_segments.clone()),
Some(bouncer_weights),
)
Expand Down Expand Up @@ -1276,6 +1278,7 @@ mod tests {
},
pending_state_diff.clone(),
pending_converted_classes.clone(),
None,
Some(visited_segments.clone()),
Some(bouncer_weights),
)
Expand Down Expand Up @@ -1463,6 +1466,7 @@ mod tests {
},
pending_state_diff.clone(),
converted_classes.clone(),
None,
None, // No visited segments!
Some(bouncer_weights),
)
Expand Down Expand Up @@ -1596,6 +1600,7 @@ mod tests {
},
pending_state_diff.clone(),
converted_classes.clone(),
None,
Some(visited_segments.clone()),
Some(bouncer_weights),
)
Expand Down Expand Up @@ -1696,6 +1701,7 @@ mod tests {
},
pending_state_diff.clone(),
converted_classes.clone(),
None,
Some(visited_segments.clone()),
Some(bouncer_weights),
)
Expand Down
7 changes: 2 additions & 5 deletions crates/madara/primitives/bloom_filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ starknet-types-core.workspace = true
thiserror.workspace = true

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
twox-hash = "2.1"

twox-hash.workspace = true
criterion.workspace = true
rand.workspace = true
plotters = "0.3"
statistical = "1.0"
rayon.workspace = true
bincode.workspace = true
proptest.workspace = true
Expand Down
11 changes: 0 additions & 11 deletions crates/madara/primitives/bloom_filter/benches/bloom_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use twox_hash::XxHash64;
const KEY_SIZE: usize = 32;
const HASH_COUNT: u8 = 7;
const BITS_PER_ELEMENT: f64 = 9.6;
const FALSE_POSITIF_RATE: f64 = 0.01;

const TEST_DATA_SIZE: usize = 100_000;
const LOOKUP_FILL_RATIO: f64 = 0.5;
Expand Down Expand Up @@ -90,16 +89,6 @@ fn bench_sequential_insertion<H: std::hash::Hasher + Default>(c: &mut Criterion,
});
});

// group.bench_function("non atomic", |b| {
// b.iter(|| {
// let mut filter = BloomFilter::<H, BitStore>::optimal(TEST_DATA_SIZE, FALSE_POSITIVE_RATE)
// .expect("Failed to create optimal filter");
// for item in test_data {
// filter.add(black_box(item));
// }
// });
// });

group.finish();
}

Expand Down
3 changes: 2 additions & 1 deletion crates/madara/primitives/bloom_filter/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{AtomicBitStore, BitStore, BloomFilter, PreCalculatedHashes};
/// where:
/// - k is the number of hash functions
/// - p is the desired false positive rate (0.01)
///
/// Reference: [Bloom, B. H. (1970). "Space/Time Trade-offs in Hash Coding with Allowable Errors"](https://dl.acm.org/doi/10.1145/362686.362692)
const HASH_COUNT: u8 = 7;

Expand Down Expand Up @@ -67,7 +68,7 @@ impl EventBloomWriter {
}

pub fn size(&self) -> u64 {
self.filter.len()
self.filter.size()
}

fn events_to_bloom_keys<'a, I>(events: I) -> impl Iterator<Item = [u8; 33]> + 'a
Expand Down
2 changes: 1 addition & 1 deletion crates/madara/primitives/bloom_filter/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<H: Hasher + Default> BloomFilter<H, AtomicBitStore> {

impl<H: Hasher + Default, B> BloomFilter<H, B> {
/// Returns the size of the Bloom filter in bits.
pub fn len(&self) -> u64 {
pub fn size(&self) -> u64 {
self.bit_size
}

Expand Down
2 changes: 1 addition & 1 deletion crates/madara/primitives/bloom_filter/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl AtomicBitStore {
}

/// Converts this atomic store into a regular BitStore.
pub(crate) fn to_readonly(self) -> BitStore {
pub(crate) fn to_readonly(&self) -> BitStore {
let bits = self.bits.iter().map(|b| b.load(Ordering::Relaxed)).collect();
BitStore::new_from_slice(bits)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn test_actual_false_positive_rate() {
fn test_size_alignment() {
// Test that the filter size is properly aligned to 64-bit boundaries
let filter = BloomFilter::<DefaultHasher, AtomicBitStore>::new(100, HASH_COUNT);
assert_eq!(filter.len() % 64, 0, "Filter size should be aligned to 64 bits");
assert_eq!(filter.size() % 64, 0, "Filter size should be aligned to 64 bits");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use proptest::prelude::*;
use rayon::prelude::*;
use std::collections::HashSet;
use std::hash::DefaultHasher;
use tests::utils::{create_filter, HASH_COUNT};
use tests::utils::create_filter;

proptest! {
#[test]
Expand Down

0 comments on commit 56a51cc

Please sign in to comment.