5#ifndef BITCOIN_BLOCKFILTER_H
6#define BITCOIN_BLOCKFILTER_H
13#include <unordered_set>
31 typedef std::vector<unsigned char>
Element;
32 typedef std::unordered_set<Element, ByteVectorHash>
ElementSet;
41 Params(uint64_t siphash_k0 = 0, uint64_t siphash_k1 = 0, uint8_t P = 0, uint32_t
M = 1)
58 bool MatchInternal(
const uint64_t* sorted_element_hashes,
size_t size)
const;
66 GCSFilter(
const Params& params, std::vector<unsigned char> encoded_filter,
bool skip_decode_check);
129 std::vector<unsigned char> filter,
bool skip_decode_check);
149 template <
typename Stream>
156 template <
typename Stream>
158 std::vector<unsigned char> encoded_filter;
169 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.
const uint256 & GetBlockHash() const LIFETIMEBOUND
void Serialize(Stream &s) const
const std::vector< unsigned char > & GetEncodedFilter() const LIFETIMEBOUND
bool BuildParams(GCSFilter::Params ¶ms) const
uint256 ComputeHeader(const uint256 &prev_header) const
Compute the filter header given the previous one.
const GCSFilter & GetFilter() const LIFETIMEBOUND
BlockFilterType GetFilterType() const
BlockFilterType m_filter_type
uint256 GetHash() const
Compute the filter hash.
void Unserialize(Stream &s)
Undo information for a CBlock.
This implements a Golomb-coded set as defined in BIP 158.
std::vector< unsigned char > Element
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).
uint32_t m_N
Number of elements in the filter.
const Params & GetParams() const LIFETIMEBOUND
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
const std::vector< unsigned char > & GetEncoded() const LIFETIMEBOUND
std::vector< unsigned char > m_encoded
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.