21static constexpr double LN2SQUARED = 0.4804530139182014246671025263266649717305529515945455;
22static constexpr double LN2 = 0.6931471805599453094172321214581765680755001343602552;
36 nHashFuncs(std::min((unsigned int)(vData.size() * 8 / nElements *
LN2),
MAX_HASH_FUNCS)),
54 unsigned int nIndex =
Hash(i, vKey);
56 vData[nIndex >> 3] |= (1 << (7 & nIndex));
73 unsigned int nIndex =
Hash(i, vKey);
75 if (!(
vData[nIndex >> 3] & (1 << (7 & nIndex))))
104 for (
unsigned int i = 0; i < tx.
vout.size(); i++)
112 std::vector<unsigned char> data;
118 if (data.size() != 0 &&
contains(data))
125 std::vector<std::vector<unsigned char> > vSolutions;
147 std::vector<unsigned char> data;
153 if (data.size() != 0 &&
contains(data))
163 double logFpRate = log(fpRate);
166 nHashFuncs = std::max(1, std::min((
int)round(logFpRate / log(0.5)), 50));
177 uint32_t nFilterBits = (uint32_t)ceil(-1.0 *
nHashFuncs * nMaxElements / log(1.0 - exp(logFpRate /
nHashFuncs)));
184 data.resize(((nFilterBits + 63) / 64) << 1);
191 return MurmurHash3(nHashNum * 0xFBA4C795 + nTweak, vDataToHash);
198static inline uint32_t
FastMod(uint32_t x,
size_t n) {
199 return ((uint64_t)x * (uint64_t)n) >> 32;
210 uint64_t nGenerationMask1 = 0 - (uint64_t)(
nGeneration & 1);
211 uint64_t nGenerationMask2 = 0 - (uint64_t)(
nGeneration >> 1);
213 for (uint32_t p = 0; p <
data.size(); p += 2) {
214 uint64_t p1 =
data[p], p2 =
data[p + 1];
215 uint64_t mask = (p1 ^ nGenerationMask1) | (p2 ^ nGenerationMask2);
217 data[p + 1] = p2 & mask;
228 data[pos & ~1] = (
data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(
nGeneration & 1)) << bit;
229 data[pos | 1] = (
data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(
nGeneration >> 1)) << bit;
240 if (!(((
data[pos & ~1] |
data[pos | 1]) >> bit) & 1)) {
252 std::fill(
data.begin(),
data.end(), 0);
static constexpr double LN2SQUARED
static uint32_t FastMod(uint32_t x, size_t n)
static constexpr double LN2
static uint32_t RollingBloomHash(unsigned int nHashNum, uint32_t nTweak, Span< const unsigned char > vDataToHash)
static constexpr unsigned int MAX_BLOOM_FILTER_SIZE
20,000 items with fp rate < 0.1% or 10,000 items and <0.0001%
static constexpr unsigned int MAX_HASH_FUNCS
@ BLOOM_UPDATE_P2PUBKEY_ONLY
bool IsWithinSizeConstraints() const
True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS (c...
void insert(Span< const unsigned char > vKey)
bool contains(Span< const unsigned char > vKey) const
std::vector< unsigned char > vData
unsigned int Hash(unsigned int nHashNum, Span< const unsigned char > vDataToHash) const
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes)
Double ended buffer combining vector and stream-like interfaces.
An outpoint - a combination of a transaction hash and an index n into its vout.
bool contains(Span< const unsigned char > vKey) const
CRollingBloomFilter(const unsigned int nElements, const double nFPRate)
void insert(Span< const unsigned char > vKey)
int nEntriesPerGeneration
int nEntriesThisGeneration
std::vector< uint64_t > data
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
The basic transaction that is broadcasted on the network and contained in blocks.
const uint256 & GetHash() const
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
A Span is an object that can refer to a contiguous sequence of objects.
unsigned int MurmurHash3(unsigned int nHashSeed, Span< const unsigned char > vDataToHash)
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
opcodetype
Script opcodes.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
static const int PROTOCOL_VERSION
network protocol versioning