mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-15 18:10:26 +01:00
indexes, refactor: Pass Chain interface instead of CChainState class to indexes
Passing abstract Chain interface will let indexes run in separate processes. This commit does not change behavior in any way.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <consensus/merkle.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/miner.h>
|
||||
#include <pow.h>
|
||||
#include <script/standard.h>
|
||||
@@ -110,7 +111,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
{
|
||||
BlockFilterIndex filter_index(BlockFilterType::BASIC, 1 << 20, true);
|
||||
BlockFilterIndex filter_index(interfaces::MakeChain(m_node), BlockFilterType::BASIC, 1 << 20, true);
|
||||
|
||||
uint256 last_header;
|
||||
|
||||
@@ -137,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
|
||||
// BlockUntilSyncedToCurrentChain should return false before index is started.
|
||||
BOOST_CHECK(!filter_index.BlockUntilSyncedToCurrentChain());
|
||||
|
||||
BOOST_REQUIRE(filter_index.Start(m_node.chainman->ActiveChainstate()));
|
||||
BOOST_REQUIRE(filter_index.Start());
|
||||
|
||||
// Allow filter index to catch up with the block index.
|
||||
constexpr int64_t timeout_ms = 10 * 1000;
|
||||
@@ -279,14 +280,14 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup)
|
||||
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
|
||||
BOOST_CHECK(filter_index == nullptr);
|
||||
|
||||
BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
BOOST_CHECK(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
|
||||
filter_index = GetBlockFilterIndex(BlockFilterType::BASIC);
|
||||
BOOST_CHECK(filter_index != nullptr);
|
||||
BOOST_CHECK(filter_index->GetFilterType() == BlockFilterType::BASIC);
|
||||
|
||||
// Initialize returns false if index already exists.
|
||||
BOOST_CHECK(!InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
BOOST_CHECK(!InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
|
||||
int iter_count = 0;
|
||||
ForEachBlockFilterIndex([&iter_count](BlockFilterIndex& _index) { iter_count++; });
|
||||
@@ -301,7 +302,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_init_destroy, BasicTestingSetup)
|
||||
BOOST_CHECK(filter_index == nullptr);
|
||||
|
||||
// Reinitialize index.
|
||||
BOOST_CHECK(InitBlockFilterIndex(BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
BOOST_CHECK(InitBlockFilterIndex([&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1 << 20, true, false));
|
||||
|
||||
DestroyAllBlockFilterIndexes();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <index/coinstatsindex.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/validation.h>
|
||||
#include <util/time.h>
|
||||
@@ -31,7 +32,7 @@ static void IndexWaitSynced(BaseIndex& index)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
|
||||
{
|
||||
CoinStatsIndex coin_stats_index{1 << 20, true};
|
||||
CoinStatsIndex coin_stats_index{interfaces::MakeChain(m_node), 1 << 20, true};
|
||||
|
||||
const CBlockIndex* block_index;
|
||||
{
|
||||
@@ -46,7 +47,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
|
||||
// is started.
|
||||
BOOST_CHECK(!coin_stats_index.BlockUntilSyncedToCurrentChain());
|
||||
|
||||
BOOST_REQUIRE(coin_stats_index.Start(m_node.chainman->ActiveChainstate()));
|
||||
BOOST_REQUIRE(coin_stats_index.Start());
|
||||
|
||||
IndexWaitSynced(coin_stats_index);
|
||||
|
||||
@@ -90,8 +91,8 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup)
|
||||
CChainState& chainstate = Assert(m_node.chainman)->ActiveChainstate();
|
||||
const CChainParams& params = Params();
|
||||
{
|
||||
CoinStatsIndex index{1 << 20};
|
||||
BOOST_REQUIRE(index.Start(chainstate));
|
||||
CoinStatsIndex index{interfaces::MakeChain(m_node), 1 << 20};
|
||||
BOOST_REQUIRE(index.Start());
|
||||
IndexWaitSynced(index);
|
||||
std::shared_ptr<const CBlock> new_block;
|
||||
CBlockIndex* new_block_index = nullptr;
|
||||
@@ -116,9 +117,9 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_unclean_shutdown, TestChain100Setup)
|
||||
}
|
||||
|
||||
{
|
||||
CoinStatsIndex index{1 << 20};
|
||||
CoinStatsIndex index{interfaces::MakeChain(m_node), 1 << 20};
|
||||
// Make sure the index can be loaded.
|
||||
BOOST_REQUIRE(index.Start(chainstate));
|
||||
BOOST_REQUIRE(index.Start());
|
||||
index.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <index/txindex.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <script/standard.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/time.h>
|
||||
@@ -15,7 +16,7 @@ BOOST_AUTO_TEST_SUITE(txindex_tests)
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
||||
{
|
||||
TxIndex txindex(1 << 20, true);
|
||||
TxIndex txindex(interfaces::MakeChain(m_node), 1 << 20, true);
|
||||
|
||||
CTransactionRef tx_disk;
|
||||
uint256 block_hash;
|
||||
@@ -28,7 +29,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
||||
// BlockUntilSyncedToCurrentChain should return false before txindex is started.
|
||||
BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain());
|
||||
|
||||
BOOST_REQUIRE(txindex.Start(m_node.chainman->ActiveChainstate()));
|
||||
BOOST_REQUIRE(txindex.Start());
|
||||
|
||||
// Allow tx index to catch up with the block index.
|
||||
constexpr int64_t timeout_ms = 10 * 1000;
|
||||
|
||||
Reference in New Issue
Block a user