22 static constexpr
double LN2SQUARED = 0.4804530139182014246671025263266649717305529515945455;
23 static constexpr
double LN2 = 0.6931471805599453094172321214581765680755001343602552;
55 unsigned int nIndex =
Hash(i, vKey);
57 vData[nIndex >> 3] |= (1 << (7 & nIndex));
74 unsigned int nIndex =
Hash(i, vKey);
76 if (!(
vData[nIndex >> 3] & (1 << (7 & nIndex))))
105 for (
unsigned int i = 0; i < tx.
vout.size(); i++)
113 std::vector<unsigned char> data;
119 if (data.size() != 0 &&
contains(data))
126 std::vector<std::vector<unsigned char> > vSolutions;
148 std::vector<unsigned char> data;
154 if (data.size() != 0 &&
contains(data))
164 double logFpRate = log(fpRate);
167 nHashFuncs = std::max(1, std::min((
int)round(logFpRate / log(0.5)), 50));
178 uint32_t nFilterBits = (uint32_t)ceil(-1.0 *
nHashFuncs * nMaxElements / log(1.0 - exp(logFpRate /
nHashFuncs)));
185 data.resize(((nFilterBits + 63) / 64) << 1);
192 return MurmurHash3(nHashNum * 0xFBA4C795 + nTweak, vDataToHash);
203 uint64_t nGenerationMask1 = 0 - (uint64_t)(
nGeneration & 1);
204 uint64_t nGenerationMask2 = 0 - (uint64_t)(
nGeneration >> 1);
206 for (uint32_t p = 0; p <
data.size(); p += 2) {
207 uint64_t p1 =
data[p], p2 =
data[p + 1];
208 uint64_t mask = (p1 ^ nGenerationMask1) | (p2 ^ nGenerationMask2);
210 data[p + 1] = p2 & mask;
221 data[pos & ~1U] = (
data[pos & ~1U] & ~(uint64_t{1} << bit)) | (uint64_t(
nGeneration & 1)) << bit;
222 data[pos | 1] = (
data[pos | 1] & ~(uint64_t{1} << bit)) | (uint64_t(
nGeneration >> 1)) << bit;
233 if (!(((
data[pos & ~1U] |
data[pos | 1]) >> bit) & 1)) {
242 nTweak = GetRand<unsigned int>();
245 std::fill(
data.begin(),
data.end(), 0);
bool contains(Span< const unsigned char > vKey) const
static constexpr double LN2SQUARED
static uint32_t RollingBloomHash(unsigned int nHashNum, uint32_t nTweak, Span< const unsigned char > vDataToHash)
void insert(Span< const unsigned char > vKey)
CRollingBloomFilter(const unsigned int nElements, const double nFPRate)
bool contains(Span< const unsigned char > vKey) const
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes) ...
static constexpr unsigned int MAX_HASH_FUNCS
std::vector< unsigned char > vData
static uint32_t FastRange32(uint32_t x, uint32_t n)
Fast range reduction with 32-bit input and 32-bit range.
const std::vector< CTxIn > vin
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 double LN2
unsigned int MurmurHash3(unsigned int nHashSeed, Span< const unsigned char > vDataToHash)
unsigned int Hash(unsigned int nHashNum, Span< const unsigned char > vDataToHash) const
An input of a transaction.
Double ended buffer combining vector and stream-like interfaces.
const uint256 & GetHash() const
opcodetype
Script opcodes.
const std::vector< CTxOut > vout
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< uint64_t > data
void insert(Span< const unsigned char > vKey)
int nEntriesThisGeneration
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span
Like the Span constructor, but for (const) unsigned char member types only.
The basic transaction that is broadcasted on the network and contained in blocks. ...
bool IsWithinSizeConstraints() const
True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS (c...
int nEntriesPerGeneration