Skip to content

Commit

Permalink
scripted-diff: replace chainActive -> ::ChainActive()
Browse files Browse the repository at this point in the history
Though at the moment ChainActive() simply references `g_chainstate.m_chain`,
doing this change now clears the way for multiple chainstate usage and allows
us to script the diff.

-BEGIN VERIFY SCRIPT-
git grep -l "chainActive" | grep -E '(h|cpp)$' | xargs sed -i '/chainActive =/b; /extern CChain& chainActive/b; s/\(::\)\{0,1\}chainActive/::ChainActive()/g'
-END VERIFY SCRIPT-
  • Loading branch information
jamesob committed May 3, 2019
1 parent a3a6090 commit 631940a
Show file tree
Hide file tree
Showing 27 changed files with 247 additions and 247 deletions.
4 changes: 2 additions & 2 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void benchmark::BenchRunner::RunAll(Printer& printer, uint64_t num_evals, double
for (const auto& p : benchmarks()) {
TestingSetup test{CBaseChainParams::REGTEST};
{
assert(::chainActive.Height() == 0);
const bool witness_enabled{IsWitnessEnabled(::chainActive.Tip(), Params().GetConsensus())};
assert(::ChainActive().Height() == 0);
const bool witness_enabled{IsWitnessEnabled(::ChainActive().Tip(), Params().GetConsensus())};
assert(witness_enabled);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void DuplicateInputs(benchmark::State& state)
CMutableTransaction coinbaseTx{};
CMutableTransaction naughtyTx{};

CBlockIndex* pindexPrev = ::chainActive.Tip();
CBlockIndex* pindexPrev = ::ChainActive().Tip();
assert(pindexPrev != nullptr);
block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus());
block.nNonce = 0;
Expand Down
16 changes: 8 additions & 8 deletions src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ bool BaseIndex::Init()
if (locator.IsNull()) {
m_best_block_index = nullptr;
} else {
m_best_block_index = FindForkInGlobalIndex(chainActive, locator);
m_best_block_index = FindForkInGlobalIndex(::ChainActive(), locator);
}
m_synced = m_best_block_index.load() == chainActive.Tip();
m_synced = m_best_block_index.load() == ::ChainActive().Tip();
return true;
}

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

if (!pindex_prev) {
return chainActive.Genesis();
return ::ChainActive().Genesis();
}

const CBlockIndex* pindex = chainActive.Next(pindex_prev);
const CBlockIndex* pindex = ::ChainActive().Next(pindex_prev);
if (pindex) {
return pindex;
}

return chainActive.Next(chainActive.FindFork(pindex_prev));
return ::ChainActive().Next(::ChainActive().FindFork(pindex_prev));
}

void BaseIndex::ThreadSync()
Expand Down Expand Up @@ -168,7 +168,7 @@ bool BaseIndex::Commit()
bool BaseIndex::CommitInternal(CDBBatch& batch)
{
LOCK(cs_main);
GetDB().WriteBestBlock(batch, chainActive.GetLocator(m_best_block_index));
GetDB().WriteBestBlock(batch, ::ChainActive().GetLocator(m_best_block_index));
return true;
}

Expand Down Expand Up @@ -280,9 +280,9 @@ bool BaseIndex::BlockUntilSyncedToCurrentChain()

