47 :
m_params(params), m_N(0), m_F(0), m_encoded{0} {}
56 throw std::ios_base::failure(
"N must be <2^32");
67 if (!stream.empty()) {
68 throw std::ios_base::failure(
"encoded_filter contains excess data");
77 throw std::invalid_argument(
"N must be <2^32");
152 if (entry.second ==
name) {
161 static std::set<BlockFilterType>
types;
163 static std::once_flag flag;
164 std::call_once(flag, []() {
166 types.insert(entry.first);
176 static std::once_flag flag;
177 std::call_once(flag, []() {
178 std::stringstream
ret;
198 for (
const CTxOut &txout : tx->vout) {
199 const CScript &script = txout.scriptPubKey;
209 const CScript &script = prevout.GetTxOut().scriptPubKey;
210 if (script.
empty()) {
222 std::vector<uint8_t> filter)
223 : m_filter_type(
filter_type), m_block_hash(block_hash) {
226 throw std::invalid_argument(
"unknown filter_type");
233 : m_filter_type(
filter_type), m_block_hash(block.GetHash()) {
236 throw std::invalid_argument(
"unknown filter_type");
static const std::map< BlockFilterType, std::string > g_filter_types
static constexpr int GCS_SER_VERSION
Protocol version used to serialize parameters in GCS filter encoding.
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.
static constexpr int GCS_SER_TYPE
SerType used to serialize parameters in GCS filter encoding.
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
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.
const std::vector< uint8_t > & GetEncodedFilter() const
std::vector< CTransactionRef > vtx
Undo information for a CBlock.
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
CHash256 & Write(Span< const uint8_t > input)
void Finalize(Span< uint8_t > output)
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.
An output of a transaction.
Restore the UTXO in a Coin at a given COutPoint.
Minimal stream for overwriting and/or appending to an existing byte vector.
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
Minimal stream for reading from an existing byte array by Span.
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.
static uint64_t GolombRiceDecode(BitStreamReader< IStream > &bitreader, uint8_t P)
static void GolombRiceEncode(BitStreamWriter< OStream > &bitwriter, uint8_t P, uint64_t x)
static unsigned char elements[DATACOUNT][DATALEN]
Implement std::hash so RCUPtr can be used as a key for maps or sets.
const CChainParams & m_params
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
A BlockHash is a unqiue identifier for a block.
uint32_t m_M
Inverse false positive rate.
uint8_t m_P
Golomb-Rice coding parameter.