Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

bloom.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2015 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_BLOOM_H
6 #define BITCOIN_BLOOM_H
7 
8 #include <serialize.h>
9 
10 #include <vector>
11 
12 class COutPoint;
13 class CScript;
14 class CTransaction;
15 class uint256;
16 class uint160;
17 
19 static const unsigned int MAX_BLOOM_FILTER_SIZE = 36000; // bytes
20 static const unsigned int MAX_HASH_FUNCS = 50;
21 
27 {
30  // Only adds outpoints to the filter if the output is a pay-to-pubkey/pay-to-multisig script
33 };
34 
47 {
48 private:
49  std::vector<unsigned char> vData;
50  bool isFull;
51  bool isEmpty;
52  unsigned int nHashFuncs;
53  unsigned int nTweak;
54  unsigned char nFlags;
55 
56  unsigned int Hash(unsigned int nHashNum, const std::vector<unsigned char>& vDataToHash) const;
57 
58  // Private constructor for CRollingBloomFilter, no restrictions on size
59  CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak);
60  friend class CRollingBloomFilter;
61 
62  // Check matches for arbitrary script data elements
63  bool CheckScript(const CScript& script) const;
64  // Check additional matches for special transactions
66 public:
76  CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak, unsigned char nFlagsIn);
78 
80 
81  template <typename Stream, typename Operation>
82  inline void SerializationOp(Stream& s, Operation ser_action) {
87  }
88 
89  void insert(const std::vector<unsigned char>& vKey);
90  void insert(const COutPoint& outpoint);
91  void insert(const uint256& hash);
92 
93  bool contains(const std::vector<unsigned char>& vKey) const;
94  bool contains(const COutPoint& outpoint) const;
95  bool contains(const uint256& hash) const;
96  bool contains(const uint160& hash) const;
97 
98  void clear();
99  void reset(const unsigned int nNewTweak);
100 
103  bool IsWithinSizeConstraints() const;
104 
106  bool IsRelevantAndUpdate(const CTransaction& tx);
107 
109  void UpdateEmptyFull();
110 };
111 
127 {
128 public:
129  // A random bloom filter calls GetRand() at creation time.
130  // Don't create global CRollingBloomFilter objects, as they may be
131  // constructed before the randomizer is properly initialized.
132  CRollingBloomFilter(const unsigned int nElements, const double nFPRate);
133 
134  void insert(const std::vector<unsigned char>& vKey);
135  void insert(const uint256& hash);
136  bool contains(const std::vector<unsigned char>& vKey) const;
137  bool contains(const uint256& hash) const;
138 
139  void reset();
140 
141 private:
145  std::vector<uint64_t> data;
146  unsigned int nTweak;
148 };
149 
150 #endif // BITCOIN_BLOOM_H
CRollingBloomFilter(const unsigned int nElements, const double nFPRate)
Definition: bloom.cpp:301
bloomflags
First two bits of nFlags control how much IsRelevantAndUpdate actually updates The remaining bits are...
Definition: bloom.h:26
#define READWRITE(obj)
Definition: serialize.h:165
ADD_SERIALIZE_METHODS
Definition: bloom.h:79
unsigned int nTweak
Definition: bloom.h:53
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:341
unsigned char nFlags
Definition: bloom.h:54
bool IsRelevantAndUpdate(const CTransaction &tx)
Also adds any outputs which match the filter to the filter (to match their spending txes) ...
Definition: bloom.cpp:233
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:46
bool CheckScript(const CScript &script) const
Definition: bloom.cpp:144
unsigned int nTweak
Definition: bloom.h:146
bool isFull
Definition: bloom.h:50
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:126
static const unsigned int MAX_BLOOM_FILTER_SIZE
20,000 items with fp rate < 0.1% or 10,000 items and <0.0001%
Definition: bloom.h:19
std::vector< unsigned char > vData
Definition: bloom.h:49
false true true true
Definition: bls_dkg.cpp:176
unsigned int Hash(unsigned int nHashNum, const std::vector< unsigned char > &vDataToHash) const
Definition: bloom.cpp:56
unsigned int nHashFuncs
Definition: bloom.h:52
void reset(const unsigned int nNewTweak)
Definition: bloom.cpp:132
void insert(const std::vector< unsigned char > &vKey)
Definition: bloom.cpp:62
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:378
false
Definition: bls_dkg.cpp:168
void clear()
Definition: bloom.cpp:125
CBloomFilter()
Definition: bloom.h:77
static const unsigned int MAX_HASH_FUNCS
Definition: bloom.h:20
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
std::vector< uint64_t > data
Definition: bloom.h:145
bool CheckSpecialTransactionMatchesAndUpdate(const CTransaction &tx)
Definition: bloom.cpp:167
256-bit opaque blob.
Definition: uint256.h:123
int nEntriesThisGeneration
Definition: bloom.h:143
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
160-bit opaque blob.
Definition: uint256.h:112
void UpdateEmptyFull()
Checks for empty and full filters to avoid wasting cpu.
Definition: bloom.cpp:288
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
void SerializationOp(Stream &s, Operation ser_action)
Definition: bloom.h:82
bool isEmpty
Definition: bloom.h:51
bool IsWithinSizeConstraints() const
True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS (c...
Definition: bloom.cpp:138
bool contains(const std::vector< unsigned char > &vKey) const
Definition: bloom.cpp:89
int nEntriesPerGeneration
Definition: bloom.h:142
Released under the MIT license