@@ -226,15 +226,18 @@ CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateManager& chainma
226226 }
227227}
228228
229- UniValue blockheaderToJSON (const CBlockIndex* tip, const CBlockIndex* blockindex )
229+ UniValue blockheaderToJSON (const CBlockIndex* tip, const CBlockIndex* blockindex_ )
230230{
231231 // Serialize passed information without accessing chain state of the active chain!
232232 AssertLockNotHeld (cs_main); // For performance reasons
233233
234+ CBlockIndex tmpBlockIndexFull;
235+ const CBlockIndex* blockindex = blockindex_->untrim_to (&tmpBlockIndexFull);
236+
234237 UniValue result (UniValue::VOBJ);
235238 result.pushKV (" hash" , blockindex->GetBlockHash ().GetHex ());
236239 const CBlockIndex* pnext;
237- int confirmations = ComputeNextBlockAndDepth (tip, blockindex , pnext);
240+ int confirmations = ComputeNextBlockAndDepth (tip, blockindex_ , pnext);
238241 result.pushKV (" confirmations" , confirmations);
239242 result.pushKV (" height" , blockindex->nHeight );
240243 result.pushKV (" version" , blockindex->nVersion );
@@ -271,7 +274,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
271274 }
272275 }
273276 result.pushKV (" nTx" , (uint64_t )blockindex->nTx );
274- if (blockindex ->pprev )
277+ if (blockindex_ ->pprev )
275278 result.pushKV (" previousblockhash" , blockindex->pprev ->GetBlockHash ().GetHex ());
276279 if (pnext)
277280 result.pushKV (" nextblockhash" , pnext->GetBlockHash ().GetHex ());
@@ -966,7 +969,7 @@ static RPCHelpMan getblockheader()
966969 if (!request.params [1 ].isNull ())
967970 fVerbose = request.params [1 ].get_bool ();
968971
969- const CBlockIndex* pblockindex;
972+ CBlockIndex* pblockindex;
970973 const CBlockIndex* tip;
971974 {
972975 ChainstateManager& chainman = EnsureAnyChainman (request.context );
@@ -982,13 +985,9 @@ static RPCHelpMan getblockheader()
982985 if (!fVerbose )
983986 {
984987 CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION);
985- if (pblockindex->trimmed ()) {
986- CBlockHeader tmp;
987- ReadBlockHeaderFromDisk (tmp, pblockindex, Params ().GetConsensus ());
988- ssBlock << tmp;
989- } else {
990- ssBlock << pblockindex->GetBlockHeader ();
991- }
988+ CBlockIndex tmpBlockIndexFull;
989+ const CBlockIndex* pblockindexfull = pblockindex->untrim_to (&tmpBlockIndexFull);
990+ ssBlock << pblockindexfull->GetBlockHeader ();
992991 std::string strHex = HexStr (ssBlock);
993992 return strHex;
994993 }
0 commit comments