5#ifndef BITCOIN_INDEX_BLOCKFILTERINDEX_H
6#define BITCOIN_INDEX_BLOCKFILTERINDEX_H
21#include <unordered_map>
44 std::unique_ptr<BaseIndex::DB>
m_db;
66 bool CustomInit(
const std::optional<interfaces::BlockRef>& block)
override;
79 size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
93 std::vector<BlockFilter>& filters_out)
const;
97 std::vector<uint256>& hashes_out)
const;
114 size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
bool DestroyBlockFilterIndex(BlockFilterType filter_type)
Destroy the block filter index with the given type.
bool InitBlockFilterIndex(std::function< std::unique_ptr< interfaces::Chain >()> make_chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Initialize a block filter index for the given type if one does not already exist.
void DestroyAllBlockFilterIndexes()
Destroy all open block filter indexes.
static const char *const DEFAULT_BLOCKFILTERINDEX
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
static constexpr int CFCHECKPT_INTERVAL
Interval between compact filter checkpoints.
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
The database stores a block locator of the chain the database is synced to so that the index can effi...
BaseIndex(std::unique_ptr< interfaces::Chain > chain, std::string name)
Complete block filter struct as defined in BIP 157.
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
std::unique_ptr< BaseIndex::DB > m_db
bool CustomInit(const std::optional< interfaces::BlockRef > &block) override
Initialize internal state from the database and block index.
BaseIndex::DB & GetDB() const LIFETIMEBOUND override
std::unordered_map< uint256, uint256, BlockHasher > m_headers_cache GUARDED_BY(m_cs_headers_cache)
cache of block hash to filter header, to avoid disk access when responding to getcfcheckpt.
bool LookupFilterRange(int start_height, const CBlockIndex *stop_index, std::vector< BlockFilter > &filters_out) const
Get a range of filters between two heights on a chain.
BlockFilterType GetFilterType() const
bool CustomRemove(const interfaces::BlockInfo &block) override
Rewind index by one block during a chain reorg.
bool CustomCommit(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
BlockFilterType m_filter_type
BlockFilterIndex(std::unique_ptr< interfaces::Chain > chain, BlockFilterType filter_type, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
interfaces::Chain::NotifyOptions CustomOptions() override
Return custom notification options for index.
std::unique_ptr< FlatFileSeq > m_filter_fileseq
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
bool ReadFilterFromDisk(const FlatFilePos &pos, const uint256 &hash, BlockFilter &filter) const
bool LookupFilterHashRange(int start_height, const CBlockIndex *stop_index, std::vector< uint256 > &hashes_out) const
Get a range of filter hashes between two heights on a chain.
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
bool AllowPrune() const override
size_t WriteFilterToDisk(FlatFilePos &pos, const BlockFilter &filter)
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache)
Get a single filter header by block.
std::optional< uint256 > ReadFilterHeader(int height, const uint256 &expected_block_hash)
bool Write(const BlockFilter &filter, uint32_t block_height, const uint256 &filter_header)
FlatFilePos m_next_filter_pos
The block chain is a tree shaped structure starting with the genesis block at the root,...
Batch of changes queued to be written to a CDBWrapper.
Block data sent with blockConnected, blockDisconnected notifications.
Options specifying which chain notifications are required.
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
#define EXCLUSIVE_LOCKS_REQUIRED(...)