Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index for BIP 157 block filters #14121

merged 12 commits into from Apr 18, 2019

index: Ensure block locator is not stale after chain reorg.

  • Loading branch information...
jimpo committed Aug 27, 2018
commit 62b7a4f09409f60a35fc99ddb70f9199ac511a53
@@ -113,6 +113,11 @@ void BaseIndex::ThreadSync()
if (pindex_next->pprev != pindex && !Rewind(pindex, pindex_next->pprev)) {
FatalError("%s: Failed to rewind index %s to a previous chain tip",
__func__, GetName());
pindex = pindex_next;

@@ -167,6 +172,22 @@ bool BaseIndex::CommitInternal(CDBBatch& batch)
return true;

bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
This conversation was marked as resolved by jimpo

This comment has been minimized.

Copy link

ryanofsky Mar 25, 2019


In commit "index: Allow atomic commits of index state to be extended." (e3845e4)

This commit still doesn't compile because BaseIndex::Rewind declaration is not added until the next commit.

assert(current_tip == m_best_block_index);
assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);

// In the case of a reorg, ensure persisted block locator is not stale.
m_best_block_index = new_tip;
if (!Commit()) {
// If commit fails, revert the best block index to avoid corruption.
m_best_block_index = current_tip;
return false;

return true;

void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex,
const std::vector<CTransactionRef>& txn_conflicted)
@@ -194,6 +215,11 @@ void BaseIndex::BlockConnected(const std::shared_ptr<const CBlock>& block, const
if (best_block_index != pindex->pprev && !Rewind(best_block_index, pindex->pprev)) {
FatalError("%s: Failed to rewind index %s to a previous chain tip",
__func__, GetName());

if (WriteBlock(*block, pindex)) {
@@ -80,6 +80,10 @@ class BaseIndex : public CValidationInterface
/// commit more index state.
virtual bool CommitInternal(CDBBatch& batch);

/// Rewind index to an earlier chain tip during a chain reorg. The tip must
/// be an ancestor of the current best block.
virtual bool Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip);

virtual DB& GetDB() const = 0;

/// Get the name of the index for display in logs.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.