Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
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 unsigned int nElements, const double nFPRate, const unsigned int nTweak, unsigned char nFlagsIn) | |
Creates a new bloom filter which will provide the given fp rate when filled with the given number of elements 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. More... | |
CBloomFilter () | |
template<typename Stream , typename Operation > | |
void | SerializationOp (Stream &s, Operation ser_action) |
void | insert (const std::vector< unsigned char > &vKey) |
void | insert (const COutPoint &outpoint) |
void | insert (const uint256 &hash) |
bool | contains (const std::vector< unsigned char > &vKey) const |
bool | contains (const COutPoint &outpoint) const |
bool | contains (const uint256 &hash) const |
bool | contains (const uint160 &hash) const |
void | clear () |
void | reset (const unsigned int nNewTweak) |
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 | IsRelevantAndUpdate (const CTransaction &tx) |
Also adds any outputs which match the filter to the filter (to match their spending txes) More... | |
void | UpdateEmptyFull () |
Checks for empty and full filters to avoid wasting cpu. More... | |
Public Attributes | |
ADD_SERIALIZE_METHODS | |
Private Member Functions | |
unsigned int | Hash (unsigned int nHashNum, const std::vector< unsigned char > &vDataToHash) const |
CBloomFilter (const unsigned int nElements, const double nFPRate, const unsigned int nTweak) | |
bool | CheckScript (const CScript &script) const |
bool | CheckSpecialTransactionMatchesAndUpdate (const CTransaction &tx) |
Private Attributes | |
std::vector< unsigned char > | vData |
bool | isFull |
bool | isEmpty |
unsigned int | nHashFuncs |
unsigned int | nTweak |
unsigned char | nFlags |
Friends | |
class | CRollingBloomFilter |
Detailed Description
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.
Constructor & Destructor Documentation
◆ CBloomFilter() [1/3]
|
private |
◆ CBloomFilter() [2/3]
CBloomFilter::CBloomFilter | ( | const unsigned int | nElements, |
const double | nFPRate, | ||
const unsigned int | nTweakIn, | ||
unsigned char | nFlagsIn | ||
) |
Creates a new bloom filter which will provide the given fp rate when filled with the given number of elements 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.
The ideal size for a bloom filter with a given number of elements and false positive rate is:
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)
- nElements * log(fp rate) / ln(2)^2 We ignore filter parameters which will create a bloom filter larger than the protocol limits 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
◆ CBloomFilter() [3/3]
Member Function Documentation
◆ CheckScript()
|
private |
Definition at line 144 of file bloom.cpp.
References prevector< N, T, Size, Diff >::begin(), contains(), prevector< N, T, Size, Diff >::end(), and CScript::GetOp().
Referenced by CheckSpecialTransactionMatchesAndUpdate(), and IsRelevantAndUpdate().
◆ CheckSpecialTransactionMatchesAndUpdate()
|
private |
Definition at line 167 of file bloom.cpp.
References BLOOM_UPDATE_ALL, BLOOM_UPDATE_MASK, CheckScript(), CProRegTx::collateralOutpoint, contains(), CTransaction::GetHash(), GetTxPayload(), insert(), CProRegTx::keyIDOwner, CProRegTx::keyIDVoting, CProUpRegTx::keyIDVoting, LogPrintf, nFlags, CTransaction::nType, CTransaction::nVersion, CProUpServTx::proTxHash, CProUpRegTx::proTxHash, CProUpRevTx::proTxHash, CProUpServTx::scriptOperatorPayout, CProRegTx::scriptPayout, CProUpRegTx::scriptPayout, TRANSACTION_COINBASE, TRANSACTION_NORMAL, TRANSACTION_PROVIDER_REGISTER, TRANSACTION_PROVIDER_UPDATE_REGISTRAR, TRANSACTION_PROVIDER_UPDATE_REVOKE, TRANSACTION_PROVIDER_UPDATE_SERVICE, and TRANSACTION_QUORUM_COMMITMENT.
Referenced by IsRelevantAndUpdate().
◆ clear()
void CBloomFilter::clear | ( | ) |
Definition at line 125 of file bloom.cpp.
References isEmpty, isFull, and vData.
Referenced by CGovernanceManager::ProcessMessage(), CGovernanceManager::RequestGovernanceObject(), reset(), and CMasternodeSync::SendGovernanceSyncRequest().
◆ contains() [1/4]
bool CBloomFilter::contains | ( | const std::vector< unsigned char > & | vKey | ) | const |
Definition at line 89 of file bloom.cpp.
References Hash(), isEmpty, isFull, nHashFuncs, and vData.
Referenced by CheckScript(), CheckSpecialTransactionMatchesAndUpdate(), contains(), IsRelevantAndUpdate(), and CGovernanceManager::SyncSingleObjVotes().
◆ contains() [2/4]
bool CBloomFilter::contains | ( | const COutPoint & | outpoint | ) | const |
Definition at line 105 of file bloom.cpp.
References CDataStream::begin(), contains(), CDataStream::end(), PROTOCOL_VERSION, and SER_NETWORK.
◆ contains() [3/4]
bool CBloomFilter::contains | ( | const uint256 & | hash | ) | const |
Definition at line 113 of file bloom.cpp.
References base_blob< BITS >::begin(), contains(), and base_blob< BITS >::end().
◆ contains() [4/4]
bool CBloomFilter::contains | ( | const uint160 & | hash | ) | const |
Definition at line 119 of file bloom.cpp.
References base_blob< BITS >::begin(), contains(), and base_blob< BITS >::end().
◆ Hash()
|
inlineprivate |
Definition at line 56 of file bloom.cpp.
References MurmurHash3(), nTweak, and vData.
Referenced by contains(), and insert().
◆ insert() [1/3]
void CBloomFilter::insert | ( | const std::vector< unsigned char > & | vKey | ) |
Definition at line 62 of file bloom.cpp.
References Hash(), isEmpty, isFull, nHashFuncs, and vData.
Referenced by CheckSpecialTransactionMatchesAndUpdate(), insert(), IsRelevantAndUpdate(), and CGovernanceManager::RequestGovernanceObject().
◆ insert() [2/3]
void CBloomFilter::insert | ( | const COutPoint & | outpoint | ) |
Definition at line 75 of file bloom.cpp.
References CDataStream::begin(), CDataStream::end(), insert(), PROTOCOL_VERSION, and SER_NETWORK.
◆ insert() [3/3]
void CBloomFilter::insert | ( | const uint256 & | hash | ) |
Definition at line 83 of file bloom.cpp.
References base_blob< BITS >::begin(), base_blob< BITS >::end(), and insert().
◆ IsRelevantAndUpdate()
bool CBloomFilter::IsRelevantAndUpdate | ( | const CTransaction & | tx | ) |
Also adds any outputs which match the filter to the filter (to match their spending txes)
Definition at line 233 of file bloom.cpp.
References BLOOM_UPDATE_ALL, BLOOM_UPDATE_MASK, BLOOM_UPDATE_P2PUBKEY_ONLY, CheckScript(), CheckSpecialTransactionMatchesAndUpdate(), contains(), CTransaction::GetHash(), insert(), isEmpty, isFull, nFlags, CTxIn::prevout, CTxOut::scriptPubKey, CTxIn::scriptSig, Solver(), TX_MULTISIG, TX_PUBKEY, CTransaction::vin, and CTransaction::vout.
Referenced by CMerkleBlock::CMerkleBlock().
◆ IsWithinSizeConstraints()
bool CBloomFilter::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)
Definition at line 138 of file bloom.cpp.
References MAX_BLOOM_FILTER_SIZE, MAX_HASH_FUNCS, nHashFuncs, and vData.
◆ reset()
void CBloomFilter::reset | ( | const unsigned int | nNewTweak | ) |
◆ SerializationOp()
|
inline |
◆ UpdateEmptyFull()
void CBloomFilter::UpdateEmptyFull | ( | ) |
Checks for empty and full filters to avoid wasting cpu.
Definition at line 288 of file bloom.cpp.
References immer::detail::dvektor::empty, isEmpty, isFull, and vData.
Referenced by CGovernanceManager::ProcessMessage().
Friends And Related Function Documentation
◆ CRollingBloomFilter
|
friend |
Member Data Documentation
◆ ADD_SERIALIZE_METHODS
◆ isEmpty
|
private |
Definition at line 51 of file bloom.h.
Referenced by clear(), contains(), insert(), IsRelevantAndUpdate(), and UpdateEmptyFull().
◆ isFull
|
private |
Definition at line 50 of file bloom.h.
Referenced by clear(), contains(), insert(), IsRelevantAndUpdate(), and UpdateEmptyFull().
◆ nFlags
|
private |
Definition at line 54 of file bloom.h.
Referenced by CheckSpecialTransactionMatchesAndUpdate(), IsRelevantAndUpdate(), and SerializationOp().
◆ nHashFuncs
|
private |
Definition at line 52 of file bloom.h.
Referenced by contains(), insert(), IsWithinSizeConstraints(), and SerializationOp().
◆ nTweak
|
private |
Definition at line 53 of file bloom.h.
Referenced by Hash(), reset(), and SerializationOp().
◆ vData
|
private |
Definition at line 49 of file bloom.h.
Referenced by clear(), contains(), Hash(), insert(), IsWithinSizeConstraints(), SerializationOp(), and UpdateEmptyFull().
The documentation for this class was generated from the following files: