| 375 | } |
| 376 | |
| 377 | bool BlockFilterIndex::LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out) |
| 378 | { |
| 379 | LOCK(m_cs_headers_cache); |
| 380 | |
| 381 | bool is_checkpoint{block_index->nHeight % CFCHECKPT_INTERVAL == 0}; |
| 382 | |
| 383 | if (is_checkpoint) { |
| 384 | // Try to find the block in the headers cache if this is a checkpoint height. |
| 385 | auto header = m_headers_cache.find(block_index->GetBlockHash()); |
| 386 | if (header != m_headers_cache.end()) { |
| 387 | header_out = header->second; |
| 388 | return true; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | DBVal entry; |
| 393 | if (!index_util::LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) { |
| 394 | return false; |
| 395 | } |
| 396 | |
| 397 | if (is_checkpoint && |
| 398 | m_headers_cache.size() < CF_HEADERS_CACHE_MAX_SZ) { |
| 399 | // Add to the headers cache if this is a checkpoint height. |
| 400 | m_headers_cache.emplace(block_index->GetBlockHash(), entry.header); |
| 401 | } |
| 402 | |
| 403 | header_out = entry.header; |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | bool BlockFilterIndex::LookupFilterRange(int start_height, const CBlockIndex* stop_index, |
| 408 | std::vector<BlockFilter>& filters_out) const |