mirror of https://github.com/bitcoin/bitcoin.git
txindex: enable parallel sync
This commit is contained in:
parent
bfb7bca893
commit
e58d84988e
|
@ -29,6 +29,10 @@ protected:
|
||||||
|
|
||||||
BaseIndex::DB& GetDB() const override;
|
BaseIndex::DB& GetDB() const override;
|
||||||
|
|
||||||
|
std::any CustomProcessBlock(const interfaces::BlockInfo& block) override {
|
||||||
|
return CustomAppend(block);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constructs the index, which becomes available to be queried.
|
/// Constructs the index, which becomes available to be queried.
|
||||||
explicit TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
|
explicit TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
|
||||||
|
@ -36,6 +40,8 @@ public:
|
||||||
// Destructor is declared because this class contains a unique_ptr to an incomplete type.
|
// Destructor is declared because this class contains a unique_ptr to an incomplete type.
|
||||||
virtual ~TxIndex() override;
|
virtual ~TxIndex() override;
|
||||||
|
|
||||||
|
bool AllowParallelSync() override { return true; }
|
||||||
|
|
||||||
/// Look up a transaction by hash.
|
/// Look up a transaction by hash.
|
||||||
///
|
///
|
||||||
/// @param[in] tx_hash The hash of the transaction to be returned.
|
/// @param[in] tx_hash The hash of the transaction to be returned.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <index/txindex.h>
|
#include <index/txindex.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
#include <util/threadpool.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
@ -73,4 +74,45 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
||||||
txindex.Stop();
|
txindex.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(txindex_parallel_initial_sync, TestChain100Setup)
|
||||||
|
{
|
||||||
|
int tip_height = 100; // pre-mined blocks
|
||||||
|
const uint16_t MINE_BLOCKS = 650;
|
||||||
|
for (int round = 0; round < 2; round++) { // two rounds to test sync from genesis and from a higher block
|
||||||
|
// Generate blocks
|
||||||
|
mineBlocks(MINE_BLOCKS);
|
||||||
|
const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_node.chainman->ActiveChain().Tip());
|
||||||
|
BOOST_REQUIRE(tip->nHeight == MINE_BLOCKS + tip_height);
|
||||||
|
tip_height = tip->nHeight;
|
||||||
|
|
||||||
|
// Init and start index
|
||||||
|
TxIndex txindex(interfaces::MakeChain(m_node), 1 << 20, /*f_memory=*/false);
|
||||||
|
BOOST_REQUIRE(txindex.Init());
|
||||||
|
ThreadPool thread_pool("txindex");
|
||||||
|
thread_pool.Start(2);
|
||||||
|
txindex.SetThreadPool(thread_pool);
|
||||||
|
txindex.SetBlocksPerWorker(200);
|
||||||
|
|
||||||
|
BOOST_CHECK(!txindex.BlockUntilSyncedToCurrentChain());
|
||||||
|
txindex.Sync();
|
||||||
|
const auto& summary{txindex.GetSummary()};
|
||||||
|
BOOST_CHECK(summary.synced);
|
||||||
|
BOOST_CHECK_EQUAL(summary.best_block_height, tip_height);
|
||||||
|
|
||||||
|
// Check that txindex has all txs that were in the chain before it started.
|
||||||
|
CTransactionRef tx_disk;
|
||||||
|
uint256 block_hash;
|
||||||
|
for (const auto& txn : m_coinbase_txns) {
|
||||||
|
if (!txindex.FindTx(txn->GetHash(), block_hash, tx_disk)) {
|
||||||
|
BOOST_ERROR("FindTx failed");
|
||||||
|
} else if (tx_disk->GetHash() != txn->GetHash()) {
|
||||||
|
BOOST_ERROR("Read incorrect tx");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
txindex.Interrupt();
|
||||||
|
txindex.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Reference in New Issue