Skip to content

Commit 91c5b68

Browse files
committed
node/ifaces: ChainImpl: Use existing NodeContext member
1 parent 8a1d580 commit 91c5b68

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/node/interfaces.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,15 @@ class ChainImpl : public Chain
449449
bool checkFinalTx(const CTransaction& tx) override
450450
{
451451
LOCK(cs_main);
452-
return CheckFinalTx(::ChainActive().Tip(), tx);
452+
assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain()));
453+
return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx);
453454
}
454455
Optional<int> findLocatorFork(const CBlockLocator& locator) override
455456
{
456457
LOCK(cs_main);
457458
const CChain& active = Assert(m_node.chainman)->ActiveChain();
458-
if (CBlockIndex* fork = g_chainman.m_blockman.FindForkInGlobalIndex(active, locator)) {
459+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
460+
if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) {
459461
return fork->nHeight;
460462
}
461463
return nullopt;
@@ -464,7 +466,8 @@ class ChainImpl : public Chain
464466
{
465467
WAIT_LOCK(cs_main, lock);
466468
const CChain& active = Assert(m_node.chainman)->ActiveChain();
467-
return FillBlock(g_chainman.m_blockman.LookupBlockIndex(hash), block, lock, active);
469+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
470+
return FillBlock(m_node.chainman->m_blockman.LookupBlockIndex(hash), block, lock, active);
468471
}
469472
bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override
470473
{
@@ -476,7 +479,8 @@ class ChainImpl : public Chain
476479
{
477480
WAIT_LOCK(cs_main, lock);
478481
const CChain& active = Assert(m_node.chainman)->ActiveChain();
479-
if (const CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash)) {
482+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
483+
if (const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
480484
if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) {
481485
return FillBlock(ancestor, ancestor_out, lock, active);
482486
}
@@ -487,17 +491,21 @@ class ChainImpl : public Chain
487491
{
488492
WAIT_LOCK(cs_main, lock);
489493
const CChain& active = Assert(m_node.chainman)->ActiveChain();
490-
const CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash);
491-
const CBlockIndex* ancestor = g_chainman.m_blockman.LookupBlockIndex(ancestor_hash);
494+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
495+
const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash);
496+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
497+
const CBlockIndex* ancestor = m_node.chainman->m_blockman.LookupBlockIndex(ancestor_hash);
492498
if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr;
493499
return FillBlock(ancestor, ancestor_out, lock, active);
494500
}
495501
bool findCommonAncestor(const uint256& block_hash1, const uint256& block_hash2, const FoundBlock& ancestor_out, const FoundBlock& block1_out, const FoundBlock& block2_out) override
496502
{
497503
WAIT_LOCK(cs_main, lock);
498504
const CChain& active = Assert(m_node.chainman)->ActiveChain();
499-
const CBlockIndex* block1 = g_chainman.m_blockman.LookupBlockIndex(block_hash1);
500-
const CBlockIndex* block2 = g_chainman.m_blockman.LookupBlockIndex(block_hash2);
505+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
506+
const CBlockIndex* block1 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash1);
507+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
508+
const CBlockIndex* block2 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash2);
501509
const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
502510
// Using & instead of && below to avoid short circuiting and leaving
503511
// output uninitialized.
@@ -507,7 +515,8 @@ class ChainImpl : public Chain
507515
double guessVerificationProgress(const uint256& block_hash) override
508516
{
509517
LOCK(cs_main);
510-
return GuessVerificationProgress(Params().TxData(), g_chainman.m_blockman.LookupBlockIndex(block_hash));
518+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
519+
return GuessVerificationProgress(Params().TxData(), m_node.chainman->m_blockman.LookupBlockIndex(block_hash));
511520
}
512521
bool hasBlocks(const uint256& block_hash, int min_height, Optional<int> max_height) override
513522
{
@@ -519,7 +528,8 @@ class ChainImpl : public Chain
519528
// used to limit the range, and passing min_height that's too low or
520529
// max_height that's too high will not crash or change the result.
521530
LOCK(::cs_main);
522-
if (CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash)) {
531+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
532+
if (CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
523533
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
524534
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
525535
// Check pprev to not segfault if min_height is too low
@@ -603,7 +613,10 @@ class ChainImpl : public Chain
603613
return ::fHavePruned;
604614
}
605615
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
606-
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
616+
bool isInitialBlockDownload() override {
617+
assert(std::addressof(::ChainstateActive()) == std::addressof(m_node.chainman->ActiveChainstate()));
618+
return m_node.chainman->ActiveChainstate().IsInitialBlockDownload();
619+
}
607620
bool shutdownRequested() override { return ShutdownRequested(); }
608621
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
609622
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }

0 commit comments

Comments
 (0)