Skip to content

Commit 5488ce9

Browse files
jimpojnewbery
authored andcommitted
[net processing] Synchronize cfilter request handling with block filter 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.
1 parent e8f40bb commit 5488ce9

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/index/base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class BaseIndex : public CValidationInterface
8484

8585
virtual DB& GetDB() const = 0;
8686

87-
/// Get the name of the index for display in logs.
88-
virtual const char* GetName() const = 0;
89-
9087
public:
9188
/// Destructor interrupts sync thread if running and blocks until it exits.
9289
virtual ~BaseIndex();
9390

91+
/// Get the name of the index for display in logs.
92+
virtual const char* GetName() const = 0;
93+
9494
/// Returns whether index has completed the initial sync with the active chain.
9595
/// After returning true once, this function will return true on all subsequent calls.
9696
bool IsSynced() const { return m_synced; }

src/index/blockfilterindex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class BlockFilterIndex final : public BaseIndex
4747

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

50-
const char* GetName() const override { return m_name.c_str(); }
51-
5250
public:
5351
/** Constructs the index, which becomes available to be queried. */
5452
explicit BlockFilterIndex(BlockFilterType filter_type,
5553
size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
5654

55+
const char* GetName() const override { return m_name.c_str(); }
56+
5757
BlockFilterType GetFilterType() const { return m_filter_type; }
5858

5959
/** Get a single filter by block. */

src/index/txindex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class TxIndex final : public BaseIndex
3030

3131
BaseIndex::DB& GetDB() const override;
3232

33-
const char* GetName() const override { return "txindex"; }
34-
3533
public:
3634
/// Constructs the index, which becomes available to be queried.
3735
explicit TxIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
3836

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

40+
const char* GetName() const override { return "txindex"; }
41+
4242
/// Look up a transaction by hash.
4343
///
4444
/// @param[in] tx_hash The hash of the transaction to be returned.

src/net_processing.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,10 @@ static bool PrepareBlockFilterRequest(CNode* pfrom, const CChainParams& chain_pa
20352035
LogPrint(BCLog::NET, "Filter index for supported type %s not found\n", BlockFilterTypeName(filter_type));
20362036
return false;
20372037
}
2038+
if (!filter_index->BlockUntilSyncedToCurrentChain()) {
2039+
LogPrint(BCLog::NET, "%s is not ready yet\n", filter_index->GetName());
2040+
return false;
2041+
}
20382042

20392043
return true;
20402044
}

0 commit comments

Comments
 (0)