![]() |
Bitcoin ABC
0.26.3
P2P Digital Currency
|
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transactions we send them. More...
#include <bloom.h>
Public Member Functions | |
CBloomFilter (const uint32_t nElements, const double nFPRate, const uint32_t nTweak, uint8_t nFlagsIn) | |
Creates a new bloom filter which will provide the given fp rate when filled with the given number of elements. More... | |
CBloomFilter () | |
SERIALIZE_METHODS (CBloomFilter, obj) | |
void | insert (const std::vector< uint8_t > &vKey) |
void | insert (const COutPoint &outpoint) |
void | insert (const uint256 &hash) |
bool | contains (const std::vector< uint8_t > &vKey) const |
bool | contains (const COutPoint &outpoint) const |
bool | contains (const uint256 &hash) const |
bool | IsWithinSizeConstraints () const |
True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS (catch a filter which was just deserialized which was too big) More... | |
bool | MatchAndInsertOutputs (const CTransaction &tx) |
Scans output scripts for matches and adds those outpoints to the filter for spend detection. More... | |
bool | MatchInputs (const CTransaction &tx) |
Scan inputs to see if the spent outpoints are a match, or the input scripts contain matching elements. More... | |
bool | IsRelevantAndUpdate (const CTransaction &tx) |
Check if the transaction is relevant for any reason. More... | |
Private Member Functions | |
uint32_t | Hash (uint32_t nHashNum, const std::vector< uint8_t > &vDataToHash) const |
Private Attributes | |
std::vector< uint8_t > | vData |
uint32_t | nHashFuncs |
uint32_t | nTweak |
uint8_t | nFlags |
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.
CBloomFilter::CBloomFilter | ( | const uint32_t | nElements, |
const double | nFPRate, | ||
const uint32_t | nTweakIn, | ||
uint8_t | nFlagsIn | ||
) |
Creates a new bloom filter which will provide the given fp rate when filled with the given number of elements.
The ideal size for a bloom filter with a given number of elements and false positive rate is:
Note that if the given parameters will result in a filter outside the bounds of the protocol limits, the filter created will be as close to the given parameters as possible within the protocol limits. This will apply if nFPRate is very low or nElements is unreasonably high. nTweak is a constant which is added to the seed value passed to the hash function. It should generally always be a random value (and is largely only exposed for unit testing) nFlags should be one of the BLOOM_UPDATE_* enums (not _MASK)
The ideal number of hash functions is filter size * ln(2) / number of elements. Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits. See https://en.wikipedia.org/wiki/Bloom_filter for an explanation of these formulas.
bool CBloomFilter::contains | ( | const COutPoint & | outpoint | ) | const |
bool CBloomFilter::contains | ( | const std::vector< uint8_t > & | vKey | ) | const |
bool CBloomFilter::contains | ( | const uint256 & | hash | ) | const |
|
inlineprivate |
void CBloomFilter::insert | ( | const COutPoint & | outpoint | ) |
void CBloomFilter::insert | ( | const std::vector< uint8_t > & | vKey | ) |
void CBloomFilter::insert | ( | const uint256 & | hash | ) |
|
inline |
bool CBloomFilter::IsWithinSizeConstraints | ( | ) | const |
bool CBloomFilter::MatchAndInsertOutputs | ( | const CTransaction & | tx | ) |
bool CBloomFilter::MatchInputs | ( | const CTransaction & | tx | ) |
|
inline |