This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
Bloom Filter: wrong number of hash functions used #9843
Labels
A3-stale 🍃
Pull request did not receive any updates in a long time. No review needed at this stage. Close it.
F3-annoyance 💩
The client behaves within expectations, however this “expected behaviour” itself is at issue.
F8-enhancement 🎊
An additional feature request.
M4-core ⛓
Core client code / Rust.
Milestone
The number of bloom filter hash functions used is actually one less than intended.
Both https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L133 and https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L145 iterate
k_i
starting at 0 up to (and including)self.k_num - 1
, for a total ofself.k_num
iterations. The intent is to getself.k_num
statistically independent hash values to set bits or check for bits inself.bitmap
, as is normal for bloom filter implementations. However, the code forbloom_hash
at https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L180 returns the same hash value fork_i
equal to either 0 or 1. This means that, in effect, we are gettingself.k_num - 1
independent hashes, instead of the expectedself.k_num
hashes. Since the value ofself.k_num
is computed innew
at https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L88 withoptimum_k_num
https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L164 the value is correct, but the actual number of independent hash function used is incorrect; it is actually one fewer.However,
hash_backward_compatibility_for_new
https://github.com/paritytech/parity-ethereum/blob/master/util/bloom/src/lib.rs#L246 seem to indicate that there is a strong desire to retain backward compatibility. Either a fix -- including changing the backwards compatibility tests -- or comments explaining why we want the first and second hash functions to be identical would be nice, because future readers of this code will want to know.The text was updated successfully, but these errors were encountered: