Skip to content

Commit

Permalink
[net processing] Synchronize cfilter request handling with block filt…
Browse files Browse the repository at this point in the history
…er index.

Since the block filter index is updated asynchronously by proxy of the
ValidationInterface queue, lazily synchronize the net thread with the
block filter index in case lookups fail.

Github-Pull: bitcoin#18876
Rebased-From: 5488ce9
  • Loading branch information
jimpo authored and luke-jr committed May 14, 2020
1 parent 7cfee10 commit ea5a8ae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/index/base.h
Expand Up @@ -84,13 +84,13 @@ class BaseIndex : public CValidationInterface

virtual DB& GetDB() const = 0;

/// Get the name of the index for display in logs.
virtual const char* GetName() const = 0;

public:
/// Destructor interrupts sync thread if running and blocks until it exits.
virtual ~BaseIndex();

/// Get the name of the index for display in logs.
virtual const char* GetName() const = 0;

/// Returns whether index has completed the initial sync with the active chain.
/// After returning true once, this function will return true on all subsequent calls.
bool IsSynced() const { return m_synced; }
Expand Down
4 changes: 2 additions & 2 deletions src/index/blockfilterindex.h
Expand Up @@ -41,13 +41,13 @@ class BlockFilterIndex final : public BaseIndex

BaseIndex::DB& GetDB() const override { return *m_db; }

const char* GetName() const override { return m_name.c_str(); }

public:
/** Constructs the index, which becomes available to be queried. */
explicit BlockFilterIndex(BlockFilterType filter_type,
size_t n_cache_size, bool f_memory = false, bool f_wipe = false);

const char* GetName() const override { return m_name.c_str(); }

BlockFilterType GetFilterType() const { return m_filter_type; }

/** Get a single filter by block. */
Expand Down
4 changes: 2 additions & 2 deletions src/index/txindex.h
Expand Up @@ -30,15 +30,15 @@ class TxIndex final : public BaseIndex

BaseIndex::DB& GetDB() const override;

const char* GetName() const override { return "txindex"; }

public:
/// Constructs the index, which becomes available to be queried.
explicit TxIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);

// Destructor is declared because this class contains a unique_ptr to an incomplete type.
virtual ~TxIndex() override;

const char* GetName() const override { return "txindex"; }

/// Look up a transaction by hash.
///
/// @param[in] tx_hash The hash of the transaction to be returned.
Expand Down
4 changes: 4 additions & 0 deletions src/net_processing.cpp
Expand Up @@ -2022,6 +2022,10 @@ static bool PrepareBlockFilterRequest(CNode* pfrom, const CChainParams& chain_pa
LogPrint(BCLog::NET, "Filter index for supported type %s not found\n", BlockFilterTypeName(filter_type));
return false;
}
if (!filter_index->BlockUntilSyncedToCurrentChain()) {
LogPrint(BCLog::NET, "%s is not ready yet\n", filter_index->GetName());
return false;
}

return true;
}
Expand Down

0 comments on commit ea5a8ae

Please sign in to comment.