 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_BLOCKFILTER_H
6 #define BITCOIN_BLOCKFILTER_H
11 #include <unordered_set>
27 typedef std::vector<unsigned char>
Element;
28 typedef std::unordered_set<Element, ByteVectorHash>
ElementSet;
37 Params(uint64_t siphash_k0 = 0, uint64_t siphash_k1 = 0, uint8_t P = 0, uint32_t
M = 1)
54 bool MatchInternal(
const uint64_t* sorted_element_hashes,
size_t size)
const;
62 GCSFilter(
const Params& params, std::vector<unsigned char> encoded_filter);
125 std::vector<unsigned char> filter);
145 template <
typename Stream>
152 template <
typename Stream>
154 std::vector<unsigned char> encoded_filter;
165 throw std::ios_base::failure(
"unknown filter_type");
171 #endif // BITCOIN_BLOCKFILTER_H
bool BuildParams(GCSFilter::Params ¶ms) const
uint64_t m_F
Range of element hashes, F = N * M.
BlockFilterType GetFilterType() const
const uint256 & GetBlockHash() const
bool Match(const Element &element) const
Checks if the element may be in the set.
constexpr uint32_t BASIC_FILTER_M
const std::vector< unsigned char > & GetEncodedFilter() const
Params(uint64_t siphash_k0=0, uint64_t siphash_k1=0, uint8_t P=0, uint32_t M=1)
const std::string & ListBlockFilterTypes()
Get a comma-separated list of known filter type names.
uint256 ComputeHeader(const uint256 &prev_header) const
Compute the filter header given the previous one.
const Params & GetParams() const
const GCSFilter & GetFilter() const
GCSFilter(const Params ¶ms=Params())
Constructs an empty filter.
uint32_t m_M
Inverse false positive rate.
This implements a Golomb-coded set as defined in BIP 158.
uint8_t m_P
Golomb-Rice coding parameter.
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
bool MatchInternal(const uint64_t *sorted_element_hashes, size_t size) const
Helper method used to implement Match and MatchAny.
std::vector< unsigned char > m_encoded
void Unserialize(Stream &s)
bool MatchAny(const ElementSet &elements) const
Checks if any of the given elements may be in the set.
void Serialize(Stream &s) const
const std::string & BlockFilterTypeName(BlockFilterType filter_type)
Get the human-readable name for a filter type.
uint32_t m_N
Number of elements in the filter.
uint256 GetHash() const
Compute the filter hash.
uint64_t HashToRange(const Element &element) const
Hash a data element to an integer in the range [0, N * M).
BlockFilterType m_filter_type
std::unordered_set< Element, ByteVectorHash > ElementSet
const CChainParams & Params()
Return the currently selected parameters.
std::vector< uint64_t > BuildHashedSet(const ElementSet &elements) const
constexpr uint8_t BASIC_FILTER_P
const std::set< BlockFilterType > & AllBlockFilterTypes()
Get a list of known filter types.
const std::vector< unsigned char > & GetEncoded() const
std::vector< unsigned char > Element
Undo information for a CBlock.
Complete block filter struct as defined in BIP 157.