35 std::vector<uint64_t> hashed_elements;
36 hashed_elements.reserve(elements.size());
37 for (
const Element& element : elements) {
40 std::sort(hashed_elements.begin(), hashed_elements.end());
41 return hashed_elements;
45 : m_params(params), m_N(0), m_F(0), m_encoded{0}
49 : m_params(params), m_encoded(
std::move(encoded_filter))
54 m_N =
static_cast<uint32_t
>(N);
56 throw std::ios_base::failure(
"N must be <2^32");
60 if (skip_decode_check)
return;
65 for (uint64_t i = 0; i <
m_N; ++i) {
68 if (!stream.empty()) {
69 throw std::ios_base::failure(
"encoded_filter contains excess data");
76 size_t N = elements.size();
77 m_N =
static_cast<uint32_t
>(N);
79 throw std::invalid_argument(
"N must be <2^32");
87 if (elements.empty()) {
93 uint64_t last_value = 0;
95 uint64_t delta = value - last_value;
114 size_t hashes_index = 0;
115 for (uint32_t i = 0; i <
m_N; ++i) {
120 if (hashes_index == size) {
122 }
else if (element_hashes[hashes_index] == value) {
124 }
else if (element_hashes[hashes_index] > value) {
149 static std::string unknown_retval;
156 if (entry.second ==
name) {
157 filter_type = entry.first;
166 static std::set<BlockFilterType> types;
168 static std::once_flag flag;
169 std::call_once(flag, []() {
171 types.insert(entry.first);
180 static std::string type_list{
Join(
g_filter_types,
", ", [](
const auto& entry) {
return entry.second; })};
191 for (
const CTxOut& txout : tx->vout) {
201 if (
script.empty())
continue;
210 std::vector<unsigned char> filter,
bool skip_decode_check)
211 : m_filter_type(filter_type), m_block_hash(block_hash)
215 throw std::invalid_argument(
"unknown filter_type");
221 : m_filter_type(filter_type), m_block_hash(block.GetHash())
225 throw std::invalid_argument(
"unknown filter_type");
static const std::map< BlockFilterType, std::string > g_filter_types
static GCSFilter::ElementSet BasicFilterElements(const CBlock &block, const CBlockUndo &block_undo)
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.
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
constexpr uint8_t BASIC_FILTER_P
constexpr uint32_t BASIC_FILTER_M
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.
BlockFilterType m_filter_type
uint256 GetHash() const
Compute the filter hash.
std::vector< CTransactionRef > vtx
Undo information for a CBlock.
std::vector< CTxUndo > vtxundo
Serialized script, used inside transaction inputs and outputs.
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
An output of a transaction.
Undo information for a CTransaction.
std::vector< Coin > vprevout
CTxOut out
unspent transaction output
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.
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< unsigned char > m_encoded
Minimal stream for reading from an existing byte array by Span.
constexpr uint64_t GetUint64(int pos) const
static uint64_t FastRange64(uint64_t x, uint64_t n)
Fast range reduction with 64-bit input and 64-bit range.
uint64_t GolombRiceDecode(BitStreamReader< IStream > &bitreader, uint8_t P)
void GolombRiceEncode(BitStreamWriter< OStream > &bitwriter, uint8_t P, uint64_t x)
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
std::shared_ptr< const CTransaction > CTransactionRef
void WriteCompactSize(SizeComputer &os, uint64_t nSize)
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
uint32_t m_M
Inverse false positive rate.
uint8_t m_P
Golomb-Rice coding parameter.