{
// Skip the queue-draining stuff if we know we're caught up with
// chainActive.Tip().
// ::ChainActive().Tip().
LOCK(cs_main);
const CBlockIndex* chain_tip = chainActive.Tip();
const CBlockIndex* chain_tip = ::ChainActive().Tip();
const CBlockIndex* best_block_index = m_best_block_index.load();
if (best_block_index->GetAncestor(chain_tip->nHeight) == chain_tip) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/index/txindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool TxIndex::Init()
// Attempt to migrate txindex from the old database to the new one. Even if
// chain_tip is null, the node could be reindexing and we still want to
// delete txindex records in the old database.
if (!m_db->MigrateData(*pblocktree, chainActive.GetLocator())) {
if (!m_db->MigrateData(*pblocktree, ::ChainActive().GetLocator())) {
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void SetupServerArgs()
"and level 4 tries to reconnect the blocks, "
"each level includes the checks of the previous levels "
"(0-4, default: %u)", DEFAULT_CHECKLEVEL), true, OptionsCategory::DEBUG_TEST);
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);
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);
gArgs.AddArg("-checkmempool=<n>", strprintf("Run checks every <n> transactions (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", true, OptionsCategory::DEBUG_TEST);
Expand Down Expand Up @@ -1572,12 +1572,12 @@ bool AppInitMain(InitInterfaces& interfaces)

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

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

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

Expand Down
26 changes: 13 additions & 13 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LockImpl : public Chain::Lock
{
Optional<int> getHeight() override
{
int height = ::chainActive.Height();
int height = ::ChainActive().Height();
if (height >= 0) {
return height;
}
Expand All @@ -50,7 +50,7 @@ class LockImpl : public Chain::Lock
Optional<int> getBlockHeight(const uint256& hash) override
{
CBlockIndex* block = LookupBlockIndex(hash);
if (block && ::chainActive.Contains(block)) {
if (block && ::ChainActive().Contains(block)) {
return block->nHeight;
}
return nullopt;
Expand All @@ -63,30 +63,30 @@ class LockImpl : public Chain::Lock
}
uint256 getBlockHash(int height) override
{
CBlockIndex* block = ::chainActive[height];
CBlockIndex* block = ::ChainActive()[height];
assert(block != nullptr);
return block->GetBlockHash();
}
int64_t getBlockTime(int height) override
{
CBlockIndex* block = ::chainActive[height];
CBlockIndex* block = ::ChainActive()[height];
assert(block != nullptr);
return block->GetBlockTime();
}
int64_t getBlockMedianTimePast(int height) override
{
CBlockIndex* block = ::chainActive[height];
CBlockIndex* block = ::ChainActive()[height];
assert(block != nullptr);
return block->GetMedianTimePast();
}
bool haveBlockOnDisk(int height) override
{
CBlockIndex* block = ::chainActive[height];
CBlockIndex* block = ::ChainActive()[height];
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
}
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
{
CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time, height);
CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height);
if (block) {
if (hash) *hash = block->GetBlockHash();
return block->nHeight;
Expand All @@ -96,7 +96,7 @@ class LockImpl : public Chain::Lock
Optional<int> findPruned(int start_height, Optional<int> stop_height) override
{
if (::fPruneMode) {
CBlockIndex* block = stop_height ? ::chainActive[*stop_height] : ::chainActive.Tip();
CBlockIndex* block = stop_height ? ::ChainActive()[*stop_height] : ::ChainActive().Tip();
while (block && block->nHeight >= start_height) {
if ((block->nStatus & BLOCK_HAVE_DATA) == 0) {
return block->nHeight;
Expand All @@ -109,7 +109,7 @@ class LockImpl : public Chain::Lock
Optional<int> findFork(const uint256& hash, Optional<int>* height) override
{
const CBlockIndex* block = LookupBlockIndex(hash);
const CBlockIndex* fork = block ? ::chainActive.FindFork(block) : nullptr;
const CBlockIndex* fork = block ? ::ChainActive().FindFork(block) : nullptr;
if (height) {
if (block) {
*height = block->nHeight;
Expand All @@ -122,11 +122,11 @@ class LockImpl : public Chain::Lock
}
return nullopt;
}
CBlockLocator getTipLocator() override { return ::chainActive.GetLocator(); }
CBlockLocator getTipLocator() override { return ::ChainActive().GetLocator(); }
Optional<int> findLocatorFork(const CBlockLocator& locator) override
{
LockAnnotation lock(::cs_main);
if (CBlockIndex* fork = FindForkInGlobalIndex(::chainActive, locator)) {
if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) {
return fork->nHeight;
}
return nullopt;
Expand Down Expand Up @@ -341,9 +341,9 @@ class ChainImpl : public Chain
{
if (!old_tip.IsNull()) {
LOCK(::cs_main);
if (old_tip == ::chainActive.Tip()->GetBlockHash()) return;
if (old_tip == ::ChainActive().Tip()->GetBlockHash()) return;
CBlockIndex* block = LookupBlockIndex(old_tip);
if (block && block->GetAncestor(::chainActive.Height()) == ::chainActive.Tip()) return;
if (block && block->GetAncestor(::ChainActive().Height()) == ::ChainActive().Tip()) return;
}
SyncWithValidationInterfaceQueue();
}
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ class NodeImpl : public Node
int getNumBlocks() override
{
LOCK(::cs_main);
return ::chainActive.Height();
return ::ChainActive().Height();
}
int64_t getLastBlockTime() override
{
LOCK(::cs_main);
if (::chainActive.Tip()) {
return ::chainActive.Tip()->GetBlockTime();
if (::ChainActive().Tip()) {
return ::ChainActive().Tip()->GetBlockTime();
}
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
}
Expand All @@ -193,7 +193,7 @@ class NodeImpl : public Node
const CBlockIndex* tip;
{
LOCK(::cs_main);
tip = ::chainActive.Tip();
tip = ::ChainActive().Tip();
}
return GuessVerificationProgress(Params().TxData(), tip);
}
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end

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

Expand Down
Loading

0 comments on commit 631940a

Please sign in to comment.