Bitcoin ABC  0.24.7
P2P Digital Currency
blockfilterindex.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 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 <dbwrapper.h>
7 #include <primitives/blockhash.h>
8 #include <util/system.h>
9 #include <validation.h>
10 
11 #include <map>
12 
32 constexpr char DB_BLOCK_HASH = 's';
33 constexpr char DB_BLOCK_HEIGHT = 't';
34 constexpr char DB_FILTER_POS = 'P';
35 
36 // 16 MiB
37 constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000;
39 // 1 MiB
40 constexpr unsigned int FLTR_FILE_CHUNK_SIZE = 0x100000;
41 
49 constexpr size_t CF_HEADERS_CACHE_MAX_SZ{2000};
50 
51 namespace {
52 
53 struct DBVal {
54  uint256 hash;
55  uint256 header;
56  FlatFilePos pos;
57 
58  SERIALIZE_METHODS(DBVal, obj) { READWRITE(obj.hash, obj.header, obj.pos); }
59 };
60 
61 struct DBHeightKey {
62  int height;
63 
64  DBHeightKey() : height(0) {}
65  explicit DBHeightKey(int height_in) : height(height_in) {}
66 
67  template <typename Stream> void Serialize(Stream &s) const {
69  ser_writedata32be(s, height);
70  }
71 
72  template <typename Stream> void Unserialize(Stream &s) {
73  char prefix = ser_readdata8(s);
74  if (prefix != DB_BLOCK_HEIGHT) {
75  throw std::ios_base::failure(
76  "Invalid format for block filter index DB height key");
77  }
78  height = ser_readdata32be(s);
79  }
80 };
81 
82 struct DBHashKey {
83  BlockHash hash;
84 
85  explicit DBHashKey(const BlockHash &hash_in) : hash(hash_in) {}
86 
87  SERIALIZE_METHODS(DBHashKey, obj) {
88  char prefix = DB_BLOCK_HASH;
90  if (prefix != DB_BLOCK_HASH) {
91  throw std::ios_base::failure(
92  "Invalid format for block filter index DB hash key");
93  }
94 
95  READWRITE(obj.hash);
96  }
97 };
98 
99 }; // namespace
100 
101 static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
102 
104  size_t n_cache_size, bool f_memory,
105  bool f_wipe)
106  : m_filter_type(filter_type) {
107  const std::string &filter_name = BlockFilterTypeName(filter_type);
108  if (filter_name.empty()) {
109  throw std::invalid_argument("unknown filter_type");
110  }
111 
112  fs::path path = GetDataDir() / "indexes" / "blockfilter" / filter_name;
113  fs::create_directories(path);
114 
115  m_name = filter_name + " block filter index";
116  m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory,
117  f_wipe);
118  m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr",
120 }
121 
123  if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
124  // Check that the cause of the read failure is that the key does not
125  // exist. Any other errors indicate database corruption or a disk
126  // failure, and starting the index would cause further corruption.
127  if (m_db->Exists(DB_FILTER_POS)) {
128  return error(
129  "%s: Cannot read current %s state; index may be corrupted",
130  __func__, GetName());
131  }
132 
133  // If the DB_FILTER_POS is not set, then initialize to the first
134  // location.
137  }
138  return BaseIndex::Init();
139 }
140 
142  const FlatFilePos &pos = m_next_filter_pos;
143 
144  // Flush current filter file to disk.
146  if (file.IsNull()) {
147  return error("%s: Failed to open filter file %d", __func__, pos.nFile);
148  }
149  if (!FileCommit(file.Get())) {
150  return error("%s: Failed to commit filter file %d", __func__,
151  pos.nFile);
152  }
153 
154  batch.Write(DB_FILTER_POS, pos);
155  return BaseIndex::CommitInternal(batch);
156 }
157 
159  BlockFilter &filter) const {
160  CAutoFile filein(m_filter_fileseq->Open(pos, true), SER_DISK,
162  if (filein.IsNull()) {
163  return false;
164  }
165 
166  BlockHash block_hash;
167  std::vector<uint8_t> encoded_filter;
168  try {
169  filein >> block_hash >> encoded_filter;
170  filter =
171  BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter));
172  } catch (const std::exception &e) {
173  return error("%s: Failed to deserialize block filter from disk: %s",
174  __func__, e.what());
175  }
176 
177  return true;
178 }
179 
181  const BlockFilter &filter) {
182  assert(filter.GetFilterType() == GetFilterType());
183 
184  size_t data_size =
187 
188  // If writing the filter would overflow the file, flush and move to the next
189  // one.
190  if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) {
191  CAutoFile last_file(m_filter_fileseq->Open(pos), SER_DISK,
193  if (last_file.IsNull()) {
194  LogPrintf("%s: Failed to open filter file %d\n", __func__,
195  pos.nFile);
196  return 0;
197  }
198  if (!TruncateFile(last_file.Get(), pos.nPos)) {
199  LogPrintf("%s: Failed to truncate filter file %d\n", __func__,
200  pos.nFile);
201  return 0;
202  }
203  if (!FileCommit(last_file.Get())) {
204  LogPrintf("%s: Failed to commit filter file %d\n", __func__,
205  pos.nFile);
206  return 0;
207  }
208 
209  pos.nFile++;
210  pos.nPos = 0;
211  }
212 
213  // Pre-allocate sufficient space for filter data.
214  bool out_of_space;
215  m_filter_fileseq->Allocate(pos, data_size, out_of_space);
216  if (out_of_space) {
217  LogPrintf("%s: out of disk space\n", __func__);
218  return 0;
219  }
220 
221  CAutoFile fileout(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION);
222  if (fileout.IsNull()) {
223  LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile);
224  return 0;
225  }
226 
227  fileout << filter.GetBlockHash() << filter.GetEncodedFilter();
228  return data_size;
229 }
230 
232  const CBlockIndex *pindex) {
233  CBlockUndo block_undo;
234  uint256 prev_header;
235 
236  if (pindex->nHeight > 0) {
237  if (!UndoReadFromDisk(block_undo, pindex)) {
238  return false;
239  }
240 
241  std::pair<BlockHash, DBVal> read_out;
242  if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) {
243  return false;
244  }
245 
246  BlockHash expected_block_hash = pindex->pprev->GetBlockHash();
247  if (read_out.first != expected_block_hash) {
248  return error("%s: previous block header belongs to unexpected "
249  "block %s; expected %s",
250  __func__, read_out.first.ToString(),
251  expected_block_hash.ToString());
252  }
253 
254  prev_header = read_out.second.header;
255  }
256 
257  BlockFilter filter(m_filter_type, block, block_undo);
258 
259  size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter);
260  if (bytes_written == 0) {
261  return false;
262  }
263 
264  std::pair<BlockHash, DBVal> value;
265  value.first = pindex->GetBlockHash();
266  value.second.hash = filter.GetHash();
267  value.second.header = filter.ComputeHeader(prev_header);
268  value.second.pos = m_next_filter_pos;
269 
270  if (!m_db->Write(DBHeightKey(pindex->nHeight), value)) {
271  return false;
272  }
273 
274  m_next_filter_pos.nPos += bytes_written;
275  return true;
276 }
277 
279  const std::string &index_name,
280  int start_height, int stop_height) {
281  DBHeightKey key(start_height);
282  db_it.Seek(key);
283 
284  for (int height = start_height; height <= stop_height; ++height) {
285  if (!db_it.GetKey(key) || key.height != height) {
286  return error("%s: unexpected key in %s: expected (%c, %d)",
287  __func__, index_name, DB_BLOCK_HEIGHT, height);
288  }
289 
290  std::pair<BlockHash, DBVal> value;
291  if (!db_it.GetValue(value)) {
292  return error("%s: unable to read value in %s at key (%c, %d)",
293  __func__, index_name, DB_BLOCK_HEIGHT, height);
294  }
295 
296  batch.Write(DBHashKey(value.first), std::move(value.second));
297 
298  db_it.Next();
299  }
300  return true;
301 }
302 
303 bool BlockFilterIndex::Rewind(const CBlockIndex *current_tip,
304  const CBlockIndex *new_tip) {
305  assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
306 
307  CDBBatch batch(*m_db);
308  std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
309 
310  // During a reorg, we need to copy all filters for blocks that are getting
311  // disconnected from the height index to the hash index so we can still find
312  // them when the height index entries are overwritten.
313  if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip->nHeight,
314  current_tip->nHeight)) {
315  return false;
316  }
317 
318  // The latest filter position gets written in Commit by the call to the
319  // BaseIndex::Rewind. But since this creates new references to the filter,
320  // the position should get updated here atomically as well in case Commit
321  // fails.
323  if (!m_db->WriteBatch(batch)) {
324  return false;
325  }
326 
327  return BaseIndex::Rewind(current_tip, new_tip);
328 }
329 
330 static bool LookupOne(const CDBWrapper &db, const CBlockIndex *block_index,
331  DBVal &result) {
332  // First check if the result is stored under the height index and the value
333  // there matches the block hash. This should be the case if the block is on
334  // the active chain.
335  std::pair<BlockHash, DBVal> read_out;
336  if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
337  return false;
338  }
339  if (read_out.first == block_index->GetBlockHash()) {
340  result = std::move(read_out.second);
341  return true;
342  }
343 
344  // If value at the height index corresponds to an different block, the
345  // result will be stored in the hash index.
346  return db.Read(DBHashKey(block_index->GetBlockHash()), result);
347 }
348 
349 static bool LookupRange(CDBWrapper &db, const std::string &index_name,
350  int start_height, const CBlockIndex *stop_index,
351  std::vector<DBVal> &results) {
352  if (start_height < 0) {
353  return error("%s: start height (%d) is negative", __func__,
354  start_height);
355  }
356  if (start_height > stop_index->nHeight) {
357  return error("%s: start height (%d) is greater than stop height (%d)",
358  __func__, start_height, stop_index->nHeight);
359  }
360 
361  size_t results_size =
362  static_cast<size_t>(stop_index->nHeight - start_height + 1);
363  std::vector<std::pair<BlockHash, DBVal>> values(results_size);
364 
365  DBHeightKey key(start_height);
366  std::unique_ptr<CDBIterator> db_it(db.NewIterator());
367  db_it->Seek(DBHeightKey(start_height));
368  for (int height = start_height; height <= stop_index->nHeight; ++height) {
369  if (!db_it->Valid() || !db_it->GetKey(key) || key.height != height) {
370  return false;
371  }
372 
373  size_t i = static_cast<size_t>(height - start_height);
374  if (!db_it->GetValue(values[i])) {
375  return error("%s: unable to read value in %s at key (%c, %d)",
376  __func__, index_name, DB_BLOCK_HEIGHT, height);
377  }
378 
379  db_it->Next();
380  }
381 
382  results.resize(results_size);
383 
384  // Iterate backwards through block indexes collecting results in order to
385  // access the block hash of each entry in case we need to look it up in the
386  // hash index.
387  for (const CBlockIndex *block_index = stop_index;
388  block_index && block_index->nHeight >= start_height;
389  block_index = block_index->pprev) {
390  BlockHash block_hash = block_index->GetBlockHash();
391 
392  size_t i = static_cast<size_t>(block_index->nHeight - start_height);
393  if (block_hash == values[i].first) {
394  results[i] = std::move(values[i].second);
395  continue;
396  }
397 
398  if (!db.Read(DBHashKey(block_hash), results[i])) {
399  return error("%s: unable to read value in %s at key (%c, %s)",
400  __func__, index_name, DB_BLOCK_HASH,
401  block_hash.ToString());
402  }
403  }
404 
405  return true;
406 }
407 
409  BlockFilter &filter_out) const {
410  DBVal entry;
411  if (!LookupOne(*m_db, block_index, entry)) {
412  return false;
413  }
414 
415  return ReadFilterFromDisk(entry.pos, filter_out);
416 }
417 
419  uint256 &header_out) {
421 
422  bool is_checkpoint{block_index->nHeight % CFCHECKPT_INTERVAL == 0};
423 
424  if (is_checkpoint) {
425  // Try to find the block in the headers cache if this is a checkpoint
426  // height.
427  auto header = m_headers_cache.find(block_index->GetBlockHash());
428  if (header != m_headers_cache.end()) {
429  header_out = header->second;
430  return true;
431  }
432  }
433 
434  DBVal entry;
435  if (!LookupOne(*m_db, block_index, entry)) {
436  return false;
437  }
438 
439  if (is_checkpoint && m_headers_cache.size() < CF_HEADERS_CACHE_MAX_SZ) {
440  // Add to the headers cache if this is a checkpoint height.
441  m_headers_cache.emplace(block_index->GetBlockHash(), entry.header);
442  }
443 
444  header_out = entry.header;
445  return true;
446 }
447 
449  int start_height, const CBlockIndex *stop_index,
450  std::vector<BlockFilter> &filters_out) const {
451  std::vector<DBVal> entries;
452  if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
453  return false;
454  }
455 
456  filters_out.resize(entries.size());
457  auto filter_pos_it = filters_out.begin();
458  for (const auto &entry : entries) {
459  if (!ReadFilterFromDisk(entry.pos, *filter_pos_it)) {
460  return false;
461  }
462  ++filter_pos_it;
463  }
464 
465  return true;
466 }
467 
469  int start_height, const CBlockIndex *stop_index,
470  std::vector<uint256> &hashes_out) const
471 
472 {
473  std::vector<DBVal> entries;
474  if (!LookupRange(*m_db, m_name, start_height, stop_index, entries)) {
475  return false;
476  }
477 
478  hashes_out.clear();
479  hashes_out.reserve(entries.size());
480  for (const auto &entry : entries) {
481  hashes_out.push_back(entry.hash);
482  }
483  return true;
484 }
485 
487  auto it = g_filter_indexes.find(filter_type);
488  return it != g_filter_indexes.end() ? &it->second : nullptr;
489 }
490 
491 void ForEachBlockFilterIndex(std::function<void(BlockFilterIndex &)> fn) {
492  for (auto &entry : g_filter_indexes) {
493  fn(entry.second);
494  }
495 }
496 
497 bool InitBlockFilterIndex(BlockFilterType filter_type, size_t n_cache_size,
498  bool f_memory, bool f_wipe) {
499  auto result = g_filter_indexes.emplace(
500  std::piecewise_construct, std::forward_as_tuple(filter_type),
501  std::forward_as_tuple(filter_type, n_cache_size, f_memory, f_wipe));
502  return result.second;
503 }
504 
506  return g_filter_indexes.erase(filter_type);
507 }
508 
510  g_filter_indexes.clear();
511 }
BlockFilterIndex::m_name
std::string m_name
Definition: blockfilterindex.h:33
FLTR_FILE_CHUNK_SIZE
constexpr unsigned int FLTR_FILE_CHUNK_SIZE
The pre-allocation chunk size for fltr?????.dat files.
Definition: blockfilterindex.cpp:40
GetSerializeSize
size_t GetSerializeSize(const T &t, int nVersion=0)
Definition: serialize.h:1182
FlatFilePos::nFile
int nFile
Definition: flatfile.h:15
BlockFilterTypeName
const std::string & BlockFilterTypeName(BlockFilterType filter_type)
Get the human-readable name for a filter type.
Definition: blockfilter.cpp:175
GetDataDir
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:779
dbwrapper.h
SERIALIZE_METHODS
#define SERIALIZE_METHODS(cls, obj)
Implement the Serialize and Unserialize methods by delegating to a single templated static method tha...
Definition: serialize.h:226
CBlockIndex::GetAncestor
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: blockindex.cpp:71
BlockFilter::GetFilterType
BlockFilterType GetFilterType() const
Definition: blockfilter.h:130
CDBBatch
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:48
BlockFilterIndex::m_db
std::unique_ptr< BaseIndex::DB > m_db
Definition: blockfilterindex.h:34
BlockFilterIndex::WriteFilterToDisk
size_t WriteFilterToDisk(FlatFilePos &pos, const BlockFilter &filter)
Definition: blockfilterindex.cpp:180
BaseIndex::Init
virtual bool Init()
Initialize internal state from the database and block index.
Definition: base.cpp:54
blockfilterindex.h
CAutoFile::Get
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
Definition: streams.h:624
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: blockindex.h:30
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:36
BlockFilter::GetBlockHash
const BlockHash & GetBlockHash() const
Definition: blockfilter.h:131
BlockFilterIndex
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
Definition: blockfilterindex.h:30
BlockFilter::ComputeHeader
uint256 ComputeHeader(const uint256 &prev_header) const
Compute the filter header given the previous one.
Definition: blockfilter.cpp:296
blockhash.h
g_filter_indexes
static std::map< BlockFilterType, BlockFilterIndex > g_filter_indexes
Definition: blockfilterindex.cpp:99
BlockFilterIndex::CommitInternal
bool CommitInternal(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
Definition: blockfilterindex.cpp:141
DestroyBlockFilterIndex
bool DestroyBlockFilterIndex(BlockFilterType filter_type)
Destroy the block filter index with the given type.
Definition: blockfilterindex.cpp:505
TruncateFile
bool TruncateFile(FILE *file, unsigned int length)
Definition: system.cpp:1175
CBlockIndex::GetBlockHash
BlockHash GetBlockHash() const
Definition: blockindex.h:133
CDBIterator::Next
void Next()
Definition: dbwrapper.cpp:248
prefix
const char * prefix
Definition: rest.cpp:772
CDBBatch::Write
void Write(const K &key, const V &value)
Definition: dbwrapper.h:73
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:581
ser_readdata32be
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:117
BlockFilterIndex::Init
bool Init() override
Initialize internal state from the database and block index.
Definition: blockfilterindex.cpp:122
CDBIterator::GetValue
bool GetValue(V &value)
Definition: dbwrapper.h:155
BlockFilterIndex::m_filter_type
BlockFilterType m_filter_type
Definition: blockfilterindex.h:32
Unserialize
void Unserialize(Stream &s, char &a)
Definition: serialize.h:293
BaseIndex::Rewind
virtual bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip)
Rewind index to an earlier chain tip during a chain reorg.
Definition: base.cpp:176
FlatFilePos
Definition: flatfile.h:14
BlockFilterIndex::LookupFilterRange
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.
Definition: blockfilterindex.cpp:448
DB_BLOCK_HEIGHT
constexpr char DB_BLOCK_HEIGHT
Definition: blockfilterindex.cpp:33
LookupOne
static bool LookupOne(const CDBWrapper &db, const CBlockIndex *block_index, DBVal &result)
Definition: blockfilterindex.cpp:330
ser_readdata8
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:97
BlockFilterIndex::Rewind
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
Definition: blockfilterindex.cpp:303
CAutoFile::IsNull
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
Definition: streams.h:627
base_blob::ToString
std::string ToString() const
Definition: uint256.h:78
uint256
256-bit opaque blob.
Definition: uint256.h:127
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
ser_writedata8
void ser_writedata8(Stream &s, uint8_t obj)
Lowest-level serialization and conversion.
Definition: serialize.h:69
LookupRange
static bool LookupRange(CDBWrapper &db, const std::string &index_name, int start_height, const CBlockIndex *stop_index, std::vector< DBVal > &results)
Definition: blockfilterindex.cpp:349
DB_BLOCK_HASH
constexpr char DB_BLOCK_HASH
The index database stores three items for each block: the disk location of the encoded filter,...
Definition: blockfilterindex.cpp:32
CDBIterator::Seek
void Seek(const K &key)
Definition: dbwrapper.h:133
db
CAddrDb db
Definition: main.cpp:193
BlockHash
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
BlockFilter::GetHash
uint256 GetHash() const
Compute the filter hash.
Definition: blockfilter.cpp:288
CDBWrapper
Definition: dbwrapper.h:171
BlockFilter::GetEncodedFilter
const std::vector< uint8_t > & GetEncodedFilter() const
Definition: blockfilter.h:134
system.h
CBlock
Definition: block.h:55
CLIENT_VERSION
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
Definition: clientversion.h:44
BlockFilterIndex::ReadFilterFromDisk
bool ReadFilterFromDisk(const FlatFilePos &pos, BlockFilter &filter) const
Definition: blockfilterindex.cpp:158
BlockFilterIndex::m_next_filter_pos
FlatFilePos m_next_filter_pos
Definition: blockfilterindex.h:36
BlockFilterIndex::LookupFilterHashRange
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.
Definition: blockfilterindex.cpp:468
BaseIndex::CommitInternal
virtual bool CommitInternal(CDBBatch &batch)
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
Definition: base.cpp:169
GetBlockFilterIndex
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
Definition: blockfilterindex.cpp:486
ForEachBlockFilterIndex
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
Definition: blockfilterindex.cpp:491
LOCK
#define LOCK(cs)
Definition: sync.h:241
FileCommit
bool FileCommit(FILE *file)
Definition: system.cpp:1139
ser_writedata32be
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:88
UndoReadFromDisk
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
Definition: validation.cpp:1267
CDBIterator::GetKey
bool GetKey(K &key)
Definition: dbwrapper.h:143
BlockFilterIndex::WriteBlock
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Definition: blockfilterindex.cpp:231
CF_HEADERS_CACHE_MAX_SZ
constexpr size_t CF_HEADERS_CACHE_MAX_SZ
Maximum size of the cfheaders cache.
Definition: blockfilterindex.cpp:49
MAX_FLTR_FILE_SIZE
constexpr unsigned int MAX_FLTR_FILE_SIZE
Definition: blockfilterindex.cpp:37
CFCHECKPT_INTERVAL
static constexpr int CFCHECKPT_INTERVAL
Interval between compact filter checkpoints.
Definition: blockfilterindex.h:14
BlockFilterIndex::LookupFilter
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
Definition: blockfilterindex.cpp:408
SER_DISK
@ SER_DISK
Definition: serialize.h:166
DB_FILTER_POS
constexpr char DB_FILTER_POS
Definition: blockfilterindex.cpp:34
InitBlockFilterIndex
bool InitBlockFilterIndex(BlockFilterType filter_type, size_t n_cache_size, bool f_memory, bool f_wipe)
Initialize a block filter index for the given type if one does not already exist.
Definition: blockfilterindex.cpp:497
BlockFilterType
BlockFilterType
Definition: blockfilter.h:88
FlatFilePos::nPos
unsigned int nPos
Definition: flatfile.h:16
BlockFilterIndex::GetFilterType
BlockFilterType GetFilterType() const
Definition: blockfilterindex.h:69
BlockFilterIndex::m_cs_headers_cache
Mutex m_cs_headers_cache
Definition: blockfilterindex.h:42
CopyHeightIndexToHashIndex
static bool CopyHeightIndexToHashIndex(CDBIterator &db_it, CDBBatch &batch, const std::string &index_name, int start_height, int stop_height)
Definition: blockfilterindex.cpp:278
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
BlockFilterIndex::BlockFilterIndex
BlockFilterIndex(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.
Definition: blockfilterindex.cpp:103
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
Serialize
void Serialize(Stream &s, char a)
Definition: serialize.h:241
BlockFilterIndex::LookupFilterHeader
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out)
Get a single filter header by block.
Definition: blockfilterindex.cpp:418
LogPrintf
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:175
DestroyAllBlockFilterIndexes
void DestroyAllBlockFilterIndexes()
Destroy all open block filter indexes.
Definition: blockfilterindex.cpp:509
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:73
BlockFilterIndex::m_filter_fileseq
std::unique_ptr< FlatFileSeq > m_filter_fileseq
Definition: blockfilterindex.h:37
CDBIterator
Definition: dbwrapper.h:115
BlockFilterIndex::GetName
const char * GetName() const override
Get the name of the index for display in logs.
Definition: blockfilterindex.h:62
BlockFilter
Complete block filter struct as defined in BIP 157.
Definition: blockfilter.h:111