@@ -672,7 +672,6 @@ static RPCHelpMan getblocktemplate()
672672 UniValue lpval = NullUniValue;
673673 std::set<std::string> setClientRules;
674674 Chainstate& active_chainstate = chainman.ActiveChainstate ();
675- CChain& active_chain = active_chainstate.m_chain ;
676675 if (!request.params [0 ].isNull ())
677676 {
678677 const UniValue& oparam = request.params [0 ].get_obj ();
@@ -707,9 +706,8 @@ static RPCHelpMan getblocktemplate()
707706 return " duplicate-inconclusive" ;
708707 }
709708
710- CBlockIndex* const pindexPrev = active_chain.Tip ();
711709 // testBlockValidity only supports blocks built on the current Tip
712- if (block.hashPrevBlock != pindexPrev-> GetBlockHash ()) {
710+ if (block.hashPrevBlock != miner. getTipHash ()) {
713711 return " inconclusive-not-best-prevblk" ;
714712 }
715713 BlockValidationState state;
@@ -761,7 +759,7 @@ static RPCHelpMan getblocktemplate()
761759 else
762760 {
763761 // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
764- hashWatchedChain = active_chain. Tip ()-> GetBlockHash ();
762+ hashWatchedChain = miner. getTipHash ();
765763 nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
766764 }
767765
@@ -806,15 +804,15 @@ static RPCHelpMan getblocktemplate()
806804 static CBlockIndex* pindexPrev;
807805 static int64_t time_start;
808806 static std::unique_ptr<CBlockTemplate> pblocktemplate;
809- if (pindexPrev != active_chain. Tip () ||
807+ if (! pindexPrev || pindexPrev-> GetBlockHash () != miner. getTipHash () ||
810808 (mempool.GetTransactionsUpdated () != nTransactionsUpdatedLast && GetTime () - time_start > 5 ))
811809 {
812810 // Clear pindexPrev so future calls make a new block, despite any failures from here on
813811 pindexPrev = nullptr ;
814812
815813 // Store the pindexBest used before CreateNewBlock, to avoid races
816814 nTransactionsUpdatedLast = mempool.GetTransactionsUpdated ();
817- CBlockIndex* pindexPrevNew = active_chain. Tip ( );
815+ CBlockIndex* pindexPrevNew = chainman. m_blockman . LookupBlockIndex (miner. getTipHash () );
818816 time_start = GetTime ();
819817
820818 // Create new block
@@ -946,7 +944,7 @@ static RPCHelpMan getblocktemplate()
946944 result.pushKV (" transactions" , std::move (transactions));
947945 result.pushKV (" coinbaseaux" , std::move (aux));
948946 result.pushKV (" coinbasevalue" , (int64_t )pblock->vtx [0 ]->vout [0 ].nValue );
949- result.pushKV (" longpollid" , active_chain. Tip ()-> GetBlockHash ().GetHex () + ToString (nTransactionsUpdatedLast));
947+ result.pushKV (" longpollid" , miner. getTipHash ().GetHex () + ToString (nTransactionsUpdatedLast));
950948 result.pushKV (" target" , hashTarget.GetHex ());
951949 result.pushKV (" mintime" , (int64_t )pindexPrev->GetMedianTimePast ()+1 );
952950 result.pushKV (" mutable" , std::move (aMutable));
0 commit comments