46 : m_params(params), m_N(0), m_F(0), m_encoded{0}
57 throw std::ios_base::failure(
"N must be <2^32");
70 throw std::ios_base::failure(
"encoded_filter contains excess data");
80 throw std::invalid_argument(
"N must be <2^32");
158 if (entry.second ==
name) {
168 static std::set<BlockFilterType> types;
170 static std::once_flag flag;
171 std::call_once(flag, []() {
173 types.insert(entry.first);
193 for (
const CTxOut& txout : tx->vout) {
203 if (
script.empty())
continue;
213 : m_filter_type(
filter_type), m_block_hash(block_hash)
217 throw std::invalid_argument(
"unknown filter_type");
223 : m_filter_type(
filter_type), m_block_hash(block.GetHash())
227 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.
bool BlockFilterTypeByName(std::string_view name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
const std::string & ListBlockFilterTypes()
Get a comma-separated list of known filter type names.
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.
Serialized script, used inside transaction inputs and outputs.
General SipHash-2-4 implementation.
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.
An output of a transaction.
Undo information for a CTransaction.
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 std::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.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.