@@ -80,6 +80,8 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex *pa, const CBlockIn
80
80
81
81
CChainState g_chainstate;
82
82
83
+ CChainState& ChainstateActive () { return g_chainstate; }
84
+
83
85
CChain& ChainActive () { return g_chainstate.m_chain ; }
84
86
85
87
/* *
@@ -94,7 +96,7 @@ CChain& ChainActive() { return g_chainstate.m_chain; }
94
96
*/
95
97
RecursiveMutex cs_main;
96
98
97
- BlockMap& mapBlockIndex = g_chainstate .mapBlockIndex;
99
+ BlockMap& mapBlockIndex = ::ChainstateActive() .mapBlockIndex;
98
100
CBlockIndex *pindexBestHeader = nullptr ;
99
101
Mutex g_best_block_mutex;
100
102
std::condition_variable g_best_block_cv;
@@ -125,12 +127,12 @@ CScript COINBASE_FLAGS;
125
127
126
128
// Internal stuff
127
129
namespace {
128
- CBlockIndex *&pindexBestInvalid = g_chainstate .pindexBestInvalid;
130
+ CBlockIndex *&pindexBestInvalid = ::ChainstateActive() .pindexBestInvalid;
129
131
130
132
/* * All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
131
133
* Pruned nodes may have entries where B is missing data.
132
134
*/
133
- std::multimap<CBlockIndex*, CBlockIndex*>& mapBlocksUnlinked = g_chainstate .mapBlocksUnlinked;
135
+ std::multimap<CBlockIndex*, CBlockIndex*>& mapBlocksUnlinked = ::ChainstateActive() .mapBlocksUnlinked;
134
136
135
137
CCriticalSection cs_LastBlockFile;
136
138
std::vector<CBlockFileInfo> vinfoBlockFile;
@@ -2627,7 +2629,7 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
2627
2629
}
2628
2630
2629
2631
bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
2630
- return g_chainstate .ActivateBestChain (state, chainparams, std::move (pblock));
2632
+ return :: ChainstateActive () .ActivateBestChain (state, chainparams, std::move (pblock));
2631
2633
}
2632
2634
2633
2635
bool CChainState::PreciousBlock (CValidationState& state, const CChainParams& params, CBlockIndex *pindex)
@@ -2659,7 +2661,7 @@ bool CChainState::PreciousBlock(CValidationState& state, const CChainParams& par
2659
2661
return ActivateBestChain (state, params, std::shared_ptr<const CBlock>());
2660
2662
}
2661
2663
bool PreciousBlock (CValidationState& state, const CChainParams& params, CBlockIndex *pindex) {
2662
- return g_chainstate .PreciousBlock (state, params, pindex);
2664
+ return :: ChainstateActive () .PreciousBlock (state, params, pindex);
2663
2665
}
2664
2666
2665
2667
bool CChainState::InvalidateBlock (CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex)
@@ -2748,7 +2750,7 @@ bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& c
2748
2750
}
2749
2751
2750
2752
bool InvalidateBlock (CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex) {
2751
- return g_chainstate .InvalidateBlock (state, chainparams, pindex);
2753
+ return :: ChainstateActive () .InvalidateBlock (state, chainparams, pindex);
2752
2754
}
2753
2755
2754
2756
void CChainState::ResetBlockFailureFlags (CBlockIndex *pindex) {
@@ -2786,7 +2788,7 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
2786
2788
}
2787
2789
2788
2790
void ResetBlockFailureFlags (CBlockIndex *pindex) {
2789
- return g_chainstate .ResetBlockFailureFlags (pindex);
2791
+ return :: ChainstateActive () .ResetBlockFailureFlags (pindex);
2790
2792
}
2791
2793
2792
2794
CBlockIndex* CChainState::AddToBlockIndex (const CBlockHeader& block)
@@ -3324,7 +3326,7 @@ bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, CValidatio
3324
3326
LOCK (cs_main);
3325
3327
for (const CBlockHeader& header : headers) {
3326
3328
CBlockIndex *pindex = nullptr ; // Use a temp pindex instead of ppindex to avoid a const_cast
3327
- if (!g_chainstate .AcceptBlockHeader (header, state, chainparams, &pindex)) {
3329
+ if (!:: ChainstateActive () .AcceptBlockHeader (header, state, chainparams, &pindex)) {
3328
3330
if (first_invalid) *first_invalid = header;
3329
3331
return false ;
3330
3332
}
@@ -3455,7 +3457,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
3455
3457
bool ret = CheckBlock (*pblock, state, chainparams.GetConsensus ());
3456
3458
if (ret) {
3457
3459
// Store to disk
3458
- ret = g_chainstate .AcceptBlock (pblock, state, chainparams, &pindex, fForceProcessing , nullptr , fNewBlock );
3460
+ ret = :: ChainstateActive () .AcceptBlock (pblock, state, chainparams, &pindex, fForceProcessing , nullptr , fNewBlock );
3459
3461
}
3460
3462
if (!ret) {
3461
3463
GetMainSignals ().BlockChecked (*pblock, state);
@@ -3466,7 +3468,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
3466
3468
NotifyHeaderTip ();
3467
3469
3468
3470
CValidationState state; // Only used to report errors, not invalidity - ignore it
3469
- if (!g_chainstate .ActivateBestChain (state, chainparams, pblock))
3471
+ if (!:: ChainstateActive () .ActivateBestChain (state, chainparams, pblock))
3470
3472
return error (" %s: ActivateBestChain failed (%s)" , __func__, FormatStateMessage (state));
3471
3473
3472
3474
return true ;
@@ -3490,7 +3492,7 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
3490
3492
return error (" %s: Consensus::CheckBlock: %s" , __func__, FormatStateMessage (state));
3491
3493
if (!ContextualCheckBlock (block, state, chainparams.GetConsensus (), pindexPrev))
3492
3494
return error (" %s: Consensus::ContextualCheckBlock: %s" , __func__, FormatStateMessage (state));
3493
- if (!g_chainstate .ConnectBlock (block, state, &indexDummy, viewNew, chainparams, true ))
3495
+ if (!:: ChainstateActive () .ConnectBlock (block, state, &indexDummy, viewNew, chainparams, true ))
3494
3496
return false ;
3495
3497
assert (state.IsValid ());
3496
3498
@@ -3757,7 +3759,7 @@ bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlo
3757
3759
3758
3760
bool static LoadBlockIndexDB (const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
3759
3761
{
3760
- if (!g_chainstate .LoadBlockIndex (chainparams.GetConsensus (), *pblocktree))
3762
+ if (!:: ChainstateActive () .LoadBlockIndex (chainparams.GetConsensus (), *pblocktree))
3761
3763
return false ;
3762
3764
3763
3765
// Load block file info
@@ -3832,7 +3834,7 @@ bool LoadChainTip(const CChainParams& chainparams)
3832
3834
}
3833
3835
::ChainActive ().SetTip(pindex);
3834
3836
3835
- g_chainstate .PruneBlockIndexCandidates ();
3837
+ ::ChainstateActive () .PruneBlockIndexCandidates();
3836
3838
3837
3839
LogPrintf (" Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n " ,
3838
3840
::ChainActive ().Tip()->GetBlockHash().ToString(), ::ChainActive().Height(),
@@ -3905,7 +3907,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3905
3907
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
3906
3908
if (nCheckLevel >= 3 && (coins.DynamicMemoryUsage () + pcoinsTip->DynamicMemoryUsage ()) <= nCoinCacheUsage) {
3907
3909
assert (coins.GetBestBlock () == pindex->GetBlockHash ());
3908
- DisconnectResult res = g_chainstate .DisconnectBlock (block, pindex, coins);
3910
+ DisconnectResult res = :: ChainstateActive () .DisconnectBlock (block, pindex, coins);
3909
3911
if (res == DISCONNECT_FAILED) {
3910
3912
return error (" VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3911
3913
}
@@ -3940,7 +3942,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
3940
3942
CBlock block;
3941
3943
if (!ReadBlockFromDisk (block, pindex, chainparams.GetConsensus ()))
3942
3944
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3943
- if (!g_chainstate .ConnectBlock (block, state, pindex, coins, chainparams))
3945
+ if (!:: ChainstateActive () .ConnectBlock (block, state, pindex, coins, chainparams))
3944
3946
return error (" VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)" , pindex->nHeight , pindex->GetBlockHash ().ToString (), FormatStateMessage (state));
3945
3947
}
3946
3948
}
@@ -4039,7 +4041,7 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
4039
4041
}
4040
4042
4041
4043
bool ReplayBlocks (const CChainParams& params, CCoinsView* view) {
4042
- return g_chainstate .ReplayBlocks (params, view);
4044
+ return :: ChainstateActive () .ReplayBlocks (params, view);
4043
4045
}
4044
4046
4045
4047
// ! Helper for CChainState::RewindBlockIndex
@@ -4172,7 +4174,7 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
4172
4174
}
4173
4175
4174
4176
bool RewindBlockIndex (const CChainParams& params) {
4175
- if (!g_chainstate .RewindBlockIndex (params)) {
4177
+ if (!:: ChainstateActive () .RewindBlockIndex (params)) {
4176
4178
return false ;
4177
4179
}
4178
4180
@@ -4222,7 +4224,7 @@ void UnloadBlockIndex()
4222
4224
mapBlockIndex.clear ();
4223
4225
fHavePruned = false ;
4224
4226
4225
- g_chainstate .UnloadBlockIndex ();
4227
+ ::ChainstateActive () .UnloadBlockIndex();
4226
4228
}
4227
4229
4228
4230
bool LoadBlockIndex (const CChainParams& chainparams)
@@ -4274,7 +4276,7 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
4274
4276
4275
4277
bool LoadGenesisBlock (const CChainParams& chainparams)
4276
4278
{
4277
- return g_chainstate .LoadGenesisBlock (chainparams);
4279
+ return :: ChainstateActive () .LoadGenesisBlock (chainparams);
4278
4280
}
4279
4281
4280
4282
bool LoadExternalBlockFile (const CChainParams& chainparams, FILE* fileIn, FlatFilePos *dbp)
@@ -4339,7 +4341,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
4339
4341
CBlockIndex* pindex = LookupBlockIndex (hash);
4340
4342
if (!pindex || (pindex->nStatus & BLOCK_HAVE_DATA) == 0 ) {
4341
4343
CValidationState state;
4342
- if (g_chainstate .AcceptBlock (pblock, state, chainparams, nullptr , true , dbp, nullptr )) {
4344
+ if (:: ChainstateActive () .AcceptBlock (pblock, state, chainparams, nullptr , true , dbp, nullptr )) {
4343
4345
nLoaded++;
4344
4346
}
4345
4347
if (state.IsError ()) {
@@ -4376,7 +4378,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
4376
4378
head.ToString ());
4377
4379
LOCK (cs_main);
4378
4380
CValidationState dummy;
4379
- if (g_chainstate .AcceptBlock (pblockrecursive, dummy, chainparams, nullptr , true , &it->second , nullptr ))
4381
+ if (:: ChainstateActive () .AcceptBlock (pblockrecursive, dummy, chainparams, nullptr , true , &it->second , nullptr ))
4380
4382
{
4381
4383
nLoaded++;
4382
4384
queue.push_back (pblockrecursive->GetHash ());
0 commit comments