@@ -402,7 +402,7 @@ void Shutdown(NodeContext& node)
402402 ECC_Stop ();
403403 node.mempool .reset ();
404404 node.fee_estimator .reset ();
405- node.chainman = nullptr ;
405+ node.chainman . reset () ;
406406 node.scheduler .reset ();
407407
408408 try {
@@ -883,12 +883,12 @@ static void StartupNotify(const ArgsManager& args)
883883}
884884#endif
885885
886- static void PeriodicStats (ArgsManager& args, const CTxMemPool& mempool)
886+ static void PeriodicStats (ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool)
887887{
888888 assert (args.GetBoolArg (" -statsenabled" , DEFAULT_STATSD_ENABLE));
889889 CCoinsStats stats{CoinStatsHashType::NONE};
890- ::ChainstateActive ().ForceFlushStateToDisk();
891- if (WITH_LOCK (cs_main, return GetUTXOStats (&:: ChainstateActive ().CoinsDB (), std::ref (g_chainman .m_blockman ), stats, RpcInterruptionPoint, :: ChainActive ().Tip ()))) {
890+ chainman. ActiveChainstate ().ForceFlushStateToDisk ();
891+ if (WITH_LOCK (cs_main, return GetUTXOStats (&chainman. ActiveChainstate ().CoinsDB (), std::ref (chainman .m_blockman ), stats, RpcInterruptionPoint, chainman. ActiveChain ().Tip ()))) {
892892 statsClient.gauge (" utxoset.tx" , stats.nTransactions , 1 .0f );
893893 statsClient.gauge (" utxoset.txOutputs" , stats.nTransactionOutputs , 1 .0f );
894894 statsClient.gauge (" utxoset.dbSizeBytes" , stats.nDiskSize , 1 .0f );
@@ -902,7 +902,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool)
902902 }
903903
904904 // short version of GetNetworkHashPS(120, -1);
905- CBlockIndex *tip = :: ChainActive ().Tip ();
905+ CBlockIndex *tip = chainman. ActiveChain ().Tip ();
906906 CBlockIndex *pindex = tip;
907907 int64_t minTime = pindex->GetBlockTime ();
908908 int64_t maxTime = minTime;
@@ -923,7 +923,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool)
923923 // No need for cs_main, we never use null tip here
924924 statsClient.gaugeDouble (" network.difficulty" , (double )GetDifficulty (tip));
925925
926- statsClient.gauge (" transactions.txCacheSize" , WITH_LOCK (cs_main, return :: ChainstateActive ().CoinsTip ().GetCacheSize ()), 1 .0f );
926+ statsClient.gauge (" transactions.txCacheSize" , WITH_LOCK (cs_main, return chainman. ActiveChainstate ().CoinsTip ().GetCacheSize ()), 1 .0f );
927927 statsClient.gauge (" transactions.totalTransactions" , tip->nChainTx , 1 .0f );
928928
929929 {
@@ -1716,8 +1716,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
17161716 node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator .get (), check_ratio);
17171717
17181718 assert (!node.chainman );
1719- node.chainman = &g_chainman ;
1720- ChainstateManager& chainman = *Assert ( node.chainman ) ;
1719+ node.chainman = std::make_unique<ChainstateManager>() ;
1720+ ChainstateManager& chainman = *node.chainman ;
17211721
17221722 assert (!node.mn_metaman );
17231723 node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
@@ -1913,7 +1913,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
19131913#endif
19141914
19151915 pdsNotificationInterface = new CDSNotificationInterface (
1916- *node.connman , *node.mn_sync , *node.govman , *node.peerman , node.mn_activeman .get (), node.dmnman , node.llmq_ctx , node.cj_ctx
1916+ *node.connman , *node.mn_sync , *node.govman , *node.peerman , chainman, node.mn_activeman .get (), node.dmnman , node.llmq_ctx , node.cj_ctx
19171917 );
19181918 RegisterValidationInterface (pdsNotificationInterface);
19191919
@@ -2016,7 +2016,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
20162016 node.llmq_ctx = std::make_unique<LLMQContext>(chainman.ActiveChainstate (), *node.connman , *node.dmnman , *node.evodb , *node.mn_metaman , *node.mnhf_manager , *node.sporkman ,
20172017 *node.mempool , node.mn_activeman .get (), *node.mn_sync , node.peerman , /* unit_tests = */ false , /* wipe = */ fReset || fReindexChainState );
20182018 // Enable CMNHFManager::{Process, Undo}Block
2019- node.mnhf_manager ->ConnectManagers (node.chainman , node.llmq_ctx ->qman .get ());
2019+ node.mnhf_manager ->ConnectManagers (node.chainman . get () , node.llmq_ctx ->qman .get ());
20202020 // Have to start it early to let VerifyDB check ChainLock signatures in coinbase
20212021 node.llmq_ctx ->Start ();
20222022
@@ -2050,12 +2050,12 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
20502050 // If the loaded chain has a wrong genesis, bail out immediately
20512051 // (we're likely using a testnet datadir, or the other way around).
20522052 if (!chainman.BlockIndex ().empty () &&
2053- !g_chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashGenesisBlock )) {
2053+ !chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashGenesisBlock )) {
20542054 return InitError (_ (" Incorrect or no genesis block found. Wrong datadir for network?" ));
20552055 }
20562056
20572057 if (!chainparams.GetConsensus ().hashDevnetGenesisBlock .IsNull () && !chainman.BlockIndex ().empty () &&
2058- !g_chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashDevnetGenesisBlock )) {
2058+ !chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashDevnetGenesisBlock )) {
20592059 return InitError (_ (" Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?" ));
20602060 }
20612061
@@ -2088,7 +2088,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
20882088 // If we're not mid-reindex (based on disk + args), add a genesis block on disk
20892089 // (otherwise we use the one already on disk).
20902090 // This is called again in ThreadImport after the reindex completes.
2091- if (!fReindex && !:: ChainstateActive ().LoadGenesisBlock ()) {
2091+ if (!fReindex && !chainman. ActiveChainstate ().LoadGenesisBlock ()) {
20922092 strLoadError = _ (" Error initializing block database" );
20932093 break ;
20942094 }
@@ -2132,7 +2132,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
21322132 // TODO: CEvoDB instance should probably be a part of CChainState
21332133 // (for multiple chainstates to actually work in parallel)
21342134 // and not a global
2135- if (&:: ChainstateActive () == chainstate && !node.evodb ->CommitRootTransaction ()) {
2135+ if (&chainman. ActiveChainstate () == chainstate && !node.evodb ->CommitRootTransaction ()) {
21362136 strLoadError = _ (" Failed to commit EvoDB" );
21372137 failed_chainstate_init = true ;
21382138 break ;
@@ -2210,7 +2210,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22102210 // TODO: CEvoDB instance should probably be a part of CChainState
22112211 // (for multiple chainstates to actually work in parallel)
22122212 // and not a global
2213- if (&:: ChainstateActive () == chainstate && !node.evodb ->IsEmpty ()) {
2213+ if (&chainman. ActiveChainstate () == chainstate && !node.evodb ->IsEmpty ()) {
22142214 // EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
22152215 strLoadError = _ (" Error initializing block database" );
22162216 failed_verification = true ;
@@ -2271,7 +2271,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
22712271
22722272 // ********************************************************* Step 7d: Setup other Dash services
22732273
2274- bool fLoadCacheFiles = !(fReindex || fReindexChainState ) && (:: ChainActive ().Tip () != nullptr );
2274+ bool fLoadCacheFiles = !(fReindex || fReindexChainState ) && (chainman. ActiveChain ().Tip () != nullptr );
22752275
22762276 if (!node.netfulfilledman ->LoadCache (fLoadCacheFiles )) {
22772277 auto file_path = (GetDataDir () / " netfulfilled.dat" ).string ();
@@ -2302,21 +2302,21 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23022302 // ********************************************************* Step 8: start indexers
23032303 if (args.GetBoolArg (" -txindex" , DEFAULT_TXINDEX)) {
23042304 g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false , fReindex );
2305- if (!g_txindex->Start (:: ChainstateActive ())) {
2305+ if (!g_txindex->Start (chainman. ActiveChainstate ())) {
23062306 return false ;
23072307 }
23082308 }
23092309
23102310 for (const auto & filter_type : g_enabled_filter_types) {
23112311 InitBlockFilterIndex (filter_type, filter_index_cache, false , fReindex );
2312- if (!GetBlockFilterIndex (filter_type)->Start (:: ChainstateActive ())) {
2312+ if (!GetBlockFilterIndex (filter_type)->Start (chainman. ActiveChainstate ())) {
23132313 return false ;
23142314 }
23152315 }
23162316
23172317 if (args.GetBoolArg (" -coinstatsindex" , DEFAULT_COINSTATSINDEX)) {
23182318 g_coin_stats_index = std::make_unique<CoinStatsIndex>(/* cache size */ 0 , false , fReindex );
2319- if (!g_coin_stats_index->Start (:: ChainstateActive ())) {
2319+ if (!g_coin_stats_index->Start (chainman. ActiveChainstate ())) {
23202320 return false ;
23212321 }
23222322 }
@@ -2383,7 +2383,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23832383
23842384 if (args.GetBoolArg (" -statsenabled" , DEFAULT_STATSD_ENABLE)) {
23852385 int nStatsPeriod = std::min (std::max ((int )args.GetArg (" -statsperiod" , DEFAULT_STATSD_PERIOD), MIN_STATSD_PERIOD), MAX_STATSD_PERIOD);
2386- node.scheduler ->scheduleEvery (std::bind (&PeriodicStats, std::ref (*node.args ), std::cref (*node.mempool )), std::chrono::seconds{nStatsPeriod});
2386+ node.scheduler ->scheduleEvery (std::bind (&PeriodicStats, std::ref (*node.args ), std::ref (chainman), std:: cref (*node.mempool )), std::chrono::seconds{nStatsPeriod});
23872387 }
23882388
23892389 // ********************************************************* Step 11: import blocks
@@ -2400,7 +2400,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
24002400 // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
24012401 // No locking, as this happens before any background thread is started.
24022402 boost::signals2::connection block_notify_genesis_wait_connection;
2403- if (:: ChainActive ().Tip () == nullptr ) {
2403+ if (chainman. ActiveChain ().Tip () == nullptr ) {
24042404 block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect (std::bind (BlockNotifyGenesisWait, std::placeholders::_2));
24052405 } else {
24062406 fHaveGenesis = true ;
@@ -2476,7 +2476,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
24762476 tip_info->header_time = ::pindexBestHeader->GetBlockTime ();
24772477 }
24782478 }
2479- LogPrintf (" ::ChainActive().Height() = %d\n " , chain_active_height);
2479+ LogPrintf (" nBestHeight = %d\n " , chain_active_height);
24802480 if (node.peerman ) node.peerman ->SetBestHeight (chain_active_height);
24812481
24822482 // Map ports with UPnP or NAT-PMP.
0 commit comments