20#define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
21#define LN2 0.6931471805599453094172321214581765680755001343602552
37 const uint32_t nTweakIn, uint8_t nFlagsIn)
38 : vData(
std::min<uint32_t>(-1 /
LN2SQUARED * nElements * log(nFPRate),
41 nHashFuncs(
std::min<uint32_t>(vData.size() * 8 / nElements *
LN2,
43 nTweak(nTweakIn), nFlags(nFlagsIn) {}
60 uint32_t nIndex =
Hash(i, vKey);
62 vData[nIndex >> 3] |= (1 << (7 & nIndex));
78 uint32_t nIndex =
Hash(i, vKey);
80 if (!(
vData[nIndex >> 3] & (1 << (7 & nIndex)))) {
112 for (
size_t i = 0; i < tx.
vout.size(); i++) {
121 std::vector<uint8_t> data;
127 if (data.size() != 0 &&
contains(data)) {
133 std::vector<std::vector<uint8_t>> vSolutions;
158 std::vector<uint8_t> data;
164 if (data.size() != 0 &&
contains(data)) {
174 const double fpRate) {
175 double logFpRate = log(fpRate);
178 nHashFuncs = std::max(1, std::min<int>(round(logFpRate / log(0.5)), 50));
196 uint32_t nFilterBits =
197 uint32_t(ceil(-1.0 *
nHashFuncs * nMaxElements /
205 data.resize(((nFilterBits + 63) / 64) << 1);
212 return MurmurHash3(nHashNum * 0xFBA4C795 + nTweak, vDataToHash);
222 uint64_t nGenerationMask1 = 0 - uint64_t(
nGeneration & 1);
223 uint64_t nGenerationMask2 = 0 - uint64_t(
nGeneration >> 1);
225 for (uint32_t p = 0; p <
data.size(); p += 2) {
226 uint64_t p1 =
data[p], p2 =
data[p + 1];
227 uint64_t mask = (p1 ^ nGenerationMask1) | (p2 ^ nGenerationMask2);
229 data[p + 1] = p2 & mask;
242 data[pos & ~1U] = (
data[pos & ~1U] & ~(uint64_t(1) << bit)) |
244 data[pos | 1U] = (
data[pos | 1] & ~(uint64_t(1) << bit)) |
256 if (!(((
data[pos & ~1] |
data[pos | 1]) >> bit) & 1)) {
264 nTweak = GetRand<unsigned int>();
267 std::fill(
data.begin(),
data.end(), 0);
static uint32_t RollingBloomHash(uint32_t nHashNum, uint32_t nTweak, Span< const uint8_t > vDataToHash)
static const uint32_t MAX_BLOOM_FILTER_SIZE
20,000 items with fp rate < 0.1% or 10,000 items and <0.0001%
static const uint32_t 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...
bool contains(Span< const uint8_t > vKey) const
void insert(Span< const uint8_t > vKey)
std::vector< uint8_t > vData
bool MatchInputs(const CTransaction &tx)
Scan inputs to see if the spent outpoints are a match, or the input scripts contain matching elements...
bool MatchAndInsertOutputs(const CTransaction &tx)
Scans output scripts for matches and adds those outpoints to the filter for spend detection.
uint32_t Hash(uint32_t nHashNum, Span< const uint8_t > vDataToHash) const
Double ended buffer combining vector and stream-like interfaces.
An outpoint - a combination of a transaction hash and an index n into its vout.
CRollingBloomFilter(const uint32_t nElements, const double nFPRate)
int nEntriesPerGeneration
int nEntriesThisGeneration
std::vector< uint64_t > data
void insert(Span< const uint8_t > vKey)
bool contains(Span< const uint8_t > vKey) const
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< uint8_t > &vchRet) const
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
static uint32_t FastRange32(uint32_t x, uint32_t n)
This file offers implementations of the fast range reduction technique described in https://lemire....
uint32_t MurmurHash3(uint32_t nHashSeed, Span< const uint8_t > vDataToHash)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
opcodetype
Script opcodes.
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) uint8_t member types only.
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
A TxId is the identifier of a transaction.
static const int PROTOCOL_VERSION
network protocol versioning