@@ -672,7 +672,6 @@ static RPCHelpMan getblocktemplate()
672
672
UniValue lpval = NullUniValue;
673
673
std::set<std::string> setClientRules;
674
674
Chainstate& active_chainstate = chainman.ActiveChainstate ();
675
- CChain& active_chain = active_chainstate.m_chain ;
676
675
if (!request.params [0 ].isNull ())
677
676
{
678
677
const UniValue& oparam = request.params [0 ].get_obj ();
@@ -707,9 +706,8 @@ static RPCHelpMan getblocktemplate()
707
706
return " duplicate-inconclusive" ;
708
707
}
709
708
710
- CBlockIndex* const pindexPrev = active_chain.Tip ();
711
709
// testBlockValidity only supports blocks built on the current Tip
712
- if (block.hashPrevBlock != pindexPrev-> GetBlockHash ()) {
710
+ if (block.hashPrevBlock != miner. getTipHash ()) {
713
711
return " inconclusive-not-best-prevblk" ;
714
712
}
715
713
BlockValidationState state;
@@ -761,7 +759,7 @@ static RPCHelpMan getblocktemplate()
761
759
else
762
760
{
763
761
// 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 ();
765
763
nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
766
764
}
767
765
@@ -806,15 +804,15 @@ static RPCHelpMan getblocktemplate()
806
804
static CBlockIndex* pindexPrev;
807
805
static int64_t time_start;
808
806
static std::unique_ptr<CBlockTemplate> pblocktemplate;
809
- if (pindexPrev != active_chain. Tip () ||
807
+ if (! pindexPrev || pindexPrev-> GetBlockHash () != miner. getTipHash () ||
810
808
(mempool.GetTransactionsUpdated () != nTransactionsUpdatedLast && GetTime () - time_start > 5 ))
811
809
{
812
810
// Clear pindexPrev so future calls make a new block, despite any failures from here on
813
811
pindexPrev = nullptr ;
814
812
815
813
// Store the pindexBest used before CreateNewBlock, to avoid races
816
814
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated ();
817
- CBlockIndex* pindexPrevNew = active_chain. Tip ( );
815
+ CBlockIndex* pindexPrevNew = chainman. m_blockman . LookupBlockIndex (miner. getTipHash () );
818
816
time_start = GetTime ();
819
817
820
818
// Create new block
@@ -946,7 +944,7 @@ static RPCHelpMan getblocktemplate()
946
944
result.pushKV (" transactions" , std::move (transactions));
947
945
result.pushKV (" coinbaseaux" , std::move (aux));
948
946
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));
950
948
result.pushKV (" target" , hashTarget.GetHex ());
951
949
result.pushKV (" mintime" , (int64_t )pindexPrev->GetMedianTimePast ()+1 );
952
950
result.pushKV (" mutable" , std::move (aMutable));
0 commit comments