@@ -402,7 +402,7 @@ void Shutdown(NodeContext& node)
402
402
ECC_Stop ();
403
403
node.mempool .reset ();
404
404
node.fee_estimator .reset ();
405
- node.chainman = nullptr ;
405
+ node.chainman . reset () ;
406
406
node.scheduler .reset ();
407
407
408
408
try {
@@ -883,12 +883,12 @@ static void StartupNotify(const ArgsManager& args)
883
883
}
884
884
#endif
885
885
886
- static void PeriodicStats (ArgsManager& args, const CTxMemPool& mempool)
886
+ static void PeriodicStats (ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool)
887
887
{
888
888
assert (args.GetBoolArg (" -statsenabled" , DEFAULT_STATSD_ENABLE));
889
889
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 ()))) {
892
892
statsClient.gauge (" utxoset.tx" , stats.nTransactions , 1 .0f );
893
893
statsClient.gauge (" utxoset.txOutputs" , stats.nTransactionOutputs , 1 .0f );
894
894
statsClient.gauge (" utxoset.dbSizeBytes" , stats.nDiskSize , 1 .0f );
@@ -902,7 +902,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool)
902
902
}
903
903
904
904
// short version of GetNetworkHashPS(120, -1);
905
- CBlockIndex *tip = :: ChainActive ().Tip ();
905
+ CBlockIndex *tip = chainman. ActiveChain ().Tip ();
906
906
CBlockIndex *pindex = tip;
907
907
int64_t minTime = pindex->GetBlockTime ();
908
908
int64_t maxTime = minTime;
@@ -923,7 +923,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool)
923
923
// No need for cs_main, we never use null tip here
924
924
statsClient.gaugeDouble (" network.difficulty" , (double )GetDifficulty (tip));
925
925
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 );
927
927
statsClient.gauge (" transactions.totalTransactions" , tip->nChainTx , 1 .0f );
928
928
929
929
{
@@ -1716,8 +1716,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
1716
1716
node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator .get (), check_ratio);
1717
1717
1718
1718
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 ;
1721
1721
1722
1722
assert (!node.mn_metaman );
1723
1723
node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
@@ -1913,7 +1913,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
1913
1913
#endif
1914
1914
1915
1915
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
1917
1917
);
1918
1918
RegisterValidationInterface (pdsNotificationInterface);
1919
1919
@@ -2016,7 +2016,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2016
2016
node.llmq_ctx = std::make_unique<LLMQContext>(chainman.ActiveChainstate (), *node.connman , *node.dmnman , *node.evodb , *node.mn_metaman , *node.mnhf_manager , *node.sporkman ,
2017
2017
*node.mempool , node.mn_activeman .get (), *node.mn_sync , node.peerman , /* unit_tests = */ false , /* wipe = */ fReset || fReindexChainState );
2018
2018
// 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 ());
2020
2020
// Have to start it early to let VerifyDB check ChainLock signatures in coinbase
2021
2021
node.llmq_ctx ->Start ();
2022
2022
@@ -2050,12 +2050,12 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2050
2050
// If the loaded chain has a wrong genesis, bail out immediately
2051
2051
// (we're likely using a testnet datadir, or the other way around).
2052
2052
if (!chainman.BlockIndex ().empty () &&
2053
- !g_chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashGenesisBlock )) {
2053
+ !chainman .m_blockman .LookupBlockIndex (chainparams.GetConsensus ().hashGenesisBlock )) {
2054
2054
return InitError (_ (" Incorrect or no genesis block found. Wrong datadir for network?" ));
2055
2055
}
2056
2056
2057
2057
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 )) {
2059
2059
return InitError (_ (" Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?" ));
2060
2060
}
2061
2061
@@ -2088,7 +2088,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2088
2088
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
2089
2089
// (otherwise we use the one already on disk).
2090
2090
// This is called again in ThreadImport after the reindex completes.
2091
- if (!fReindex && !:: ChainstateActive ().LoadGenesisBlock ()) {
2091
+ if (!fReindex && !chainman. ActiveChainstate ().LoadGenesisBlock ()) {
2092
2092
strLoadError = _ (" Error initializing block database" );
2093
2093
break ;
2094
2094
}
@@ -2132,7 +2132,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2132
2132
// TODO: CEvoDB instance should probably be a part of CChainState
2133
2133
// (for multiple chainstates to actually work in parallel)
2134
2134
// and not a global
2135
- if (&:: ChainstateActive () == chainstate && !node.evodb ->CommitRootTransaction ()) {
2135
+ if (&chainman. ActiveChainstate () == chainstate && !node.evodb ->CommitRootTransaction ()) {
2136
2136
strLoadError = _ (" Failed to commit EvoDB" );
2137
2137
failed_chainstate_init = true ;
2138
2138
break ;
@@ -2210,7 +2210,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2210
2210
// TODO: CEvoDB instance should probably be a part of CChainState
2211
2211
// (for multiple chainstates to actually work in parallel)
2212
2212
// and not a global
2213
- if (&:: ChainstateActive () == chainstate && !node.evodb ->IsEmpty ()) {
2213
+ if (&chainman. ActiveChainstate () == chainstate && !node.evodb ->IsEmpty ()) {
2214
2214
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
2215
2215
strLoadError = _ (" Error initializing block database" );
2216
2216
failed_verification = true ;
@@ -2271,7 +2271,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2271
2271
2272
2272
// ********************************************************* Step 7d: Setup other Dash services
2273
2273
2274
- bool fLoadCacheFiles = !(fReindex || fReindexChainState ) && (:: ChainActive ().Tip () != nullptr );
2274
+ bool fLoadCacheFiles = !(fReindex || fReindexChainState ) && (chainman. ActiveChain ().Tip () != nullptr );
2275
2275
2276
2276
if (!node.netfulfilledman ->LoadCache (fLoadCacheFiles )) {
2277
2277
auto file_path = (GetDataDir () / " netfulfilled.dat" ).string ();
@@ -2302,21 +2302,21 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2302
2302
// ********************************************************* Step 8: start indexers
2303
2303
if (args.GetBoolArg (" -txindex" , DEFAULT_TXINDEX)) {
2304
2304
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false , fReindex );
2305
- if (!g_txindex->Start (:: ChainstateActive ())) {
2305
+ if (!g_txindex->Start (chainman. ActiveChainstate ())) {
2306
2306
return false ;
2307
2307
}
2308
2308
}
2309
2309
2310
2310
for (const auto & filter_type : g_enabled_filter_types) {
2311
2311
InitBlockFilterIndex (filter_type, filter_index_cache, false , fReindex );
2312
- if (!GetBlockFilterIndex (filter_type)->Start (:: ChainstateActive ())) {
2312
+ if (!GetBlockFilterIndex (filter_type)->Start (chainman. ActiveChainstate ())) {
2313
2313
return false ;
2314
2314
}
2315
2315
}
2316
2316
2317
2317
if (args.GetBoolArg (" -coinstatsindex" , DEFAULT_COINSTATSINDEX)) {
2318
2318
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 ())) {
2320
2320
return false ;
2321
2321
}
2322
2322
}
@@ -2383,7 +2383,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2383
2383
2384
2384
if (args.GetBoolArg (" -statsenabled" , DEFAULT_STATSD_ENABLE)) {
2385
2385
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});
2387
2387
}
2388
2388
2389
2389
// ********************************************************* Step 11: import blocks
@@ -2400,7 +2400,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2400
2400
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
2401
2401
// No locking, as this happens before any background thread is started.
2402
2402
boost::signals2::connection block_notify_genesis_wait_connection;
2403
- if (:: ChainActive ().Tip () == nullptr ) {
2403
+ if (chainman. ActiveChain ().Tip () == nullptr ) {
2404
2404
block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect (std::bind (BlockNotifyGenesisWait, std::placeholders::_2));
2405
2405
} else {
2406
2406
fHaveGenesis = true ;
@@ -2476,7 +2476,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
2476
2476
tip_info->header_time = ::pindexBestHeader->GetBlockTime ();
2477
2477
}
2478
2478
}
2479
- LogPrintf (" ::ChainActive().Height() = %d\n " , chain_active_height);
2479
+ LogPrintf (" nBestHeight = %d\n " , chain_active_height);
2480
2480
if (node.peerman ) node.peerman ->SetBestHeight (chain_active_height);
2481
2481
2482
2482
// Map ports with UPnP or NAT-PMP.
0 commit comments