18 #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455 19 #define LN2 0.6931471805599453094172321214581765680755001343602552 27 vData(
std::
min((unsigned int)(-1 /
LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8),
35 nHashFuncs(
std::
min((unsigned int)(vData.
size() * 8 / nElements *
LN2), MAX_HASH_FUNCS)),
52 inline unsigned int CBloomFilter::Hash(
unsigned int nHashNum,
const std::vector<unsigned char>& vDataToHash)
const 64 unsigned int nIndex =
Hash(i, vKey);
66 vData[nIndex >> 3] |= (1 << (7 & nIndex));
75 std::vector<unsigned char>
data(stream.
begin(), stream.
end());
81 std::vector<unsigned char>
data(hash.
begin(), hash.
end());
93 unsigned int nIndex =
Hash(i, vKey);
95 if (!(
vData[nIndex >> 3] & (1 << (7 & nIndex))))
105 std::vector<unsigned char>
data(stream.
begin(), stream.
end());
111 std::vector<unsigned char>
data(hash.
begin(), hash.
end());
130 return vData.size() <= MAX_BLOOM_FILTER_SIZE &&
nHashFuncs <= MAX_HASH_FUNCS;
146 for (
unsigned int i = 0; i < tx.
vout.size(); i++)
154 std::vector<unsigned char>
data;
160 if (data.size() != 0 &&
contains(data))
168 std::vector<std::vector<unsigned char> > vSolutions;
189 std::vector<unsigned char>
data;
195 if (data.size() != 0 &&
contains(data))
207 for (
unsigned int i = 0; i <
vData.size(); i++)
209 full &=
vData[i] == 0xff;
210 empty &=
vData[i] == 0;
218 double logFpRate = log(fpRate);
223 nEntriesPerGeneration = (nElements + 1) / 2;
224 uint32_t nMaxElements = nEntriesPerGeneration * 3;
232 uint32_t nFilterBits = (uint32_t)ceil(-1.0 *
nHashFuncs * nMaxElements / log(1.0 - exp(logFpRate /
nHashFuncs)));
239 data.resize(((nFilterBits + 63) / 64) << 1);
244 static inline uint32_t RollingBloomHash(
unsigned int nHashNum, uint32_t
nTweak,
const std::vector<unsigned char>& vDataToHash) {
250 if (nEntriesThisGeneration == nEntriesPerGeneration) {
251 nEntriesThisGeneration = 0;
253 if (nGeneration == 4) {
256 uint64_t nGenerationMask1 = 0 - (uint64_t)(nGeneration & 1);
257 uint64_t nGenerationMask2 = 0 - (uint64_t)(nGeneration >> 1);
259 for (uint32_t p = 0; p <
data.size(); p += 2) {
260 uint64_t p1 =
data[p], p2 =
data[p + 1];
261 uint64_t mask = (p1 ^ nGenerationMask1) | (p2 ^ nGenerationMask2);
263 data[p + 1] = p2 & mask;
266 nEntriesThisGeneration++;
269 uint32_t
h = RollingBloomHash(n,
nTweak, vKey);
271 uint32_t pos = (h >> 6) %
data.size();
273 data[pos & ~1] = (
data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit;
274 data[pos | 1] = (
data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit;
287 uint32_t
h = RollingBloomHash(n,
nTweak, vKey);
289 uint32_t pos = (h >> 6) %
data.size();
291 if (!(((
data[pos & ~1] |
data[pos | 1]) >> bit) & 1)) {
307 nEntriesThisGeneration = 0;
309 for (std::vector<uint64_t>::iterator it =
data.begin(); it !=
data.end(); it++) {
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet, bool contractConsensus)
Return public keys or hashes from scriptPubKey, for 'standard' transaction types. ...
bool contains(const std::vector< unsigned char > &vKey) const
CRollingBloomFilter(const unsigned int nElements, const double nFPRate)
const_iterator begin() const
void insert(const std::vector< unsigned char > &vKey)
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes) ...
unsigned int Hash(unsigned int nHashNum, const std::vector< unsigned char > &vDataToHash) const
std::hash for asio::adress
std::vector< unsigned char > vData
void reset(const unsigned int nNewTweak)
Double ended buffer combining vector and stream-like interfaces.
void insert(const std::vector< unsigned char > &vKey)
const std::vector< CTxIn > vin
bool IsWithinSizeConstraints() const
True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS (c...
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector< unsigned char > &vDataToHash)
opcodetype
Script opcodes.
An input of a transaction.
bool contains(const std::vector< unsigned char > &vKey) const
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.
PlatformStyle::TableColorType type
uint8_t const size_t const size
#define round(a, b, c, x, mul)
void UpdateEmptyFull()
Checks for empty and full filters to avoid wasting cpu.
const uint256 & GetHash() const
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
The basic transaction that is broadcasted on the network and contained in blocks. ...
uint64_t GetRand(uint64_t nMax)
const_iterator end() const