diff options
Diffstat (limited to 'src/test/util/setup_common.cpp')
-rw-r--r-- | src/test/util/setup_common.cpp | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index d9fff85bf5..74b055ee45 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -4,6 +4,8 @@ #include <test/util/setup_common.h> +#include <kernel/validation_cache_sizes.h> + #include <addrman.h> #include <banman.h> #include <chainparams.h> @@ -18,9 +20,13 @@ #include <net_processing.h> #include <node/blockstorage.h> #include <node/chainstate.h> +#include <node/context.h> +#include <node/mempool_args.h> #include <node/miner.h> +#include <node/validation_cache_args.h> #include <noui.h> #include <policy/fees.h> +#include <policy/fees_args.h> #include <pow.h> #include <rpc/blockchain.h> #include <rpc/register.h> @@ -32,6 +38,7 @@ #include <test/util/net.h> #include <timedata.h> #include <txdb.h> +#include <txmempool.h> #include <util/strencodings.h> #include <util/string.h> #include <util/thread.h> @@ -48,13 +55,14 @@ #include <functional> #include <stdexcept> +using kernel::ValidationCacheSizes; +using node::ApplyArgsManOptions; using node::BlockAssembler; using node::CalculateCacheSizes; using node::LoadChainstate; +using node::NodeContext; using node::RegenerateCommitments; using node::VerifyLoadedChainstate; -using node::fPruneMode; -using node::fReindex; const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = nullptr; @@ -100,6 +108,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve "-logsourcelocations", "-logtimemicros", "-logthreadnames", + "-loglevel=trace", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", @@ -130,8 +139,12 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve m_node.kernel = std::make_unique<kernel::Context>(); SetupEnvironment(); SetupNetworking(); - InitSignatureCache(); - InitScriptExecutionCache(); + + ValidationCacheSizes validation_cache_sizes{}; + ApplyArgsManOptions(*m_node.args, validation_cache_sizes); + Assert(InitSignatureCache(validation_cache_sizes.signature_cache_bytes)); + Assert(InitScriptExecutionCache(validation_cache_sizes.script_execution_cache_bytes)); + m_node.chain = interfaces::MakeChain(m_node); fCheckBlockIndex = true; static bool noui_connected = false; @@ -149,6 +162,19 @@ BasicTestingSetup::~BasicTestingSetup() gArgs.ClearArgs(); } +CTxMemPool::Options MemPoolOptionsForTest(const NodeContext& node) +{ + CTxMemPool::Options mempool_opts{ + .estimator = node.fee_estimator.get(), + // Default to always checking mempool regardless of + // chainparams.DefaultConsistencyChecks for tests + .check_ratio = 1, + }; + const auto err{ApplyArgsManOptions(*node.args, ::Params(), mempool_opts)}; + Assert(!err); + return mempool_opts; +} + ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args) : BasicTestingSetup(chainName, extra_args) { @@ -160,14 +186,14 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); }); GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler); - m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(); - m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), m_node.args->GetIntArg("-checkmempool", 1)); + m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(*m_node.args)); + m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node)); m_cache_sizes = CalculateCacheSizes(m_args); const ChainstateManager::Options chainman_opts{ - chainparams, - GetAdjustedTime, + .chainparams = chainparams, + .adjusted_time_callback = GetAdjustedTime, }; m_node.chainman = std::make_unique<ChainstateManager>(chainman_opts); m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true); @@ -201,25 +227,20 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const // instead of unit tests, but for now we need these here. RegisterAllCoreRPCCommands(tableRPC); - auto maybe_load_error = LoadChainstate(fReindex.load(), - *Assert(m_node.chainman.get()), - Assert(m_node.mempool.get()), - fPruneMode, - m_args.GetBoolArg("-reindex-chainstate", false), - m_cache_sizes.block_tree_db, - m_cache_sizes.coins_db, - m_cache_sizes.coins, - /*block_tree_db_in_memory=*/true, - /*coins_db_in_memory=*/true); - assert(!maybe_load_error.has_value()); - - auto maybe_verify_error = VerifyLoadedChainstate( - *Assert(m_node.chainman), - fReindex.load(), - m_args.GetBoolArg("-reindex-chainstate", false), - m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS), - m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL)); - assert(!maybe_verify_error.has_value()); + node::ChainstateLoadOptions options; + options.mempool = Assert(m_node.mempool.get()); + options.block_tree_db_in_memory = true; + options.coins_db_in_memory = true; + options.reindex = node::fReindex; + options.reindex_chainstate = m_args.GetBoolArg("-reindex-chainstate", false); + options.prune = node::fPruneMode; + options.check_blocks = m_args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS); + options.check_level = m_args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL); + auto [status, error] = LoadChainstate(*Assert(m_node.chainman), m_cache_sizes, options); + assert(status == node::ChainstateLoadStatus::SUCCESS); + + std::tie(status, error) = VerifyLoadedChainstate(*Assert(m_node.chainman), options); + assert(status == node::ChainstateLoadStatus::SUCCESS); BlockValidationState state; if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) { @@ -275,7 +296,7 @@ void TestChain100Setup::mineBlocks(int num_blocks) CBlock TestChain100Setup::CreateBlock( const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey, - CChainState& chainstate) + Chainstate& chainstate) { CBlock block = BlockAssembler{chainstate, nullptr}.CreateNewBlock(scriptPubKey)->block; @@ -293,7 +314,7 @@ CBlock TestChain100Setup::CreateBlock( CBlock TestChain100Setup::CreateAndProcessBlock( const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey, - CChainState* chainstate) + Chainstate* chainstate) { if (!chainstate) { chainstate = &Assert(m_node.chainman)->ActiveChainstate(); @@ -301,7 +322,7 @@ CBlock TestChain100Setup::CreateAndProcessBlock( const CBlock block = this->CreateBlock(txns, scriptPubKey, *chainstate); std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block); - Assert(m_node.chainman)->ProcessNewBlock(shared_pblock, true, nullptr); + Assert(m_node.chainman)->ProcessNewBlock(shared_pblock, true, true, nullptr); return block; } |