Skip to content

Commit

Permalink
sync from start height h/t fjahr
Browse files Browse the repository at this point in the history
  • Loading branch information
josibake committed Jan 27, 2024
1 parent 2069b83 commit c3a4ee9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator
batch.Write(DB_BEST_BLOCK, locator);
}

BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name)
: m_chain{std::move(chain)}, m_name{std::move(name)} {}
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name, int start_height)
: m_chain{std::move(chain)}, m_name{std::move(name)}, m_start_height{std::move(start_height)} {}

BaseIndex::~BaseIndex()
{
Expand Down Expand Up @@ -125,11 +125,12 @@ bool BaseIndex::Init()
return true;
}

static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev, CChain& chain) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev, CChain& chain, int start_height) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
AssertLockHeld(cs_main);

if (!pindex_prev) {
if (start_height > 0) return chain[start_height];
return chain.Genesis();
}

Expand Down Expand Up @@ -161,7 +162,7 @@ void BaseIndex::ThreadSync()

{
LOCK(cs_main);
const CBlockIndex* pindex_next = NextSyncBlock(pindex, m_chainstate->m_chain);
const CBlockIndex* pindex_next = NextSyncBlock(pindex, m_chainstate->m_chain, m_start_height);
if (!pindex_next) {
SetBestBlockIndex(pindex);
m_synced = true;
Expand Down
3 changes: 2 additions & 1 deletion src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class BaseIndex : public CValidationInterface
std::unique_ptr<interfaces::Chain> m_chain;
Chainstate* m_chainstate{nullptr};
const std::string m_name;
const int m_start_height{0};

void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;

Expand All @@ -132,7 +133,7 @@ class BaseIndex : public CValidationInterface
void SetBestBlockIndex(const CBlockIndex* block);

public:
BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name);
BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name, int start_height = 0);
/// Destructor interrupts sync thread if running and blocks until it exits.
virtual ~BaseIndex();

Expand Down
7 changes: 6 additions & 1 deletion src/index/blockfilterindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <undo.h>
#include <util/fs_helpers.h>
#include <validation.h>
#include <chainparams.h>

/* The index database stores three items for each block: the disk location of the encoded filter,
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
Expand Down Expand Up @@ -99,7 +100,11 @@ 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")
: BaseIndex(
std::move(chain),
BlockFilterTypeName(filter_type) + " block filter index",
(filter_type == BlockFilterType::SILENT_PAYMENTS ? Params().GetConsensus().vDeployments[Consensus::DEPLOYMENT_TAPROOT].min_activation_height : 0)
)
, m_filter_type(filter_type)
{
const std::string& filter_name = BlockFilterTypeName(filter_type);
Expand Down

0 comments on commit c3a4ee9

Please sign in to comment.