@@ -431,6 +431,8 @@ class RpcHandlerImpl : public Handler
431431
432432class ChainImpl : public Chain
433433{
434+ private:
435+ ChainstateManager& chainman () { return *Assert (m_node.chainman ); }
434436public:
435437 explicit ChainImpl (NodeContext& node) : m_node(node) {}
436438 std::optional<int > getHeight () override
@@ -467,8 +469,8 @@ class ChainImpl : public Chain
467469 bool checkFinalTx (const CTransaction& tx) override
468470 {
469471 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);
472474 }
473475 std::optional<int > findLocatorFork (const CBlockLocator& locator) override
474476 {
@@ -533,8 +535,8 @@ class ChainImpl : public Chain
533535 double guessVerificationProgress (const uint256& block_hash) override
534536 {
535537 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));
538540 }
539541 bool hasBlocks (const uint256& block_hash, int min_height, std::optional<int > max_height) override
540542 {
@@ -546,8 +548,8 @@ class ChainImpl : public Chain
546548 // used to limit the range, and passing min_height that's too low or
547549 // max_height that's too high will not crash or change the result.
548550 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)) {
551553 if (max_height && block->nHeight >= *max_height) block = block->GetAncestor (*max_height);
552554 for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev ) {
553555 // Check pprev to not segfault if min_height is too low
@@ -638,8 +640,16 @@ class ChainImpl : public Chain
638640 }
639641 bool isReadyToBroadcast () override { return !::fImporting && !::fReindex && !isInitialBlockDownload (); }
640642 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 ();
643653 }
644654 bool shutdownRequested () override { return ShutdownRequested (); }
645655 int64_t getAdjustedTime () override { return GetAdjustedTime (); }
0 commit comments