Skip to content

Commit b2a6b02

Browse files
author
MarcoFalke
committed
Merge #15948: refactor: rename chainActive
486c1ee refactoring: remove unused chainActive (James O'Beirne) 631940a scripted-diff: replace chainActive -> ::ChainActive() (James O'Beirne) a3a6090 refactoring: introduce unused ChainActive() (James O'Beirne) 1b6e6fc rename: CChainState.chainActive -> m_chain (James O'Beirne) Pull request description: This is part of the assumeutxo project: Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/2019-04-proposal/proposal --- This change refactors the `chainActive` reference into a `::ChainActive()` call. It also distinguishes `CChainState`'s `CChain` data member as `m_chain` instead of the current `chainActive`, which makes it easily confused with the global data. The active chain must be obtained via function because its reference will be swapped at some point during runtime after loading a UTXO snapshot. This change, though lengthy, should be pretty easy to review since most of it is contained within a scripted-diff. Once merged, the parent PR should be easier to review. ACKs for commit 486c1e: Sjors: utACK 486c1ee promag: utACK 486c1ee. practicalswift: utACK 486c1ee Tree-SHA512: 06ed8f9e77f2d25fc9bea0ba86436d80dbbce90a1e8be23e37ec4eeb26060483e60b4a5c4fba679cb1867f61e3921c24abeb9cabdfb4d0a9b1c4ddd77b17456a
2 parents 3632143 + 486c1ee commit b2a6b02

27 files changed

+307
-304
lines changed

src/bench/bench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
114114
for (const auto& p : benchmarks()) {
115115
TestingSetup test{CBaseChainParams::REGTEST};
116116
{
117-
assert(::chainActive.Height() == 0);
118-
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), Params().GetConsensus())};
117+
assert(::ChainActive().Height() == 0);
118+
const bool witness_enabled{IsWitnessEnabled(::ChainActive().Tip(), Params().GetConsensus())};
119119
assert(witness_enabled);
120120
}
121121

src/bench/duplicate_inputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void DuplicateInputs(benchmark::State& state)
2929
CMutableTransaction coinbaseTx{};
3030
CMutableTransaction naughtyTx{};
3131

32-
CBlockIndex* pindexPrev = ::chainActive.Tip();
32+
CBlockIndex* pindexPrev = ::ChainActive().Tip();
3333
assert(pindexPrev != nullptr);
3434
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
3535
block.nNonce = 0;

src/index/base.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ bool BaseIndex::Init()
6363
if (locator.IsNull()) {
6464
m_best_block_index = nullptr;
6565
} else {
66-
m_best_block_index = FindForkInGlobalIndex(chainActive, locator);
66+
m_best_block_index = FindForkInGlobalIndex(::ChainActive(), locator);
6767
}
68-
m_synced = m_best_block_index.load() == chainActive.Tip();
68+
m_synced = m_best_block_index.load() == ::ChainActive().Tip();
6969
return true;
7070
}
7171

@@ -74,15 +74,15 @@ static const CBlockIndex* NextSyncBlock(const CBlockIndex* pindex_prev) EXCLUSIV
7474
AssertLockHeld(cs_main);
7575

7676
if (!pindex_prev) {
77-
return chainActive.Genesis();
77+
return ::ChainActive().Genesis();
7878
}
7979

80-
const CBlockIndex* pindex = chainActive.Next(pindex_prev);
80+
const CBlockIndex* pindex = ::ChainActive().Next(pindex_prev);
8181
if (pindex) {
8282
return pindex;
8383
}
8484

85-
return chainActive.Next(chainActive.FindFork(pindex_prev));
85+
return ::ChainActive().Next(::ChainActive().FindFork(pindex_prev));
8686
}
8787

8888
void BaseIndex::ThreadSync()
@@ -168,7 +168,7 @@ bool BaseIndex::Commit()
168168
bool BaseIndex::CommitInternal(CDBBatch& batch)
169169
{
170170
LOCK(cs_main);
171-
GetDB().WriteBestBlock(batch, chainActive.GetLocator(m_best_block_index));
171+
GetDB().WriteBestBlock(batch, ::ChainActive().GetLocator(m_best_block_index));
172172
return true;
173173
}
174174

@@ -280,9 +280,9 @@ bool BaseIndex::BlockUntilSyncedToCurrentChain()
280280

