Crate bitcoin_bloom

source ·

Structs

  • | BloomFilter is a probabilistic filter | which SPV clients provide so that we | can filter the transactions we send | them. | | This allows for significantly more | efficient transaction and block downloads. | | Because bloom filters are probabilistic, | a SPV node can increase the false- positive | rate, making us send it transactions | which aren’t actually its, allowing | clients to trade more bandwidth for | more privacy by obfuscating which keys | are controlled by them. |
  • | RollingBloomFilter is a probabilistic “keep | track of most recently inserted” set. | Construct it with the number of items to keep | track of, and a false-positive rate. Unlike | CBloomFilter, by default nTweak is set to | a cryptographically secure random value for | you. Similarly rather than clear() the method | reset() is provided, which also changes nTweak | to decrease the impact of false-positives. | | contains(item) will always return true if item | was one of the last N to 1.5*N insert()’ed | … but may also return true for items that | were not inserted. | | It needs around 1.8 bytes per element per | factor 0.1 of false positive rate. | | For example, if we want 1000 elements, we’d | need: | | - ~1800 bytes for a false positive rate of 0.1 | - ~3600 bytes for a false positive rate of 0.01 | - ~5400 bytes for a false positive rate of 0.001 | | If we make these simplifying assumptions: | | - logFpRate / log(0.5) doesn’t get rounded or | clamped in the nHashFuncs calculation | | - nElements is even, so that | nEntriesPerGeneration == nElements / 2 | | Then we get a more accurate estimate for filter | bytes: | | 3/(log(256)*log(2)) * log(1/fpRate) * nElements

Enums

  • | First two bits of nFlags control how | much IsRelevantAndUpdate actually | updates | | The remaining bits are reserved |

Constants

Functions

  • | A replacement for x % n. This assumes that | x and n are 32bit integers, and x is | a uniformly random distributed 32bit value | which should be the case for a good hash. See | https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
  • | Similar to BloomFilter::Hash |