LCOV - code coverage report
Current view: top level - src/index - blockfilterindex.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 230 279 82.4 %
Date: 2026-06-25 07:23:43 Functions: 38 38 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2018-2021 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <map>
       6             : 
       7             : #include <dbwrapper.h>
       8             : #include <hash.h>
       9             : #include <index/blockfilterindex.h>
      10             : #include <node/blockstorage.h>
      11             : #include <serialize.h>
      12             : #include <util/system.h>
      13             : 
      14             : using node::UndoReadFromDisk;
      15             : 
      16             : /* The index database stores three items for each block: the disk location of the encoded filter,
      17             :  * its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
      18             :  * height, and those belonging to blocks that have been reorganized out of the active chain are
      19             :  * indexed by block hash. This ensures that filter data for any block that becomes part of the
      20             :  * active chain can always be retrieved, alleviating timing concerns.
      21             :  *
      22             :  * The filters themselves are stored in flat files and referenced by the LevelDB entries. This
      23             :  * minimizes the amount of data written to LevelDB and keeps the database values constant size. The
      24             :  * disk location of the next block filter to be written (represented as a FlatFilePos) is stored
      25             :  * under the DB_FILTER_POS key.
      26             :  *
      27             :  * Keys for the height index have the type [DB_BLOCK_HEIGHT, uint32 (BE)]. The height is represented
      28             :  * as big-endian so that sequential reads of filters by height are fast.
      29             :  * Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
      30             :  */
      31             : constexpr uint8_t DB_BLOCK_HASH{'s'};
      32             : constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
      33             : constexpr uint8_t DB_FILTER_POS{'P'};
      34             : constexpr uint8_t DB_VERSION{'V'};
      35             : 
      36             : constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB
      37             : /** The pre-allocation chunk size for fltr?????.dat files */
      38             : constexpr unsigned int FLTR_FILE_CHUNK_SIZE = 0x100000; // 1 MiB
      39             : /** Maximum size of the cfheaders cache
      40             :  *  We have a limit to prevent a bug in filling this cache
      41             :  *  potentially turning into an OOM. At 2000 entries, this cache
      42             :  *  is big enough for a 2,000,000 length block chain, which
      43             :  *  we should be enough until ~2047. */
      44             : constexpr size_t CF_HEADERS_CACHE_MAX_SZ{2000};
      45             : 
      46             : namespace {
      47             : 
      48             : struct DBVal {
      49             :     uint256 hash;
      50             :     uint256 header;
      51             :     FlatFilePos pos;
      52             : 
      53      930246 :     SERIALIZE_METHODS(DBVal, obj)
      54             :     {
      55      310082 :         READWRITE(obj.hash);
      56      310082 :         READWRITE(obj.header);
      57      310082 :         READWRITE(obj.pos);
      58      310082 :     }
      59             : };
      60             : 
      61             : struct DBHeightKey {
      62             :     int height;
      63             : 
      64      595572 :     explicit DBHeightKey(int height_in) : height(height_in) {}
      65             : 
      66             :     template<typename Stream>
      67      297346 :     void Serialize(Stream& s) const
      68             :     {
      69      297346 :         ser_writedata8(s, DB_BLOCK_HEIGHT);
      70      297346 :         ser_writedata32be(s, height);
      71      297346 :     }
      72             : 
      73             :     template<typename Stream>
      74       10380 :     void Unserialize(Stream& s)
      75             :     {
      76       10380 :         const uint8_t prefix{ser_readdata8(s)};
      77       10380 :         if (prefix != DB_BLOCK_HEIGHT) {
      78           0 :             throw std::ios_base::failure("Invalid format for block filter index DB height key");
      79             :         }
      80       10380 :         height = ser_readdata32be(s);
      81       10380 :     }
      82             : };
      83             : 
      84             : struct DBHashKey {
      85             :     uint256 hash;
      86             : 
      87       11916 :     explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
      88             : 
      89       17874 :     SERIALIZE_METHODS(DBHashKey, obj) {
      90        5958 :         uint8_t prefix{DB_BLOCK_HASH};
      91        5958 :         READWRITE(prefix);
      92        5958 :         if (prefix != DB_BLOCK_HASH) {
      93           0 :             throw std::ios_base::failure("Invalid format for block filter index DB hash key");
      94             :         }
      95             : 
      96        5958 :         READWRITE(obj.hash);
      97        5958 :     }
      98             : };
      99             : 
     100             : }; // namespace
     101             : 
     102        3308 : static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
     103             : 
     104        2082 : BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type,
     105             :                                    size_t n_cache_size, bool f_memory, bool f_wipe)
     106         694 :     : m_filter_type(filter_type)
     107        1388 : {
     108         694 :     const std::string& filter_name = BlockFilterTypeName(filter_type);
     109         694 :     if (filter_name.empty()) throw std::invalid_argument("unknown filter_type");
     110             : 
     111         694 :     fs::path path = gArgs.GetDataDirNet() / "indexes" / "blockfilter" / fs::u8path(filter_name);
     112         694 :     fs::create_directories(path);
     113             : 
     114         694 :     m_name = filter_name + " block filter index";
     115         694 :     m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
     116             : 
     117             :     // Check version
     118         694 :     int version = 0;
     119         694 :     if (!m_db->Read(DB_VERSION, version) || version < CURRENT_VERSION) {
     120             :         // No version or too old version means we need to start from scratch
     121         694 :         LogPrintf("%s: Outdated or no version blockfilter, starting from scratch\n", __func__);
     122         455 :         m_db.reset();
     123         455 :         m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, /*f_wipe=*/true);
     124         455 :         m_db->Write(DB_VERSION, CURRENT_VERSION);
     125         455 :     }
     126             : 
     127         455 :     m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
     128        1388 : }
     129             : 
     130         691 : bool BlockFilterIndex::Init()
     131             : {
     132             :     // Check version compatibility first
     133         691 :     int version = 0;
     134         691 :     if (m_db->Exists(DB_VERSION)) {
     135         691 :         if (!m_db->Read(DB_VERSION, version)) {
     136           0 :             return error("%s: Failed to read %s index version from database", __func__, GetName());
     137             :         }
     138         691 :         if (version > CURRENT_VERSION) {
     139           0 :             return error("%s: %s index version %d is too high (expected <= %d)",
     140           0 :                         __func__, GetName(), version, CURRENT_VERSION);
     141             :         }
     142         691 :     }
     143             : 
     144         691 :     if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
     145             :         // Check that the cause of the read failure is that the key does not exist. Any other errors
     146             :         // indicate database corruption or a disk failure, and starting the index would cause
     147             :         // further corruption.
     148         452 :         if (m_db->Exists(DB_FILTER_POS)) {
     149           0 :             return error("%s: Cannot read current %s state; index may be corrupted",
     150           0 :                          __func__, GetName());
     151             :         }
     152             : 
     153             :         // If the DB_FILTER_POS is not set, then initialize to the first location.
     154         452 :         m_next_filter_pos.nFile = 0;
     155         452 :         m_next_filter_pos.nPos = 0;
     156         452 :     }
     157         691 :     return BaseIndex::Init();
     158         691 : }
     159             : 
     160        4400 : bool BlockFilterIndex::CommitInternal(CDBBatch& batch)
     161             : {
     162        4400 :     const FlatFilePos& pos = m_next_filter_pos;
     163             : 
     164             :     // Write the current version if this is a new index
     165        4400 :     if (!m_db->Exists(DB_VERSION)) {
     166           0 :         batch.Write(DB_VERSION, CURRENT_VERSION);
     167           0 :     }
     168             : 
     169             :     // Flush current filter file to disk.
     170        4400 :     AutoFile file{m_filter_fileseq->Open(pos)};
     171        4400 :     if (file.IsNull()) {
     172           0 :         return error("%s: Failed to open filter file %d", __func__, pos.nFile);
     173             :     }
     174        4400 :     if (!FileCommit(file.Get())) {
     175           0 :         return error("%s: Failed to commit filter file %d", __func__, pos.nFile);
     176             :     }
     177             : 
     178        4400 :     batch.Write(DB_FILTER_POS, pos);
     179        4400 :     return BaseIndex::CommitInternal(batch);
     180        4400 : }
     181             : 
     182        1217 : bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256& hash, BlockFilter& filter) const
     183             : {
     184        1217 :     AutoFile filein{m_filter_fileseq->Open(pos, true)};
     185        1217 :     if (filein.IsNull()) {
     186           0 :         return false;
     187             :     }
     188             : 
     189             :     // Check that the hash of the encoded_filter matches the one stored in the db.
     190        1217 :     uint256 block_hash;
     191        1217 :     std::vector<uint8_t> encoded_filter;
     192             :     try {
     193        1217 :         filein >> block_hash >> encoded_filter;
     194        1217 :         if (Hash(encoded_filter) != hash) return error("Checksum mismatch in filter decode.");
     195        1217 :         filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
     196        1217 :     }
     197             :     catch (const std::exception& e) {
     198           0 :         return error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
     199           0 :     }
     200             : 
     201        1217 :     return true;
     202        1217 : }
     203             : 
     204      146530 : size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& filter)
     205             : {
     206      146530 :     assert(filter.GetFilterType() == GetFilterType());
     207             : 
     208      146530 :     size_t data_size =
     209      293060 :         GetSerializeSize(filter.GetBlockHash(), CLIENT_VERSION) +
     210      146530 :         GetSerializeSize(filter.GetEncodedFilter(), CLIENT_VERSION);
     211             : 
     212             :     // If writing the filter would overflow the file, flush and move to the next one.
     213      146530 :     if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) {
     214           0 :         AutoFile last_file{m_filter_fileseq->Open(pos)};
     215           0 :         if (last_file.IsNull()) {
     216           0 :             LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
     217           0 :             return 0;
     218             :         }
     219           0 :         if (!TruncateFile(last_file.Get(), pos.nPos)) {
     220           0 :             LogPrintf("%s: Failed to truncate filter file %d\n", __func__, pos.nFile);
     221           0 :             return 0;
     222             :         }
     223           0 :         if (!FileCommit(last_file.Get())) {
     224           0 :             LogPrintf("%s: Failed to commit filter file %d\n", __func__, pos.nFile);
     225           0 :             return 0;
     226             :         }
     227             : 
     228           0 :         pos.nFile++;
     229           0 :         pos.nPos = 0;
     230           0 :     }
     231             : 
     232             :     // Pre-allocate sufficient space for filter data.
     233             :     bool out_of_space;
     234      146530 :     m_filter_fileseq->Allocate(pos, data_size, out_of_space);
     235      146530 :     if (out_of_space) {
     236           0 :         LogPrintf("%s: out of disk space\n", __func__);
     237           0 :         return 0;
     238             :     }
     239             : 
     240      146530 :     AutoFile fileout{m_filter_fileseq->Open(pos)};
     241      146530 :     if (fileout.IsNull()) {
     242           0 :         LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
     243           0 :         return 0;
     244             :     }
     245             : 
     246      146530 :     fileout << filter.GetBlockHash() << filter.GetEncodedFilter();
     247      146530 :     return data_size;
     248      146530 : }
     249             : 
     250      146530 : bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
     251             : {
     252      146530 :     CBlockUndo block_undo;
     253      146530 :     uint256 prev_header;
     254             : 
     255      146530 :     if (pindex->nHeight > 0) {
     256      146078 :         if (!UndoReadFromDisk(block_undo, pindex)) {
     257           0 :             return false;
     258             :         }
     259             : 
     260      146078 :         std::pair<uint256, DBVal> read_out;
     261      146078 :         if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) {
     262           0 :             return false;
     263             :         }
     264             : 
     265      146078 :         uint256 expected_block_hash = pindex->pprev->GetBlockHash();
     266      146078 :         if (read_out.first != expected_block_hash) {
     267           0 :             return error("%s: previous block header belongs to unexpected block %s; expected %s",
     268           0 :                          __func__, read_out.first.ToString(), expected_block_hash.ToString());
     269             :         }
     270             : 
     271      146078 :         prev_header = read_out.second.header;
     272      146078 :     }
     273             : 
     274      146530 :     BlockFilter filter(m_filter_type, block, block_undo);
     275             : 
     276      146530 :     size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter);
     277      146530 :     if (bytes_written == 0) return false;
     278             : 
     279      146530 :     std::pair<uint256, DBVal> value;
     280      146530 :     value.first = pindex->GetBlockHash();
     281      146530 :     value.second.hash = filter.GetHash();
     282      146530 :     value.second.header = filter.ComputeHeader(prev_header);
     283      146530 :     value.second.pos = m_next_filter_pos;
     284             : 
     285      146530 :     if (!m_db->Write(DBHeightKey(pindex->nHeight), value)) {
     286           0 :         return false;
     287             :     }
     288             : 
     289      146530 :     m_next_filter_pos.nPos += bytes_written;
     290      146530 :     return true;
     291      146530 : }
     292             : 
     293        2960 : [[nodiscard]] static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
     294             :                                        const std::string& index_name,
     295             :                                        int start_height, int stop_height)
     296             : {
     297        2960 :     DBHeightKey key(start_height);
     298        2960 :     db_it.Seek(key);
     299             : 
     300        8880 :     for (int height = start_height; height <= stop_height; ++height) {
     301        5920 :         if (!db_it.GetKey(key) || key.height != height) {
     302           0 :             return error("%s: unexpected key in %s: expected (%c, %d)",
     303           0 :                          __func__, index_name, DB_BLOCK_HEIGHT, height);
     304             :         }
     305             : 
     306        5920 :         std::pair<uint256, DBVal> value;
     307        5920 :         if (!db_it.GetValue(value)) {
     308           0 :             return error("%s: unable to read value in %s at key (%c, %d)",
     309           0 :                          __func__, index_name, DB_BLOCK_HEIGHT, height);
     310             :         }
     311             : 
     312        5920 :         batch.Write(DBHashKey(value.first), std::move(value.second));
     313             : 
     314        5920 :         db_it.Next();
     315        5920 :     }
     316        2960 :     return true;
     317        2960 : }
     318             : 
     319        2960 : bool BlockFilterIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
     320             : {
     321        2960 :     assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
     322             : 
     323        2960 :     CDBBatch batch(*m_db);
     324        2960 :     std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
     325             : 
     326             :     // During a reorg, we need to copy all filters for blocks that are getting disconnected from the
     327             :     // height index to the hash index so we can still find them when the height index entries are
     328             :     // overwritten.
     329        2960 :     if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip->nHeight, current_tip->nHeight)) {
     330           0 :         return false;
     331             :     }
     332             : 
     333             :     // The latest filter position gets written in Commit by the call to the BaseIndex::Rewind.
     334             :     // But since this creates new references to the filter, the position should get updated here
     335             :     // atomically as well in case Commit fails.
     336        2960 :     batch.Write(DB_FILTER_POS, m_next_filter_pos);
     337        2960 :     if (!m_db->WriteBatch(batch)) return false;
     338             : 
     339        2960 :     return BaseIndex::Rewind(current_tip, new_tip);
     340        2960 : }
     341             : 
     342        1338 : static bool LookupOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
     343             : {
     344             :     // First check if the result is stored under the height index and the value there matches the
     345             :     // block hash. This should be the case if the block is on the active chain.
     346        1338 :     std::pair<uint256, DBVal> read_out;
     347        1338 :     if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
     348         202 :         return false;
     349             :     }
     350        1136 :     if (read_out.first == block_index->GetBlockHash()) {
     351        1112 :         result = std::move(read_out.second);
     352        1112 :         return true;
     353             :     }
     354             : 
     355             :     // If value at the height index corresponds to an different block, the result will be stored in
     356             :     // the hash index.
     357          24 :     return db.Read(DBHashKey(block_index->GetBlockHash()), result);
     358        1338 : }
     359             : 
     360         440 : static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start_height,
     361             :                         const CBlockIndex* stop_index, std::vector<DBVal>& results)
     362             : {
     363         440 :     if (start_height < 0) {
     364           0 :         return error("%s: start height (%d) is negative", __func__, start_height);
     365             :     }
     366         440 :     if (start_height > stop_index->nHeight) {
     367           0 :         return error("%s: start height (%d) is greater than stop height (%d)",
     368           0 :                      __func__, start_height, stop_index->nHeight);
     369             :     }
     370             : 
     371         440 :     size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
     372         440 :     std::vector<std::pair<uint256, DBVal>> values(results_size);
     373             : 
     374         440 :     DBHeightKey key(start_height);
     375         440 :     std::unique_ptr<CDBIterator> db_it(db.NewIterator());
     376         440 :     db_it->Seek(DBHeightKey(start_height));
     377        4900 :     for (int height = start_height; height <= stop_index->nHeight; ++height) {
     378        4662 :         if (!db_it->Valid() || !db_it->GetKey(key) || key.height != height) {
     379         202 :             return false;
     380             :         }
     381             : 
     382        4460 :         size_t i = static_cast<size_t>(height - start_height);
     383        4460 :         if (!db_it->GetValue(values[i])) {
     384           0 :             return error("%s: unable to read value in %s at key (%c, %d)",
     385           0 :                          __func__, index_name, DB_BLOCK_HEIGHT, height);
     386             :         }
     387             : 
     388        4460 :         db_it->Next();
     389        4460 :     }
     390             : 
     391         238 :     results.resize(results_size);
     392             : 
     393             :     // Iterate backwards through block indexes collecting results in order to access the block hash
     394             :     // of each entry in case we need to look it up in the hash index.
     395        9396 :     for (const CBlockIndex* block_index = stop_index;
     396        4698 :          block_index && block_index->nHeight >= start_height;
     397        4460 :          block_index = block_index->pprev) {
     398        4460 :         uint256 block_hash = block_index->GetBlockHash();
     399             : 
     400        4460 :         size_t i = static_cast<size_t>(block_index->nHeight - start_height);
     401        4460 :         if (block_hash == values[i].first) {
     402        4446 :             results[i] = std::move(values[i].second);
     403        4446 :             continue;
     404             :         }
     405             : 
     406          14 :         if (!db.Read(DBHashKey(block_hash), results[i])) {
     407           0 :             return error("%s: unable to read value in %s at key (%c, %s)",
     408           0 :                          __func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
     409             :         }
     410          14 :     }
     411             : 
     412         238 :     return true;
     413         440 : }
     414             : 
     415        1077 : bool BlockFilterIndex::LookupFilter(const CBlockIndex* block_index, BlockFilter& filter_out) const
     416             : {
     417        1077 :     DBVal entry;
     418        1077 :     if (!LookupOne(*m_db, block_index, entry)) {
     419         101 :         return false;
     420             :     }
     421             : 
     422         976 :     return ReadFilterFromDisk(entry.pos, entry.hash, filter_out);
     423        1077 : }
     424             : 
     425         273 : bool BlockFilterIndex::LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out)
     426             : {
     427         273 :     LOCK(m_cs_headers_cache);
     428             : 
     429         273 :     bool is_checkpoint{block_index->nHeight % CFCHECKPT_INTERVAL == 0};
     430             : 
     431         273 :     if (is_checkpoint) {
     432             :         // Try to find the block in the headers cache if this is a checkpoint height.
     433          24 :         auto header = m_headers_cache.find(block_index->GetBlockHash());
     434          24 :         if (header != m_headers_cache.end()) {
     435          12 :             header_out = header->second;
     436          12 :             return true;
     437             :         }
     438          12 :     }
     439             : 
     440         261 :     DBVal entry;
     441         261 :     if (!LookupOne(*m_db, block_index, entry)) {
     442         101 :         return false;
     443             :     }
     444             : 
     445         160 :     if (is_checkpoint &&
     446          11 :         m_headers_cache.size() < CF_HEADERS_CACHE_MAX_SZ) {
     447             :         // Add to the headers cache if this is a checkpoint height.
     448          11 :         m_headers_cache.emplace(block_index->GetBlockHash(), entry.header);
     449          11 :     }
     450             : 
     451         160 :     header_out = entry.header;
     452         160 :     return true;
     453         273 : }
     454             : 
     455         220 : bool BlockFilterIndex::LookupFilterRange(int start_height, const CBlockIndex* stop_index,
     456             :                                          std::vector<BlockFilter>& filters_out) const
     457             : {
     458         220 :     std::vector<DBVal> entries;
     459         220 :     if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
     460         101 :         return false;
     461             :     }
     462             : 
     463         119 :     filters_out.resize(entries.size());
     464         119 :     auto filter_pos_it = filters_out.begin();
     465         360 :     for (const auto& entry : entries) {
     466         241 :         if (!ReadFilterFromDisk(entry.pos, entry.hash, *filter_pos_it)) {
     467           0 :             return false;
     468             :         }
     469         241 :         ++filter_pos_it;
     470             :     }
     471             : 
     472         119 :     return true;
     473         220 : }
     474             : 
     475         220 : bool BlockFilterIndex::LookupFilterHashRange(int start_height, const CBlockIndex* stop_index,
     476             :                                              std::vector<uint256>& hashes_out) const
     477             : 
     478             : {
     479         220 :     std::vector<DBVal> entries;
     480         220 :     if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
     481         101 :         return false;
     482             :     }
     483             : 
     484         119 :     hashes_out.clear();
     485         119 :     hashes_out.reserve(entries.size());
     486        4338 :     for (const auto& entry : entries) {
     487        4219 :         hashes_out.push_back(entry.hash);
     488             :     }
     489         119 :     return true;
     490         220 : }
     491             : 
     492        2135 : BlockFilterIndex* GetBlockFilterIndex(BlockFilterType filter_type)
     493             : {
     494        2135 :     auto it = g_filter_indexes.find(filter_type);
     495        2135 :     return it != g_filter_indexes.end() ? &it->second : nullptr;
     496             : }
     497             : 
     498        6185 : void ForEachBlockFilterIndex(std::function<void (BlockFilterIndex&)> fn)
     499             : {
     500        7684 :     for (auto& entry : g_filter_indexes) fn(entry.second);
     501        6185 : }
     502             : 
     503         693 : bool InitBlockFilterIndex(BlockFilterType filter_type,
     504             :                           size_t n_cache_size, bool f_memory, bool f_wipe)
     505             : {
     506         693 :     auto result = g_filter_indexes.emplace(std::piecewise_construct,
     507         693 :                                            std::forward_as_tuple(filter_type),
     508         693 :                                            std::forward_as_tuple(filter_type,
     509             :                                                                  n_cache_size, f_memory, f_wipe));
     510         693 :     return result.second;
     511             : }
     512             : 
     513           2 : bool DestroyBlockFilterIndex(BlockFilterType filter_type)
     514             : {
     515           2 :     return g_filter_indexes.erase(filter_type);
     516             : }
     517             : 
     518        3031 : void DestroyAllBlockFilterIndexes()
     519             : {
     520        3031 :     g_filter_indexes.clear();
     521        3031 : }

Generated by: LCOV version 1.16