281281
{
282282
// Skip the queue-draining stuff if we know we're caught up with
283-
// chainActive.Tip().
283+
// ::ChainActive().Tip().
284284
LOCK(cs_main);
285-
const CBlockIndex* chain_tip = chainActive.Tip();
285+
const CBlockIndex* chain_tip = ::ChainActive().Tip();
286286
const CBlockIndex* best_block_index = m_best_block_index.load();
287287
if (best_block_index->GetAncestor(chain_tip->nHeight) == chain_tip) {
288288
return true;

src/index/txindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ bool TxIndex::Init()
236236
// Attempt to migrate txindex from the old database to the new one. Even if
237237
// chain_tip is null, the node could be reindexing and we still want to
238238
// delete txindex records in the old database.
239-
if (!m_db->MigrateData(*pblocktree, chainActive.GetLocator())) {
239+
if (!m_db->MigrateData(*pblocktree, ::ChainActive().GetLocator())) {
240240
return false;
241241
}
242242

src/init.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void SetupServerArgs()
490490
"and level 4 tries to reconnect the blocks, "
491491
"each level includes the checks of the previous levels "
492492
"(0-4, default: %u)", DEFAULT_CHECKLEVEL), true, OptionsCategory::DEBUG_TEST);
493-
gArgs.AddArg("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, chainActive and mapBlocksUnlinked occasionally. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), true, OptionsCategory::DEBUG_TEST);
493+
gArgs.AddArg("-checkblockindex", strprintf("Do a full consistency check for mapBlockIndex, setBlockIndexCandidates, ::ChainActive() and mapBlocksUnlinked occasionally. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), true, OptionsCategory::DEBUG_TEST);
494494
gArgs.AddArg("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), true, OptionsCategory::DEBUG_TEST);
495495
gArgs.AddArg("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED), true, OptionsCategory::DEBUG_TEST);
496496
gArgs.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", true, OptionsCategory::DEBUG_TEST);
@@ -1572,12 +1572,12 @@ bool AppInitMain(InitInterfaces& interfaces)
15721572

15731573
is_coinsview_empty = fReset || fReindexChainState || pcoinsTip->GetBestBlock().IsNull();
15741574
if (!is_coinsview_empty) {
1575-
// LoadChainTip sets chainActive based on pcoinsTip's best block
1575+
// LoadChainTip sets ::ChainActive() based on pcoinsTip's best block
15761576
if (!LoadChainTip(chainparams)) {
15771577
strLoadError = _("Error initializing block database");
15781578
break;
15791579
}
1580-
assert(chainActive.Tip() != nullptr);
1580+
assert(::ChainActive().Tip() != nullptr);
15811581
}
15821582
} catch (const std::exception& e) {
15831583
LogPrintf("%s\n", e.what());
@@ -1587,7 +1587,7 @@ bool AppInitMain(InitInterfaces& interfaces)
15871587

15881588
if (!fReset) {
15891589
// Note that RewindBlockIndex MUST run even if we're about to -reindex-chainstate.
1590-
// It both disconnects blocks based on chainActive, and drops block data in
1590+
// It both disconnects blocks based on ::ChainActive(), and drops block data in
15911591
// mapBlockIndex based on lack of available witness data.
15921592
uiInterface.InitMessage(_("Rewinding blocks..."));
15931593
if (!RewindBlockIndex(chainparams)) {
@@ -1605,7 +1605,7 @@ bool AppInitMain(InitInterfaces& interfaces)
16051605
MIN_BLOCKS_TO_KEEP);
16061606
}
16071607

1608-
CBlockIndex* tip = chainActive.Tip();
1608+
CBlockIndex* tip = ::ChainActive().Tip();
16091609
RPCNotifyBlockChange(true, tip);
16101610
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
16111611
strLoadError = _("The block database contains a block which appears to be from the future. "
@@ -1719,7 +1719,7 @@ bool AppInitMain(InitInterfaces& interfaces)
17191719
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
17201720
// No locking, as this happens before any background thread is started.
17211721
boost::signals2::connection block_notify_genesis_wait_connection;
1722-
if (chainActive.Tip() == nullptr) {
1722+
if (::ChainActive().Tip() == nullptr) {
17231723
block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
17241724
} else {
17251725
fHaveGenesis = true;
@@ -1759,7 +1759,7 @@ bool AppInitMain(InitInterfaces& interfaces)
17591759
{
17601760
LOCK(cs_main);
17611761
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
1762-
chain_active_height = chainActive.Height();
1762+
chain_active_height = ::ChainActive().Height();
17631763
}
17641764
LogPrintf("nBestHeight = %d\n", chain_active_height);
17651765

src/interfaces/chain.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class LockImpl : public Chain::Lock
4141
{
4242
Optional<int> getHeight() override
4343
{
44-
int height = ::chainActive.Height();
44+
int height = ::ChainActive().Height();
4545
if (height >= 0) {
4646
return height;
4747
}
@@ -50,7 +50,7 @@ class LockImpl : public Chain::Lock
5050
Optional<int> getBlockHeight(const uint256& hash) override
5151
{
5252
CBlockIndex* block = LookupBlockIndex(hash);
53-
if (block && ::chainActive.Contains(block)) {
53+
if (block && ::ChainActive().Contains(block)) {
5454
return block->nHeight;
5555
}
5656
return nullopt;
@@ -63,30 +63,30 @@ class LockImpl : public Chain::Lock
6363
}
6464
uint256 getBlockHash(int height) override
6565
{
66-
CBlockIndex* block = ::chainActive[height];
66+
CBlockIndex* block = ::ChainActive()[height];
6767
assert(block != nullptr);
6868
return block->GetBlockHash();
6969
}
7070
int64_t getBlockTime(int height) override
7171
{
72-
CBlockIndex* block = ::chainActive[height];
72+
CBlockIndex* block = ::ChainActive()[height];
7373
assert(block != nullptr);
7474
return block->GetBlockTime();
7575
}
7676
int64_t getBlockMedianTimePast(int height) override
7777
{
78-
CBlockIndex* block = ::chainActive[height];
78+
CBlockIndex* block = ::ChainActive()[height];
7979
assert(block != nullptr);
8080
return block->GetMedianTimePast();
8181
}
8282
bool haveBlockOnDisk(int height) override
8383
{
84-
CBlockIndex* block = ::chainActive[height];
84+
CBlockIndex* block = ::ChainActive()[height];
8585
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
8686
}
8787
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
8888
{
89-
CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time, height);
89+
CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height);
9090
if (block) {
9191
if (hash) *hash = block->GetBlockHash();
9292
return block->nHeight;
@@ -96,7 +96,7 @@ class LockImpl : public Chain::Lock
9696
Optional<int> findPruned(int start_height, Optional<int> stop_height) override
9797
{
9898
if (::fPruneMode) {
99-
CBlockIndex* block = stop_height ? ::chainActive[*stop_height] : ::chainActive.Tip();
99+
CBlockIndex* block = stop_height ? ::ChainActive()[*stop_height] : ::ChainActive().Tip();
100100
while (block && block->nHeight >= start_height) {
101101
if ((block->nStatus & BLOCK_HAVE_DATA) == 0) {
102102
return block->nHeight;
@@ -109,7 +109,7 @@ class LockImpl : public Chain::Lock
109109
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
110110
{
111111
const CBlockIndex* block = LookupBlockIndex(hash);
112-
const CBlockIndex* fork = block ? ::chainActive.FindFork(block) : nullptr;
112+
const CBlockIndex* fork = block ? ::ChainActive().FindFork(block) : nullptr;
113113
if (height) {
114114
if (block) {
115115
*height = block->nHeight;
@@ -122,11 +122,11 @@ class LockImpl : public Chain::Lock
122122
}
123123
return nullopt;
124124
}
125-
CBlockLocator getTipLocator() override { return ::chainActive.GetLocator(); }
125+
CBlockLocator getTipLocator() override { return ::ChainActive().GetLocator(); }
126126
Optional<int> findLocatorFork(const CBlockLocator& locator) override
127127
{
128128
LockAnnotation lock(::cs_main);
129-
if (CBlockIndex* fork = FindForkInGlobalIndex(::chainActive, locator)) {
129+
if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) {
130130
return fork->nHeight;
131131
}
132132
return nullopt;
@@ -341,9 +341,9 @@ class ChainImpl : public Chain
341341
{
342342
if (!old_tip.IsNull()) {
343343
LOCK(::cs_main);
344-
if (old_tip == ::chainActive.Tip()->GetBlockHash()) return;
344+
if (old_tip == ::ChainActive().Tip()->GetBlockHash()) return;
345345
CBlockIndex* block = LookupBlockIndex(old_tip);
346-
if (block && block->GetAncestor(::chainActive.Height()) == ::chainActive.Tip()) return;
346+
if (block && block->GetAncestor(::ChainActive().Height()) == ::ChainActive().Tip()) return;
347347
}
348348
SyncWithValidationInterfaceQueue();
349349
}

src/interfaces/node.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ class NodeImpl : public Node
178178
int getNumBlocks() override
179179
{
180180
LOCK(::cs_main);
181-
return ::chainActive.Height();
181+
return ::ChainActive().Height();
182182
}
183183
int64_t getLastBlockTime() override
184184
{
185185
LOCK(::cs_main);
186-
if (::chainActive.Tip()) {
187-
return ::chainActive.Tip()->GetBlockTime();
186+
if (::ChainActive().Tip()) {
187+
return ::ChainActive().Tip()->GetBlockTime();
188188
}
189189
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
190190
}
@@ -193,7 +193,7 @@ class NodeImpl : public Node
193193
const CBlockIndex* tip;
194194
{
195195
LOCK(::cs_main);
196-
tip = ::chainActive.Tip();
196+
tip = ::ChainActive().Tip();
197197
}
198198
return GuessVerificationProgress(Params().TxData(), tip);
199199
}

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
109109
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
110110

111111
LOCK2(cs_main, mempool.cs);
112-
CBlockIndex* pindexPrev = chainActive.Tip();
112+
CBlockIndex* pindexPrev = ::ChainActive().Tip();
113113
assert(pindexPrev != nullptr);
114114
nHeight = pindexPrev->nHeight + 1;
115115

0 commit comments

Comments
 (0)