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