@@ -431,6 +431,8 @@ class RpcHandlerImpl : public Handler
431
431
432
432
class ChainImpl : public Chain
433
433
{
434
+ private:
435
+ ChainstateManager& chainman () { return *Assert (m_node.chainman ); }
434
436
public:
435
437
explicit ChainImpl (NodeContext& node) : m_node(node) {}
436
438
std::optional<int > getHeight () override
@@ -467,8 +469,8 @@ class ChainImpl : public Chain
467
469
bool checkFinalTx (const CTransaction& tx) override
468
470
{
469
471
LOCK (cs_main);
470
- assert (std::addressof (::ChainActive ()) == std::addressof (m_node. chainman -> ActiveChain ()));
471
- return CheckFinalTx (m_node. chainman -> ActiveChain ().Tip (), tx);
472
+ assert (std::addressof (::ChainActive ()) == std::addressof (chainman (). ActiveChain ()));
473
+ return CheckFinalTx (chainman (). ActiveChain ().Tip (), tx);
472
474
}
473
475
std::optional<int > findLocatorFork (const CBlockLocator& locator) override
474
476
{
@@ -533,8 +535,8 @@ class ChainImpl : public Chain
533
535
double guessVerificationProgress (const uint256& block_hash) override
534
536
{
535
537
LOCK (cs_main);
536
- assert (std::addressof (g_chainman) == std::addressof (*m_node. chainman ));
537
- return GuessVerificationProgress (Params ().TxData (), m_node. chainman -> m_blockman .LookupBlockIndex (block_hash));
538
+ assert (std::addressof (g_chainman. m_blockman ) == std::addressof (chainman (). m_blockman ));
539
+ return GuessVerificationProgress (Params ().TxData (), chainman (). m_blockman .LookupBlockIndex (block_hash));
538
540
}
539
541
bool hasBlocks (const uint256& block_hash, int min_height, std::optional<int > max_height) override
540
542
{
@@ -546,8 +548,8 @@ class ChainImpl : public Chain
546
548
// used to limit the range, and passing min_height that's too low or
547
549
// max_height that's too high will not crash or change the result.
548
550
LOCK (::cs_main);
549
- assert (std::addressof (g_chainman) == std::addressof (*m_node. chainman ));
550
- if (CBlockIndex* block = m_node. chainman -> m_blockman .LookupBlockIndex (block_hash)) {
551
+ assert (std::addressof (g_chainman. m_blockman ) == std::addressof (chainman (). m_blockman ));
552
+ if (CBlockIndex* block = chainman (). m_blockman .LookupBlockIndex (block_hash)) {
551
553
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor (*max_height);
552
554
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev ) {
553
555
// Check pprev to not segfault if min_height is too low
@@ -638,8 +640,16 @@ class ChainImpl : public Chain
638
640
}
639
641
bool isReadyToBroadcast () override { return !::fImporting && !::fReindex && !isInitialBlockDownload (); }
640
642
bool isInitialBlockDownload () override {
641
- assert (std::addressof (::ChainstateActive ()) == std::addressof (m_node.chainman ->ActiveChainstate ()));
642
- return m_node.chainman ->ActiveChainstate ().IsInitialBlockDownload ();
643
+ const CChainState* active_chainstate;
644
+ {
645
+ // TODO: Temporary scope to check correctness of refactored code.
646
+ // Should be removed manually after merge of
647
+ // https://github.com/bitcoin/bitcoin/pull/20158
648
+ LOCK (::cs_main);
649
+ active_chainstate = &chainman ().ActiveChainstate ();
650
+ assert (std::addressof (::ChainstateActive ()) == std::addressof (*active_chainstate));
651
+ }
652
+ return active_chainstate->IsInitialBlockDownload ();
643
653
}
644
654
bool shutdownRequested () override { return ShutdownRequested (); }
645
655
int64_t getAdjustedTime () override { return GetAdjustedTime (); }
0 commit comments