diff --git a/src/node/bloom.rs b/src/node/bloom.rs index 17e67de..a86f729 100644 --- a/src/node/bloom.rs +++ b/src/node/bloom.rs @@ -87,7 +87,7 @@ impl Node { // operator to see one clear message, not spam. let max_fpr = self.config().node.bloom.max_inbound_fpr; let out_fill = sent_filter.fill_ratio(); - let out_fpr = out_fill.powi(sent_filter.hash_count() as i32); + let out_fpr = sent_filter.fpr(); if out_fpr > max_fpr { let now = std::time::Instant::now(); let should_warn = self @@ -213,7 +213,7 @@ impl Node { // to wipe a victim's contribution to aggregation. let max_fpr = self.config().node.bloom.max_inbound_fpr; let fill = announce.filter.fill_ratio(); - let fpr = fill.powi(announce.filter.hash_count() as i32); + let fpr = announce.filter.fpr(); if fpr > max_fpr { self.metrics() .bloom diff --git a/src/proto/bloom/core.rs b/src/proto/bloom/core.rs index 2876faf..6ef9600 100644 --- a/src/proto/bloom/core.rs +++ b/src/proto/bloom/core.rs @@ -139,6 +139,11 @@ impl BloomFilter { self.count_ones() as f64 / self.num_bits as f64 } + /// Current false-positive rate: fill ratio raised to the hash count. + pub fn fpr(&self) -> f64 { + self.fill_ratio().powi(self.hash_count as i32) + } + /// Estimate the number of elements in the filter. /// /// Uses the formula: n = -(m/k) * ln(1 - X/m) @@ -160,7 +165,7 @@ impl BloomFilter { } let fill = x / m; - let fpr = fill.powi(self.hash_count as i32); + let fpr = self.fpr(); if fpr > max_fpr { return None; }