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