Merge bitcoin/bitcoin#35474: node: move index ownership to NodeContext
What changed, and why it matters
This is a code-cleanup change in Bitcoin Core that moves ownership of several optional indexes (used to look up transactions, block filters, and coin statistics) from global variables into the NodeContext object. The pull request description explicitly states behavior should be unchanged, and the diff shows a mechanical refactor: replacing global pointers with node.txindex, node.coin_stats_index, node.block_filter_indexes, etc., and passing a lookup callback to the peer manager instead of reading global state. There is no direct evidence in the commit of a security vulnerability being fixed or introduced.
No immediate security action required. Treat as a normal refactor review: verify that index startup/shutdown order and lifetime are preserved, that the custom deleter does not introduce use-after-free or double-delete, and that the getindexinfo output key-order change is acceptable. Regression testing of -txindex, -coinstatsindex, -txospenderindex, and block filter index RPC/REST/peer behavior is appropriate.
Security signals we found
Removal of global mutable state for indexes
Introduction of custom IndexDeleter to manage index lifetimes within NodeContext
PeerManager now uses an injected callback for block filter index lookup instead of a global function
No explicit security fix or vulnerability disclosure in commit message or diff
Evidence from the diff
The merge commit refactors index ownership in Bitcoin Core. It removes process-global unique_ptrs g_txindex, g_txospenderindex, g_coin_stats_index and the global std::map of block filter indexes, moving ownership into NodeContext members with a custom IndexDeleter to avoid circular includes. PeerManager::Options gains a get_block_filter_index callback so net_processing no longer depends on global state. RPC, REST, init, and test code are updated to retrieve indexes from NodeContext. The change is architectural: it reduces global mutable state and improves testability/isolation. No security bug is described or visible in the diff.
Changed components
src/node/context.hsrc/node/indexes.cppsrc/node/indexes.hsrc/init.cppsrc/net_processing.cppsrc/net_processing.hsrc/rpc/blockchain.cppsrc/rpc/mempool.cppsrc/rpc/node.cppsrc/rpc/rawtransaction.cppsrc/rpc/txoutproof.cppsrc/rest.cppsrc/index/blockfilterindex.cppsrc/index/blockfilterindex.hsrc/index/coinstatsindex.cppsrc/index/coinstatsindex.hsrc/index/txindex.cppsrc/index/txindex.hsrc/index/txospenderindex.cppsrc/index/txospenderindex.hInspect captured patch +207 / −201
### src/CMakeLists.txt
@@ -233,6 +233,7 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
node/database_args.cpp
node/eviction.cpp
node/interface_ui.cpp
+ node/indexes.cpp
node/interfaces.cpp
node/kernel_notifications.cpp
node/mempool_args.cpp
### src/index/blockfilterindex.cpp
@@ -27,11 +27,9 @@
#include <cerrno>
#include <exception>
-#include <map>
#include <optional>
#include <stdexcept>
#include <string>
-#include <tuple>
#include <utility>
#include <vector>
@@ -81,8 +79,6 @@ struct DBVal {
}; // namespace
-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", BlockFilterThreadName(filter_type))
@@ -441,34 +437,3 @@ bool BlockFilterIndex::LookupFilterHashRange(int start_height, const CBlockIndex
}
return true;
}
-
-BlockFilterIndex* GetBlockFilterIndex(BlockFilterType filter_type)
-{
- auto it = g_filter_indexes.find(filter_type);
- return it != g_filter_indexes.end() ? &it->second : nullptr;
-}
-
-void ForEachBlockFilterIndex(std::function<void (BlockFilterIndex&)> fn)
-{
- for (auto& entry : g_filter_indexes) fn(entry.second);
-}
-
-bool InitBlockFilterIndex(std::function<std::unique_ptr<interfaces::Chain>()> make_chain, BlockFilterType filter_type,
- size_t n_cache_size, bool f_memory, bool f_wipe)
-{
- auto result = g_filter_indexes.emplace(std::piecewise_construct,
- std::forward_as_tuple(filter_type),
- std::forward_as_tuple(make_chain(), filter_type,
- n_cache_size, f_memory, f_wipe));
- return result.second;
-}
-
-bool DestroyBlockFilterIndex(BlockFilterType filter_type)
-{
- return g_filter_indexes.erase(filter_type);
-}
-
-void DestroyAllBlockFilterIndexes()
-{
- g_filter_indexes.clear();
-}
### src/index/blockfilterindex.h
@@ -15,7 +15,6 @@
#include <cstddef>
#include <cstdint>
-#include <functional>
#include <memory>
#include <optional>
#include <unordered_map>
@@ -97,30 +96,4 @@ class BlockFilterIndex final : public BaseIndex
std::vector<uint256>& hashes_out) const;
};
-/**
- * Get a block filter index by type. Returns nullptr if index has not been initialized or was
- * already destroyed.
- */
-BlockFilterIndex* GetBlockFilterIndex(BlockFilterType filter_type);
-
-/** Iterate over all running block filter indexes, invoking fn on each. */
-void ForEachBlockFilterIndex(std::function<void (BlockFilterIndex&)> fn);
-
-/**
- * Initialize a block filter index for the given type if one does not already exist. Returns true if
- * a new index is created and false if one has already been initialized.
- */
-bool InitBlockFilterIndex(std::function<std::unique_ptr<interfaces::Chain>()> make_chain, BlockFilterType filter_type,
- size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
-
-/**
- * Destroy the block filter index with the given type. Returns false if no such index exists. This
- * just releases the allocated memory and closes the database connection, it does not delete the
- * index data.
- */
-bool DestroyBlockFilterIndex(BlockFilterType filter_type);
-
-/** Destroy all open block filter indexes. */
-void DestroyAllBlockFilterIndexes();
-
#endif // BITCOIN_INDEX_BLOCKFILTERINDEX_H
### src/index/coinstatsindex.cpp
@@ -84,8 +84,6 @@ struct DBVal {
};
}; // namespace
-std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
-
CoinStatsIndex::CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
: BaseIndex(std::move(chain), "coinstatsindex", "coinstatsidx")
{
### src/index/coinstatsindex.h
@@ -72,7 +72,4 @@ class CoinStatsIndex final : public BaseIndex
std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;
};
-/// The global UTXO set hash object.
-extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
-
#endif // BITCOIN_INDEX_COINSTATSINDEX_H
### src/index/txindex.cpp
@@ -41,8 +41,6 @@
#include <utility>
#include <vector>
-std::unique_ptr<TxIndex> g_txindex;
-
namespace {
SipHasher13UJ ReadOrCreateTxidHasher(CDBWrapper& db)
{
### src/index/txindex.h
@@ -66,7 +66,4 @@ class TxIndex final : public BaseIndex
std::optional<TxIndexResult> FindTx(const Txid& tx_hash) const;
};
-/// The global transaction index, used in GetTransaction. May be null.
-extern std::unique_ptr<TxIndex> g_txindex;
-
#endif // BITCOIN_INDEX_TXINDEX_H
### src/index/txospenderindex.cpp
@@ -41,8 +41,6 @@
// LevelDB key prefix. We only have one key for now but it will make it easier to add others if needed.
constexpr uint8_t DB_TXOSPENDERINDEX{'s'};
-std::unique_ptr<TxoSpenderIndex> g_txospenderindex;
-
struct DBKey {
uint64_t hash;
CDiskTxPos pos;
### src/index/txospenderindex.h
@@ -68,8 +68,4 @@ class TxoSpenderIndex final : public BaseIndex
util::Expected<std::optional<TxoSpender>, std::string> FindSpender(const COutPoint& txo) const;
};
-/// The global txo spender index. May be null.
-extern std::unique_ptr<TxoSpenderIndex> g_txospenderindex;
-
-
#endif // BITCOIN_INDEX_TXOSPENDERINDEX_H
### src/init.cpp
@@ -58,6 +58,7 @@
#include <node/chainstate.h>
#include <node/chainstatemanager_args.h>
#include <node/context.h>
+#include <node/indexes.h>
#include <node/interface_ui.h>
#include <node/kernel_notifications.h>
#include <node/mempool_args.h>
@@ -156,10 +157,12 @@ using node::DEFAULT_PERSIST_MEMPOOL;
using node::DEFAULT_PRINT_MODIFIED_FEE;
using node::DEFAULT_STOPATHEIGHT;
using node::DumpMempool;
+using node::GetBlockFilterIndex;
using node::ImportBlocks;
using node::KernelNotifications;
using node::LoadChainstate;
using node::LoadMempool;
+using node::MakeIndex;
using node::MempoolPath;
using node::NodeContext;
using node::ShouldPersistMempool;
@@ -388,11 +391,11 @@ void Shutdown(NodeContext& node)
// Stop and delete all indexes only after flushing background callbacks.
for (auto* index : node.indexes) index->Stop();
- if (g_txindex) g_txindex.reset();
- if (g_txospenderindex) g_txospenderindex.reset();
- if (g_coin_stats_index) g_coin_stats_index.reset();
- DestroyAllBlockFilterIndexes();
- node.indexes.clear(); // all instances are nullptr now
+ node.indexes.clear();
+ node.txindex.reset();
+ node.txospenderindex.reset();
+ node.coin_stats_index.reset();
+ node.block_filter_indexes.clear();
// Callbacks queued by this final chainstate flush will not run during shutdown
if (node.chainman) {
@@ -1683,6 +1686,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
PeerManager::Options peerman_opts{};
ApplyArgsManOptions(args, peerman_opts);
+ peerman_opts.get_block_filter_index = [&node](BlockFilterType filter_type) {
+ return GetBlockFilterIndex(node, filter_type);
+ };
{
// Read asmap file if configured or embedded asmap data and initialize
@@ -2008,23 +2014,24 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// ********************************************************* Step 8: start indexers
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
- g_txindex = std::make_unique<TxIndex>(interfaces::MakeChain(node), index_cache_sizes.tx_index, false, do_reindex);
- node.indexes.emplace_back(g_txindex.get());
+ node.txindex = MakeIndex<TxIndex>(interfaces::MakeChain(node), index_cache_sizes.tx_index, /*f_memory=*/false, do_reindex);
+ node.indexes.emplace_back(node.txindex.get());
}
if (args.GetBoolArg("-txospenderindex", DEFAULT_TXOSPENDERINDEX)) {
- g_txospenderindex = std::make_unique<TxoSpenderIndex>(interfaces::MakeChain(node), index_cache_sizes.txospender_index, false, do_reindex);
- node.indexes.emplace_back(g_txospenderindex.get());
+ node.txospenderindex = MakeIndex<TxoSpenderIndex>(interfaces::MakeChain(node), index_cache_sizes.txospender_index, /*f_memory=*/false, do_reindex);
+ node.indexes.emplace_back(node.txospenderindex.get());
}
for (const auto& filter_type : g_enabled_filter_types) {
- InitBlockFilterIndex([&]{ return interfaces::MakeChain(node); }, filter_type, index_cache_sizes.filter_index, false, do_reindex);
- node.indexes.emplace_back(GetBlockFilterIndex(filter_type));
+ auto& index{node.block_filter_indexes.emplace_back(
+ MakeIndex<BlockFilterIndex>(interfaces::MakeChain(node), filter_type, index_cache_sizes.filter_index, /*f_memory=*/false, do_reindex))};
+ node.indexes.emplace_back(index.get());
}
if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) {
- g_coin_stats_index = std::make_unique<CoinStatsIndex>(interfaces::MakeChain(node), /*cache_size=*/0, false, do_reindex);
- node.indexes.emplace_back(g_coin_stats_index.get());
+ node.coin_stats_index = MakeIndex<CoinStatsIndex>(interfaces::MakeChain(node), /*n_cache_size=*/0, /*f_memory=*/false, do_reindex);
+ node.indexes.emplace_back(node.coin_stats_index.get());
}
// Init indexes
### src/net_processing.cpp
@@ -3559,7 +3559,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
return false;
}
- filter_index = GetBlockFilterIndex(filter_type);
+ filter_index = m_opts.get_block_filter_index(filter_type);
if (!filter_index) {
LogDebug(BCLog::NET, "Filter index for supported type %s not found\n", BlockFilterTypeName(filter_type));
return false;
### src/net_processing.h
@@ -19,12 +19,15 @@
#include <atomic>
#include <chrono>
#include <cstdint>
+#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>
class AddrMan;
+class BlockFilterIndex;
+enum class BlockFilterType : uint8_t;
class CTxMemPool;
class ChainstateManager;
class BanMan;
@@ -110,6 +113,8 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
bool private_broadcast{DEFAULT_PRIVATE_BROADCAST};
//! Maximum per-second rate for sending transaction inventory to peers.
unsigned int tx_send_rate{DEFAULT_TX_SEND_RATE};
+ //! Return the running block filter index for a filter type, if enabled.
+ std::function<BlockFilterIndex*(BlockFilterType)> get_block_filter_index{[](BlockFilterType) { return nullptr; }};
};
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
### src/node/context.h
@@ -10,13 +10,16 @@
#include <functional>
#include <memory>
#include <thread>
+#include <utility>
#include <vector>
class ArgsManager;
class AddrMan;
class BanMan;
class BaseIndex;
+class BlockFilterIndex;
class CConnman;
+class CoinStatsIndex;
class FeeRateEstimatorManager;
class ValidationSignals;
class CScheduler;
@@ -26,6 +29,8 @@ class ECC_Context;
class NetGroupManager;
class PeerManager;
class TorController;
+class TxIndex;
+class TxoSpenderIndex;
namespace interfaces {
class Chain;
class ChainClient;
@@ -44,6 +49,23 @@ class BlockTemplateManager;
class KernelNotifications;
class Warnings;
+// A custom deleter lets NodeContext own indexes without node/context.cpp
+// including index headers. Index code includes node/context.h, so including
+// index headers there would create a circular dependency.
+struct IndexDeleter {
+ void operator()(BlockFilterIndex* index) const noexcept;
+ void operator()(CoinStatsIndex* index) const noexcept;
+ void operator()(TxIndex* index) const noexcept;
+ void operator()(TxoSpenderIndex* index) const noexcept;
+};
+
+//! Construct an index with the out-of-line deleter used by NodeContext.
+template <typename Index, typename... Args>
+std::unique_ptr<Index, IndexDeleter> MakeIndex(Args&&... args)
+{
+ return std::unique_ptr<Index, IndexDeleter>{new Index(std::forward<Args>(args)...)};
+}
+
//! NodeContext struct containing references to chain state and connection
//! state.
//!
@@ -74,7 +96,7 @@ struct NodeContext {
std::unique_ptr<ChainstateManager> chainman;
std::unique_ptr<BanMan> banman;
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
- std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct
+ std::vector<BaseIndex*> indexes; // raw pointers because memory is managed by index owner members below
std::unique_ptr<interfaces::Chain> chain;
//! List of all chain clients (wallet processes or other client) connected to node.
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
@@ -90,6 +112,12 @@ struct NodeContext {
std::atomic<int> exit_status{EXIT_SUCCESS};
//! Manages all the node warnings
std::unique_ptr<node::Warnings> warnings;
+ //! Destroy indexes while they can still unregister from validation_signals
+ //! and report fatal errors through exit_status and warnings.
+ std::vector<std::unique_ptr<BlockFilterIndex, IndexDeleter>> block_filter_indexes;
+ std::unique_ptr<TxIndex, IndexDeleter> txindex;
+ std::unique_ptr<TxoSpenderIndex, IndexDeleter> txospenderindex;
+ std::unique_ptr<CoinStatsIndex, IndexDeleter> coin_stats_index;
std::thread background_init_thread;
//! Declare default constructor and destructor that are not inline, so code
### src/node/indexes.cpp
@@ -0,0 +1,28 @@
+// Copyright (c) 2026-present The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <node/indexes.h>
+
+#include <index/blockfilterindex.h>
+#include <index/coinstatsindex.h>
+#include <index/txindex.h>
+#include <index/txospenderindex.h>
+#include <node/context.h>
+
+namespace node {
+
+void IndexDeleter::operator()(BlockFilterIndex* index) const noexcept { delete index; }
+void IndexDeleter::operator()(CoinStatsIndex* index) const noexcept { delete index; }
+void IndexDeleter::operator()(TxIndex* index) const noexcept { delete index; }
+void IndexDeleter::operator()(TxoSpenderIndex* index) const noexcept { delete index; }
+
+BlockFilterIndex* GetBlockFilterIndex(const NodeContext& node, BlockFilterType filter_type)
+{
+ for (const auto& index : node.block_filter_indexes) {
+ if (index->GetFilterType() == filter_type) return index.get();
+ }
+ return nullptr;
+}
+
+} // namespace node
### src/node/indexes.h
@@ -0,0 +1,23 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_NODE_INDEXES_H
+#define BITCOIN_NODE_INDEXES_H
+
+#include <cstdint>
+
+class BlockFilterIndex;
+enum class BlockFilterType : uint8_t;
+
+namespace node {
+struct NodeContext;
+
+/**
+ * Get a block filter index by type. Returns nullptr if index has not been initialized or was
+ * already destroyed.
+ */
+BlockFilterIndex* GetBlockFilterIndex(const NodeContext& node, BlockFilterType filter_type);
+} // namespace node
+
+#endif // BITCOIN_NODE_INDEXES_H
### src/node/interfaces.cpp
@@ -37,6 +37,7 @@
#include <node/blockstorage.h>
#include <node/coin.h>
#include <node/context.h>
+#include <node/indexes.h>
#include <node/interface_ui.h>
#include <node/kernel_notifications.h>
#include <node/miner.h>
@@ -582,11 +583,11 @@ class ChainImpl : public Chain
}
bool hasBlockFilterIndex(BlockFilterType filter_type) override
{
- return GetBlockFilterIndex(filter_type) != nullptr;
+ return GetBlockFilterIndex(m_node, filter_type) != nullptr;
}
std::optional<bool> blockFilterMatchesAny(BlockFilterType filter_type, const uint256& block_hash, const GCSFilter::ElementSet& filter_set) override
{
- const BlockFilterIndex* block_filter_index{GetBlockFilterIndex(filter_type)};
+ const BlockFilterIndex* block_filter_index{GetBlockFilterIndex(m_node, filter_type)};
if (!block_filter_index) return std::nullopt;
BlockFilter filter;
### src/node/transaction.cpp
@@ -142,14 +142,14 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
return TransactionError::OK;
}
-CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const Txid& hash, const BlockManager& blockman, uint256& hashBlock)
+CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const TxIndex* const txindex, const Txid& hash, const BlockManager& blockman, uint256& hashBlock)
{
if (mempool && !block_index) {
CTransactionRef ptx = mempool->get(hash);
if (ptx) return ptx;
}
- if (g_txindex) {
- if (auto result{g_txindex->FindTx(hash)}) {
+ if (txindex) {
+ if (auto result{txindex->FindTx(hash)}) {
if (!block_index || block_index->GetBlockHash() == result->block_hash) {
// Don't return the transaction if the provided block hash doesn't match.
// The case where a transaction appears in multiple blocks (e.g. reorgs or
### src/node/transaction.h
@@ -12,6 +12,7 @@
class CBlockIndex;
class CTxMemPool;
+class TxIndex;
namespace Consensus {
struct Params;
}
@@ -62,17 +63,18 @@ inline constexpr CAmount DEFAULT_MAX_BURN_AMOUNT{0};
/**
* Return transaction with a given hash.
* If mempool is provided and block_index is not provided, check it first for the tx.
- * If -txindex is available, check it next for the tx.
+ * If txindex is provided, check it next for the tx.
* Finally, if block_index is provided, check for tx by reading entire block from disk.
*
* @param[in] block_index The block to read from disk, or nullptr
* @param[in] mempool If provided, check mempool for tx
+ * @param[in] txindex If provided, check txindex for tx
* @param[in] hash The txid
* @param[in] blockman Used to access and read blocks from disk
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
* @returns The tx if found, otherwise nullptr
*/
-CTransactionRef GetTransaction(const CBlockIndex* block_index, const CTxMemPool* mempool, const Txid& hash, const BlockManager& blockman, uint256& hashBlock);
+CTransactionRef GetTransaction(const CBlockIndex* block_index, const CTxMemPool* mempool, const TxIndex* txindex, const Txid& hash, const BlockManager& blockman, uint256& hashBlock);
} // namespace node
#endif // BITCOIN_NODE_TRANSACTION_H
### src/rest.cpp
@@ -17,6 +17,7 @@
#include <index/txindex.h>
#include <node/blockstorage.h>
#include <node/context.h>
+#include <node/indexes.h>
#include <node/transaction.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
@@ -53,6 +54,7 @@
#include <utility>
#include <vector>
+using node::GetBlockFilterIndex;
using node::GetTransaction;
using node::NodeContext;
using util::SplitString;
@@ -577,7 +579,9 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
}
- BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
+ NodeContext* node = GetNodeContext(context, req);
+ if (!node) return false;
+ BlockFilterIndex* index = GetBlockFilterIndex(*node, filtertype);
if (!index) {
return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
}
@@ -685,7 +689,9 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s
return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
}
- BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
+ NodeContext* node = GetNodeContext(context, req);
+ if (!node) return false;
+ BlockFilterIndex* index = GetBlockFilterIndex(*node, filtertype);
if (!index) {
return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
}
@@ -897,14 +903,13 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
}
- if (g_txindex) {
- g_txindex->BlockUntilSyncedToCurrentChain();
- }
-
const NodeContext* const node = GetNodeContext(context, req);
if (!node) return false;
+ if (node->txindex) {
+ node->txindex->BlockUntilSyncedToCurrentChain();
+ }
uint256 hashBlock = uint256();
- const CTransactionRef tx{GetTransaction(/*block_index=*/nullptr, node->mempool.get(), *hash, node->chainman->m_blockman, hashBlock)};
+ const CTransactionRef tx{GetTransaction(/*block_index=*/nullptr, node->mempool.get(), node->txindex.get(), *hash, node->chainman->m_blockman, hashBlock)};
if (!tx) {
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
}
### src/rpc/blockchain.cpp
@@ -34,6 +34,7 @@
#include <node/block_template_manager.h>
#include <node/blockstorage.h>
#include <node/context.h>
+#include <node/indexes.h>
#include <node/utxo_snapshot.h>
#include <node/warnings.h>
#include <policy/feerate.h>
@@ -102,6 +103,7 @@ using kernel::CoinStatsHashType;
using interfaces::BlockRef;
using node::BlockManager;
+using node::GetBlockFilterIndex;
using node::NodeContext;
using node::SnapshotMetadata;
using util::MakeUnorderedList;
@@ -1012,21 +1014,21 @@ CoinStatsHashType ParseHashType(std::string_view hash_type_input)
/**
* Calculate statistics about the unspent transaction output set
*
- * @param[in] index_requested Signals if the coinstatsindex should be used (when available).
+ * @param[in] coin_stats_index The coinstatsindex to use, or nullptr to compute the statistics from the view.
*/
static std::optional<kernel::CCoinsStats> GetUTXOStats(const CCoinsViewDB& view, node::BlockManager& blockman,
+ const CoinStatsIndex* coin_stats_index,
kernel::CoinStatsHashType hash_type,
const std::function<void()>& interruption_point = {},
- const CBlockIndex* pindex = nullptr,
- bool index_requested = true)
+ const CBlockIndex* pindex = nullptr)
{
- // Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested
- if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
+ // Use CoinStatsIndex if it is provided and a hash_type of MuHash or None was requested.
+ if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && coin_stats_index) {
if (pindex) {
- return g_coin_stats_index->LookUpStats(*pindex);
+ return coin_stats_index->LookUpStats(*pindex);
} else {
CBlockIndex& block_index = *CHECK_NONFATAL(WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view.GetBestBlock())));
- return g_coin_stats_index->LookUpStats(block_index);
+ return coin_stats_index->LookUpStats(block_index);
}
}
@@ -1101,6 +1103,7 @@ static RPCMethod gettxoutsetinfo()
const bool index_requested{self.Arg<bool>("use_index")};
NodeContext& node = EnsureAnyNodeContext(request.context);
+ const CoinStatsIndex* const coin_stats_index{index_requested ? node.coin_stats_index.get() : nullptr};
ChainstateManager& chainman = EnsureChainman(node);
Chainstate& active_chainstate = chainman.ActiveChainstate();
active_chainstate.ForceFlushStateToDisk(/*wipe_cache=*/false);
@@ -1110,7 +1113,7 @@ static RPCMethod gettxoutsetinfo()
const CBlockIndex* pindex{nullptr};
if (!request.params[1].isNull()) {
- if (!g_coin_stats_index) {
+ if (!node.coin_stats_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Querying specific block heights requires coinstatsindex");
}
@@ -1124,9 +1127,9 @@ static RPCMethod gettxoutsetinfo()
pindex = ParseHashOrHeight(request.params[1], chainman);
}
- if (index_requested && g_coin_stats_index) {
- if (!g_coin_stats_index->BlockUntilSyncedToCurrentChain()) {
- const IndexSummary summary{g_coin_stats_index->GetSummary()};
+ if (coin_stats_index) {
+ if (!coin_stats_index->BlockUntilSyncedToCurrentChain()) {
+ const IndexSummary summary{coin_stats_index->GetSummary()};
// If a specific block was requested and the index has already synced past that height, we can return the
// data already even though the index is not fully synced yet.
@@ -1136,7 +1139,7 @@ static RPCMethod gettxoutsetinfo()
}
}
- const std::optional<CCoinsStats> maybe_stats = GetUTXOStats(coins_view, blockman, hash_type, node.rpc_interruption_point, pindex, index_requested);
+ const std::optional<CCoinsStats> maybe_stats = GetUTXOStats(coins_view, blockman, coin_stats_index, hash_type, node.rpc_interruption_point, pindex);
if (maybe_stats.has_value()) {
const CCoinsStats& stats = maybe_stats.value();
ret.pushKV("height", stats.nHeight);
@@ -1158,7 +1161,7 @@ static RPCMethod gettxoutsetinfo()
CCoinsStats prev_stats{};
if (stats.nHeight > 0) {
const CBlockIndex& block_index = *CHECK_NONFATAL(WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(stats.hashBlock)));
- const std::optional<CCoinsStats> maybe_prev_stats = GetUTXOStats(coins_view, blockman, hash_type, node.rpc_interruption_point, block_index.pprev, index_requested);
+ const std::optional<CCoinsStats> maybe_prev_stats = GetUTXOStats(coins_view, blockman, coin_stats_index, hash_type, node.rpc_interruption_point, block_index.pprev);
if (!maybe_prev_stats) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
}
@@ -2642,12 +2645,12 @@ static RPCMethod scanblocks()
UniValue options{request.params[5].isNull() ? UniValue::VOBJ : request.params[5]};
bool filter_false_positives{options.exists("filter_false_positives") ? options["filter_false_positives"].get_bool() : false};
- BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
+ NodeContext& node = EnsureAnyNodeContext(request.context);
+ BlockFilterIndex* index = GetBlockFilterIndex(node, filtertype);
if (!index) {
throw JSONRPCError(RPC_MISC_ERROR, tfm::format("Index is not enabled for filtertype %s", filtertype_name));
}
- NodeContext& node = EnsureAnyNodeContext(request.context);
ChainstateManager& chainman = EnsureChainman(node);
// set the start-height
@@ -3010,15 +3013,16 @@ static RPCMethod getblockfilter()
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unknown filtertype");
}
- BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
+ NodeContext& node = EnsureAnyNodeContext(request.context);
+ BlockFilterIndex* index = GetBlockFilterIndex(node, filtertype);
if (!index) {
throw JSONRPCError(RPC_MISC_ERROR, tfm::format("Index is not enabled for filtertype %s", filtertype_name));
}
const CBlockIndex* block_index;
bool block_was_connected;
{
- ChainstateManager& chainman = EnsureAnyChainman(request.context);
+ ChainstateManager& chainman = EnsureChainman(node);
LOCK(cs_main);
block_index = chainman.m_blockman.LookupBlockIndex(block_hash);
if (!block_index) {
@@ -3342,6 +3346,7 @@ UniValue CreateRolledBackUTXOSnapshot(
LogInfo("Rollback complete. Computing UTXO statistics for created txoutset dump.");
std::optional<CCoinsStats> maybe_stats = GetUTXOStats(*temp_db,
chainstate.m_blockman,
+ /*coin_stats_index=*/nullptr,
CoinStatsHashType::HASH_SERIALIZED,
node.rpc_interruption_point);
@@ -3388,7 +3393,7 @@ PrepareUTXOSnapshot(
chainstate.ForceFlushStateToDisk(/*wipe_cache=*/false);
- maybe_stats = GetUTXOStats(chainstate.CoinsDB(), chainstate.m_blockman, CoinStatsHashType::HASH_SERIALIZED, interruption_point);
+ maybe_stats = GetUTXOStats(chainstate.CoinsDB(), chainstate.m_blockman, /*coin_stats_index=*/nullptr, CoinStatsHashType::HASH_SERIALIZED, interruption_point);
if (!maybe_stats) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
}
### src/rpc/mempool.cpp
@@ -15,6 +15,7 @@
#include <net_processing.h>
#include <netaddress.h>
#include <netbase.h>
+#include <node/context.h>
#include <node/mempool_persist.h>
#include <node/mempool_persist_args.h>
#include <node/transaction.h>
@@ -63,10 +64,6 @@
#include <utility>
#include <vector>
-namespace node {
-struct NodeContext;
-} // namespace node
-
using node::DumpMempool;
using node::DEFAULT_MAX_BURN_AMOUNT;
@@ -1004,7 +1001,8 @@ static RPCMethod gettxspendingprevout()
{"return_spending_tx", UniValueType(UniValue::VBOOL)},
}, /*fAllowNull=*/true, /*fStrict=*/true);
- const bool mempool_only{options.exists("mempool_only") ? options["mempool_only"].get_bool() : !g_txospenderindex};
+ const NodeContext& node{EnsureAnyNodeContext(request.context)};
+ const bool mempool_only{options.exists("mempool_only") ? options["mempool_only"].get_bool() : !node.txospenderindex};
const bool return_spending_tx{options.exists("return_spending_tx") ? options["return_spending_tx"].get_bool() : false};
// Worklist of outpoints to resolve
@@ -1048,7 +1046,7 @@ static RPCMethod gettxspendingprevout()
std::vector<Entry> unresolved;
unresolved.reserve(prevouts_to_process.size());
{
- const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
+ const CTxMemPool& mempool = EnsureMemPool(node);
LOCK(mempool.cs);
// Make the result if the spending tx appears in the mempool or this is a mempool_only request
@@ -1066,12 +1064,12 @@ static RPCMethod gettxspendingprevout()
}
// mempool_only requests resolve every outpoint above, so only other requests reach the index.
- if (!unresolved.empty() && (!g_txospenderindex || !g_txospenderindex->BlockUntilSyncedToCurrentChain())) {
+ if (!unresolved.empty() && (!node.txospenderindex || !node.txospenderindex->BlockUntilSyncedToCurrentChain())) {
throw JSONRPCError(RPC_MISC_ERROR, "Mempool lacks a relevant spend, and txospenderindex is unavailable.");
}
for (const auto& prevout : unresolved) {
- const auto spender{g_txospenderindex->FindSpender(prevout.outpoint)};
+ const auto spender{node.txospenderindex->FindSpender(prevout.outpoint)};
if (!spender) {
throw JSONRPCError(RPC_MISC_ERROR, spender.error());
}
### src/rpc/node.cpp
@@ -9,10 +9,6 @@
#include <chainparams.h>
#include <index/base.h>
-#include <index/blockfilterindex.h>
-#include <index/coinstatsindex.h>
-#include <index/txindex.h>
-#include <index/txospenderindex.h>
#include <interfaces/chain.h>
#include <interfaces/echo.h>
#include <interfaces/init.h>
@@ -398,23 +394,12 @@ static RPCMethod getindexinfo()
{
UniValue result(UniValue::VOBJ);
const std::string index_name{self.MaybeArg<std::string_view>("index_name").value_or("")};
+ const NodeContext& node{EnsureAnyNodeContext(request.context)};
- if (g_txindex) {
- result.pushKVs(SummaryToJSON(g_txindex->GetSummary(), index_name));
+ for (const auto* index : node.indexes) {
+ result.pushKVs(SummaryToJSON(index->GetSummary(), index_name));
}
- if (g_coin_stats_index) {
- result.pushKVs(SummaryToJSON(g_coin_stats_index->GetSummary(), index_name));
- }
-
- if (g_txospenderindex) {
- result.pushKVs(SummaryToJSON(g_txospenderindex->GetSummary(), index_name));
- }
-
- ForEachBlockFilterIndex([&result, &index_name](const BlockFilterIndex& index) {
- result.pushKVs(SummaryToJSON(index.GetSummary(), index_name));
- });
-
return result;
},
};
### src/rpc/rawtransaction.cpp
@@ -161,8 +161,8 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std
}
PartiallySignedTransaction psbtx = *psbt_res;
- if (g_txindex) g_txindex->BlockUntilSyncedToCurrentChain();
const NodeContext& node = EnsureAnyNodeContext(context);
+ if (node.txindex) node.txindex->BlockUntilSyncedToCurrentChain();
// If we can't find the corresponding full transaction for all of our inputs,
// this will be used to find just the utxos for the segwit inputs for which
@@ -176,7 +176,7 @@ PartiallySignedTransaction ProcessPSBT(const std::string& psbt_string, const std
if (psbt_input.non_witness_utxo) continue;
uint256 block_hash;
- CTransactionRef tx{GetTransaction(/*block_index=*/nullptr, node.mempool.get(), psbt_input.prev_txid, node.chainman->m_blockman, block_hash)};
+ CTransactionRef tx{GetTransaction(/*block_index=*/nullptr, node.mempool.get(), node.txindex.get(), psbt_input.prev_txid, node.chainman->m_blockman, block_hash)};
if (tx) {
psbt_input.non_witness_utxo = tx;
} else {
@@ -315,14 +315,14 @@ static RPCMethod getrawtransaction()
}
bool f_txindex_ready = false;
- if (g_txindex && !blockindex) {
- f_txindex_ready = g_txindex->BlockUntilSyncedToCurrentChain();
+ if (node.txindex && !blockindex) {
+ f_txindex_ready = node.txindex->BlockUntilSyncedToCurrentChain();
}
uint256 hash_block;
CTransactionRef tx;
try {
- tx = GetTransaction(blockindex, node.mempool.get(), txid, chainman.m_blockman, hash_block);
+ tx = GetTransaction(blockindex, node.mempool.get(), node.txindex.get(), txid, chainman.m_blockman, hash_block);
} catch (const std::runtime_error&) {
if (blockindex) WITH_LOCK(::cs_main, CheckBlockDataAvailability(chainman.m_blockman, *blockindex, /*check_for_undo=*/false));
throw;
@@ -331,7 +331,7 @@ static RPCMethod getrawtransaction()
std::string errmsg;
if (blockindex) {
errmsg = "No such transaction found in the provided block";
- } else if (!g_txindex) {
+ } else if (!node.txindex) {
errmsg = "No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries";
} else if (!f_txindex_ready) {
errmsg = "No such mempool transaction. Blockchain transactions are still in the process of being indexed";
### src/rpc/txoutproof.cpp
@@ -11,6 +11,7 @@
#include <index/txindex.h>
#include <merkleblock.h>
#include <node/blockstorage.h>
+#include <node/context.h>
#include <node/transaction.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
@@ -34,6 +35,7 @@
#include <vector>
using node::GetTransaction;
+using node::NodeContext;
static RPCMethod gettxoutproof()
{
@@ -72,7 +74,8 @@ static RPCMethod gettxoutproof()
const CBlockIndex* pblockindex = nullptr;
uint256 hashBlock;
- ChainstateManager& chainman = EnsureAnyChainman(request.context);
+ NodeContext& node = EnsureAnyNodeContext(request.context);
+ ChainstateManager& chainman = EnsureChainman(node);
if (!request.params[1].isNull()) {
LOCK(cs_main);
hashBlock = ParseHashV(request.params[1], "blockhash");
@@ -96,12 +99,12 @@ static RPCMethod gettxoutproof()
// Allow txindex to catch up if we need to query it and before we acquire cs_main.
- if (g_txindex && !pblockindex) {
- g_txindex->BlockUntilSyncedToCurrentChain();
+ if (node.txindex && !pblockindex) {
+ node.txindex->BlockUntilSyncedToCurrentChain();
}
if (pblockindex == nullptr) {
- const CTransactionRef tx = GetTransaction(/*block_index=*/nullptr, /*mempool=*/nullptr, *setTxids.begin(), chainman.m_blockman, hashBlock);
+ const CTransactionRef tx = GetTransaction(/*block_index=*/nullptr, /*mempool=*/nullptr, node.txindex.get(), *setTxids.begin(), chainman.m_blockman, hashBlock);
if (!tx || hashBlock.IsNull()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
}
### src/test/blockfilter_index_tests.cpp
@@ -9,6 +9,8 @@
#include <interfaces/chain.h>
#include <key.h>
#include <node/blockstorage.h>
+#include <node/context.h>
+#include <node/indexes.h>
#include <primitives/block.h>
#include <script/script.h>
#include <sync.h>
@@ -227,41 +229,19 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
StopIndex(filter_index, m_node);
}
-BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup)
+BOOST_FIXTURE_TEST_CASE(blockfilter_index_lookup, BasicTestingSetup)
{
- BlockFilterIndex* filter_index;
+ BOOST_CHECK(node::GetBlockFilterIndex(m_node, BlockFilterType::BASIC) == nullptr);
- filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
- BOOST_CHECK(filter_index == nullptr);
+ m_node.block_filter_indexes.emplace_back(
+ node::MakeIndex<BlockFilterIndex>(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true));
- BOOST_CHECK(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, true, false));
-
- filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
- BOOST_CHECK(filter_index != nullptr);
+ BlockFilterIndex* filter_index{node::GetBlockFilterIndex(m_node, BlockFilterType::BASIC)};
+ BOOST_REQUIRE(filter_index != nullptr);
BOOST_CHECK(filter_index->GetFilterType() == BlockFilterType::BASIC);
- // Initialize returns false if index already exists.
- BOOST_CHECK(!InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, true, false));
-
- int iter_count = 0;
- ForEachBlockFilterIndex([&iter_count](BlockFilterIndex& _index) { iter_count++; });
- BOOST_CHECK_EQUAL(iter_count, 1);
-
- BOOST_CHECK(DestroyBlockFilterIndex(BlockFilterType::BASIC));
-
- // Destroy returns false because index was already destroyed.
- BOOST_CHECK(!DestroyBlockFilterIndex(BlockFilterType::BASIC));
-
- filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
- BOOST_CHECK(filter_index == nullptr);
-
- // Reinitialize index.
- BOOST_CHECK(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, true, false));
-
- DestroyAllBlockFilterIndexes();
-
- filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
- BOOST_CHECK(filter_index == nullptr);
+ m_node.block_filter_indexes.clear();
+ BOOST_CHECK(node::GetBlockFilterIndex(m_node, BlockFilterType::BASIC) == nullptr);
}
BOOST_AUTO_TEST_SUITE_END()
### src/test/fuzz/process_message.cpp
@@ -4,9 +4,11 @@
#include <addrman.h>
#include <banman.h>
+#include <blockfilter.h>
#include <kernel/chainparams.h>
#include <net.h>
#include <net_processing.h>
+#include <node/indexes.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <protocol.h>
@@ -95,6 +97,9 @@ FUZZ_TARGET(process_message, .init = initialize_process_message)
PeerManager::Options{
.reconcile_txs = true,
.deterministic_rng = true,
+ .get_block_filter_index = [&node](BlockFilterType filter_type) {
+ return node::GetBlockFilterIndex(node, filter_type);
+ },
});
connman.SetMsgProc(node.peerman.get());
### src/test/fuzz/process_messages.cpp
@@ -4,9 +4,11 @@
#include <addrman.h>
#include <banman.h>
+#include <blockfilter.h>
#include <kernel/chainparams.h>
#include <net.h>
#include <net_processing.h>
+#include <node/indexes.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <protocol.h>
@@ -87,6 +89,9 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages)
PeerManager::Options{
.reconcile_txs = true,
.deterministic_rng = true,
+ .get_block_filter_index = [&node](BlockFilterType filter_type) {
+ return node::GetBlockFilterIndex(node, filter_type);
+ },
});
connman.SetMsgProc(node.peerman.get());
connman.SetAddrman(*node.addrman);
### src/test/util/setup_common.cpp
@@ -30,6 +30,7 @@
#include <node/blockstorage.h>
#include <node/chainstate.h>
#include <node/context.h>
+#include <node/indexes.h>
#include <node/kernel_notifications.h>
#include <node/miner.h>
#include <node/mining_args.h>
@@ -346,7 +347,7 @@ ChainTestingSetup::~ChainTestingSetup()
{
if (m_node.scheduler) m_node.scheduler->stop();
if (m_node.validation_signals) m_node.validation_signals->FlushBackgroundCallbacks();
- DestroyAllBlockFilterIndexes();
+ m_node.block_filter_indexes.clear();
m_node.block_template_manager.reset();
m_node.connman.reset();
m_node.banman.reset();
@@ -409,6 +410,9 @@ TestingSetup::TestingSetup(
PeerManager::Options peerman_opts;
ApplyArgsManOptions(*m_node.args, peerman_opts);
peerman_opts.deterministic_rng = true;
+ peerman_opts.get_block_filter_index = [this](BlockFilterType filter_type) {
+ return node::GetBlockFilterIndex(m_node, filter_type);
+ };
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
m_node.banman.get(), *m_node.chainman,
*m_node.mempool, *m_node.warnings,
### src/test/util/validation.cpp
@@ -115,7 +115,7 @@ std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup&
{
node_clock.set(setup.m_node.chainman->GetParams().GenesisBlock().Time());
- DestroyAllBlockFilterIndexes();
+ setup.m_node.block_filter_indexes.clear();
bilingual_str error{};
setup.m_node.block_template_manager.reset();
@@ -142,8 +142,8 @@ std::vector<std::pair<COutPoint, CAmount>> ResetChainmanAndMempool(TestingSetup&
}
if (opts.init_block_filter_basic) {
- Assert(InitBlockFilterIndex([&] { return interfaces::MakeChain(setup.m_node); }, BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true, /*f_wipe=*/true));
- auto& index = *Assert(GetBlockFilterIndex(BlockFilterType::BASIC));
+ auto& index{*setup.m_node.block_filter_indexes.emplace_back(
+ node::MakeIndex<BlockFilterIndex>(interfaces::MakeChain(setup.m_node), BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true, /*f_wipe=*/true))};
Assert(index.Init());
index.Sync();
// The index serves the static setup chain only. Leaving it registered
### src/wallet/test/rescan_tests.cpp
@@ -7,6 +7,7 @@
#include <index/blockfilterindex.h>
#include <interfaces/chain.h>
#include <node/blockstorage.h>
+#include <node/context.h>
#include <test/util/common.h>
#include <test/util/logging.h>
#include <test/util/setup_common.h>
@@ -163,8 +164,8 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions_reorged_block, TestChain100Setup)
{
- BOOST_REQUIRE(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true));
- BlockFilterIndex& filter_index{*Assert(GetBlockFilterIndex(BlockFilterType::BASIC))};
+ BlockFilterIndex& filter_index{*m_node.block_filter_indexes.emplace_back(
+ node::MakeIndex<BlockFilterIndex>(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true))};
BOOST_REQUIRE(filter_index.Init());
filter_index.Sync();
@@ -258,7 +259,6 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions_reorged_block, TestChain100
}
StopIndex(filter_index, m_node);
- BOOST_REQUIRE(DestroyBlockFilterIndex(BlockFilterType::BASIC));
}
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions_abort, TestChain100Setup)
@@ -506,8 +506,8 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions_missing_filter, TestChain10
// Enable the block filter index but do not sync it: no filters are
// available, so the scan must inspect every block rather than treat
// the missing filters as misses and skip blocks.
- BOOST_REQUIRE(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true));
- BlockFilterIndex& filter_index{*Assert(GetBlockFilterIndex(BlockFilterType::BASIC))};
+ BlockFilterIndex& filter_index{*m_node.block_filter_indexes.emplace_back(
+ node::MakeIndex<BlockFilterIndex>(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1_MiB, /*f_memory=*/true))};
BOOST_REQUIRE(filter_index.Init());
{
@@ -545,7 +545,6 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions_missing_filter, TestChain10
}
StopIndex(filter_index, m_node);
- BOOST_REQUIRE(DestroyBlockFilterIndex(BlockFilterType::BASIC));
}
//! Test the rescan that loading a wallet performs when the wallet is behindWhy this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.