From c7682aa277e9fc3ae72ee619d3347fda118ebd68 Mon Sep 17 00:00:00 2001
From: josibake <josibake@protonmail.com>
Date: Wed, 31 Jan 2024 15:41:34 +0100
Subject: [PATCH] index: add start_height to blockfilterindex

Allow start_height to be specified when creating a blockfilterindex
---
 src/index/blockfilterindex.cpp | 11 ++++++++---
 src/index/blockfilterindex.h   |  5 ++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index 58f777b3266073..dc09806317b6e2 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -98,8 +98,13 @@ struct DBHashKey {
 static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
 
 BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
-                                   size_t n_cache_size, bool f_memory, bool f_wipe)
-    : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index")
+                                   size_t n_cache_size, bool f_memory, bool f_wipe, int start_height)
+    : BaseIndex(
+            std::move(chain),
+            BlockFilterTypeName(filter_type) + " block filter index",
+            start_height
+    )
+    , m_start_height(start_height)
     , m_filter_type(filter_type)
 {
     const std::string& filter_name = BlockFilterTypeName(filter_type);
@@ -220,7 +225,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
     CBlockUndo block_undo;
     uint256 prev_header;
 
-    if (block.height > 0) {
+    if (block.height > m_start_height) {
         // pindex variable gives indexing code access to node internals. It
         // will be removed in upcoming commit
         const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h
index 10a1cfd2ee0e54..d13ec3dacac99a 100644
--- a/src/index/blockfilterindex.h
+++ b/src/index/blockfilterindex.h
@@ -29,6 +29,7 @@ static constexpr int CFCHECKPT_INTERVAL = 1000;
 class BlockFilterIndex final : public BaseIndex
 {
 private:
+    const int m_start_height;
     BlockFilterType m_filter_type;
     std::unique_ptr<BaseIndex::DB> m_db;
 
@@ -58,7 +59,9 @@ class BlockFilterIndex final : public BaseIndex
 public:
     /** Constructs the index, which becomes available to be queried. */
     explicit BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
-                              size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
+                              size_t n_cache_size, bool f_memory = false, bool f_wipe = false, int start_height = 0);
+
+    int GetStartHeight() const { return m_start_height; }
 
     BlockFilterType GetFilterType() const { return m_filter_type; }