22static constexpr double LN2SQUARED = 0.4804530139182014246671025263266649717305529515945455;
23static 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;
126 std::vector<std::vector<unsigned char> > vSolutions;
148 std::vector<unsigned char>
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)) {
245 std::fill(
data.begin(),
data.end(), 0);
static constexpr double LN2SQUARED
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)
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 std::vector< CTxOut > vout
const Txid & GetHash() const LIFETIMEBOUND
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
Double ended buffer combining vector and stream-like interfaces.
I rand() noexcept
Generate a random integer in its entire (non-negative) range.
const uint256 & ToUint256() const LIFETIMEBOUND
static uint32_t FastRange32(uint32_t x, uint32_t n)
Fast range reduction with 32-bit input and 32-bit range.
unsigned int MurmurHash3(unsigned int nHashSeed, Span< const unsigned char > vDataToHash)
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.
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) unsigned char member types only.