0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

validation: add CChainParams to ChainstateManager

This commit is contained in:
Anthony Towns 2022-01-18 21:34:16 +10:00
parent a8098f2cef
commit 69675ea4e7
5 changed files with 18 additions and 4 deletions

View file

@ -70,7 +70,7 @@ int main(int argc, char* argv[])
// SETUP: Chainstate
ChainstateManager chainman;
ChainstateManager chainman{chainparams};
auto rv = node::LoadChainstate(false,
std::ref(chainman),

View file

@ -1424,7 +1424,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
for (bool fLoaded = false; !fLoaded && !ShutdownRequested();) {
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), mempool_check_ratio);
node.chainman = std::make_unique<ChainstateManager>();
node.chainman = std::make_unique<ChainstateManager>(chainparams);
ChainstateManager& chainman = *node.chainman;
const bool fReset = fReindex;

View file

@ -151,6 +151,8 @@ BasicTestingSetup::~BasicTestingSetup()
ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args)
: BasicTestingSetup(chainName, extra_args)
{
const CChainParams& chainparams = Params();
// We have to run a scheduler thread to prevent ActivateBestChain
// from blocking due to queue overrun.
m_node.scheduler = std::make_unique<CScheduler>();
@ -162,7 +164,7 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
m_cache_sizes = CalculateCacheSizes(m_args);
m_node.chainman = std::make_unique<ChainstateManager>();
m_node.chainman = std::make_unique<ChainstateManager>(chainparams);
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
// Start script-checking threads. Set g_parallel_script_checks to true so they are used.

View file

@ -22,7 +22,8 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup)
//!
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches)
{
ChainstateManager manager;
const CChainParams& chainparams = Params();
ChainstateManager manager(chainparams);
WITH_LOCK(::cs_main, manager.m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true));
CTxMemPool mempool;

View file

@ -13,6 +13,7 @@
#include <arith_uint256.h>
#include <attributes.h>
#include <chain.h>
#include <chainparams.h>
#include <consensus/amount.h>
#include <fs.h>
#include <node/blockstorage.h>
@ -51,6 +52,9 @@ struct AssumeutxoData;
namespace node {
class SnapshotMetadata;
} // namespace node
namespace Consensus {
struct Params;
} // namespace Consensus
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
@ -834,6 +838,8 @@ private:
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
const CChainParams& m_chainparams;
//! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate,
@ -852,6 +858,11 @@ private:
friend CChainState;
public:
explicit ChainstateManager(const CChainParams& chainparams) : m_chainparams{chainparams} { }
const CChainParams& GetParams() const { return m_chainparams; }
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.