Skip to content

Commit dbdc83a

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24909: refactor: Move and rename pindexBestHeader, fHavePruned
f0a2fb3 scripted-diff: Rename pindexBestHeader, fHavePruned (Carl Dong) a401402 Clear fHavePruned in BlockManager::Unload() (Carl Dong) 3308ecd move-mostly: Make fHavePruned a BlockMan member (Carl Dong) c965241 Clear pindexBestHeader in ChainstateManager::Unload() (Carl Dong) 73eedaa style-only: Miscellaneous whitespace changes (Carl Dong) 0d567da move-mostly: Make pindexBestHeader a ChainMan member (Carl Dong) 5d67017 validation: Load pindexBestHeader in ChainMan (Carl Dong) Pull request description: Split off from #22564 per Marco's suggestion: bitcoin/bitcoin#22564 (comment) This is basically the move-mostly parts of #22564. The overall intent is to move mutable globals manually reset by `::UnloadBlockIndex` into appropriate structs such that they are cleared at the appropriate times. Please read #22564's description for more rationale. In summary , this PR moves: 1. `pindexBestHeader` -> `ChainstateManager::m_best_header` 2. `fHavePruned` -> `BlockManager::m_have_pruned` ACKs for top commit: ajtowns: ACK f0a2fb3 -- code review only MarcoFalke: kirby ACK f0a2fb3 😋 Tree-SHA512: 8d161701af81af1ff42da1b22a6bef2f8626e8642146bc9c3b27f3a7cd24f4d691910a2392b188ae058fec0611a17304dd73f60da695f53832d327f73d2fc963
2 parents fc99f8c + f0a2fb3 commit dbdc83a

File tree

12 files changed

+100
-99
lines changed

12 files changed

+100
-99
lines changed

src/bench/rpc_blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void BlockToJsonVerbose(benchmark::Bench& bench)
4040
{
4141
TestBlockAndIndex data;
4242
bench.run([&] {
43-
auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
43+
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
4444
ankerl::nanobench::doNotOptimizeAway(univalue);
4545
});
4646
}
@@ -50,7 +50,7 @@ BENCHMARK(BlockToJsonVerbose);
5050
static void BlockToJsonVerboseWrite(benchmark::Bench& bench)
5151
{
5252
TestBlockAndIndex data;
53-
auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
53+
auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, &data.blockindex, &data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
5454
bench.run([&] {
5555
auto str = univalue.write();
5656
ankerl::nanobench::doNotOptimizeAway(str);

src/init.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ using node::LoadChainstate;
109109
using node::NodeContext;
110110
using node::ThreadImport;
111111
using node::VerifyLoadedChainstate;
112-
using node::fHavePruned;
113112
using node::fPruneMode;
114113
using node::fReindex;
115114
using node::nPruneTarget;
@@ -1481,7 +1480,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14811480
try {
14821481
uiInterface.InitMessage(_("Verifying blocks…").translated);
14831482
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
1484-
if (fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
1483+
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
14851484
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
14861485
MIN_BLOCKS_TO_KEEP);
14871486
}
@@ -1665,9 +1664,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16651664
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
16661665
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
16671666
}
1668-
if (tip_info && ::pindexBestHeader) {
1669-
tip_info->header_height = ::pindexBestHeader->nHeight;
1670-
tip_info->header_time = ::pindexBestHeader->GetBlockTime();
1667+
if (tip_info && chainman.m_best_header) {
1668+
tip_info->header_height = chainman.m_best_header->nHeight;
1669+
tip_info->header_time = chainman.m_best_header->GetBlockTime();
16711670
}
16721671
}
16731672
LogPrintf("nBestHeight = %d\n", chain_active_height);

src/net_processing.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
14991499
{
15001500
AssertLockHeld(cs_main);
15011501
if (m_chainman.ActiveChain().Contains(pindex)) return true;
1502-
return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (pindexBestHeader != nullptr) &&
1503-
(pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) &&
1504-
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
1502+
return pindex->IsValid(BLOCK_VALID_SCRIPTS) && (m_chainman.m_best_header != nullptr) &&
1503+
(m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() < STALE_RELAY_AGE_LIMIT) &&
1504+
(GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
15051505
}
15061506

15071507
std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index)
@@ -1896,7 +1896,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
18961896
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
18971897
// disconnect node in case we have reached the outbound limit for serving historical blocks
18981898
if (m_connman.OutboundTargetReached(true) &&
1899-
(((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
1899+
(((m_chainman.m_best_header != nullptr) && (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
19001900
!pfrom.HasPermission(NetPermissionFlags::Download) // nodes with the download permission may exceed target
19011901
) {
19021902
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom.GetId());
@@ -2173,12 +2173,12 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
21732173
// nUnconnectingHeaders gets reset back to 0.
21742174
if (!m_chainman.m_blockman.LookupBlockIndex(headers[0].hashPrevBlock) && nCount < MAX_BLOCKS_TO_ANNOUNCE) {
21752175
nodestate->nUnconnectingHeaders++;
2176-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(pindexBestHeader), uint256()));
2176+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), uint256()));
21772177
LogPrint(BCLog::NET, "received header %s: missing prev block %s, sending getheaders (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n",
2178-
headers[0].GetHash().ToString(),
2179-
headers[0].hashPrevBlock.ToString(),
2180-
pindexBestHeader->nHeight,
2181-
pfrom.GetId(), nodestate->nUnconnectingHeaders);
2178+
headers[0].GetHash().ToString(),
2179+
headers[0].hashPrevBlock.ToString(),
2180+
m_chainman.m_best_header->nHeight,
2181+
pfrom.GetId(), nodestate->nUnconnectingHeaders);
21822182
// Set hashLastUnknownBlock for this peer, so that if we
21832183
// eventually get the headers - even from a different peer -
21842184
// we can use this peer to download.
@@ -2235,7 +2235,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
22352235

22362236
if (nCount == MAX_HEADERS_RESULTS) {
22372237
// Headers message had its maximum size; the peer may have more headers.
2238-
// TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or pindexBestHeader, continue
2238+
// TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or m_chainman.m_best_header, continue
22392239
// from there instead.
22402240
LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n",
22412241
pindexLast->nHeight, pfrom.GetId(), peer.m_starting_height);
@@ -3102,8 +3102,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31023102
}
31033103

31043104
if (best_block != nullptr) {
3105-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(pindexBestHeader), *best_block));
3106-
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, best_block->ToString(), pfrom.GetId());
3105+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), *best_block));
3106+
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", m_chainman.m_best_header->nHeight, best_block->ToString(), pfrom.GetId());
31073107
}
31083108

31093109
return;
@@ -3549,7 +3549,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
35493549
if (!m_chainman.m_blockman.LookupBlockIndex(cmpctblock.header.hashPrevBlock)) {
35503550
// Doesn't connect (or is genesis), instead of DoSing in AcceptBlockHeader, request deeper headers
35513551
if (!m_chainman.ActiveChainstate().IsInitialBlockDownload())
3552-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(pindexBestHeader), uint256()));
3552+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETHEADERS, m_chainman.ActiveChain().GetLocator(m_chainman.m_best_header), uint256()));
35533553
return;
35543554
}
35553555

@@ -4670,28 +4670,29 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
46704670
CNodeState &state = *State(pto->GetId());
46714671

46724672
// Start block sync
4673-
if (pindexBestHeader == nullptr)
4674-
pindexBestHeader = m_chainman.ActiveChain().Tip();
4673+
if (m_chainman.m_best_header == nullptr) {
4674+
m_chainman.m_best_header = m_chainman.ActiveChain().Tip();
4675+
}
46754676
bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
46764677
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
46774678
// Only actively request headers from a single peer, unless we're close to today.
4678-
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
4679+
if ((nSyncStarted == 0 && fFetch) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) {
46794680
state.fSyncStarted = true;
46804681
state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
46814682
(
46824683
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
46834684
// to maintain precision
46844685
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
4685-
(GetAdjustedTime() - pindexBestHeader->GetBlockTime()) / consensusParams.nPowTargetSpacing
4686+
(GetAdjustedTime() - m_chainman.m_best_header->GetBlockTime()) / consensusParams.nPowTargetSpacing
46864687
);
46874688
nSyncStarted++;
4688-
const CBlockIndex *pindexStart = pindexBestHeader;
4689+
const CBlockIndex* pindexStart = m_chainman.m_best_header;
46894690
/* If possible, start at the block preceding the currently
46904691
best known header. This ensures that we always get a
46914692
non-empty list of headers back as long as the peer
46924693
is up-to-date. With a non-empty response, we can initialise
46934694
the peer's known best block. This wouldn't be possible
4694-
if we requested starting at pindexBestHeader and
4695+
if we requested starting at m_chainman.m_best_header and
46954696
got back an empty response. */
46964697
if (pindexStart->pprev)
46974698
pindexStart = pindexStart->pprev;
@@ -5016,7 +5017,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
50165017
// Check for headers sync timeouts
50175018
if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) {
50185019
// Detect whether this is a stalling initial-headers-sync peer
5019-
if (pindexBestHeader->GetBlockTime() <= GetAdjustedTime() - 24 * 60 * 60) {
5020+
if (m_chainman.m_best_header->GetBlockTime() <= GetAdjustedTime() - 24 * 60 * 60) {
50205021
if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) {
50215022
// Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer,
50225023
// and we have others we could be using instead.

src/node/blockstorage.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace node {
2525
std::atomic_bool fImporting(false);
2626
std::atomic_bool fReindex(false);
27-
bool fHavePruned = false;
2827
bool fPruneMode = false;
2928
uint64_t nPruneTarget = 0;
3029

@@ -81,7 +80,7 @@ const CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash) const
8180
return it == m_block_index.end() ? nullptr : &it->second;
8281
}
8382

84-
CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
83+
CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header)
8584
{
8685
AssertLockHeld(cs_main);
8786

@@ -106,8 +105,9 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
106105
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
107106
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
108107
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
109-
if (pindexBestHeader == nullptr || pindexBestHeader->nChainWork < pindexNew->nChainWork)
110-
pindexBestHeader = pindexNew;
108+
if (best_header == nullptr || best_header->nChainWork < pindexNew->nChainWork) {
109+
best_header = pindexNew;
110+
}
111111

112112
m_dirty_blockindex.insert(pindexNew);
113113

@@ -285,8 +285,6 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
285285
if (pindex->pprev) {
286286
pindex->BuildSkip();
287287
}
288-
if (pindex->IsValid(BLOCK_VALID_TREE) && (pindexBestHeader == nullptr || CBlockIndexWorkComparator()(pindexBestHeader, pindex)))
289-
pindexBestHeader = pindex;
290288
}
291289

292290
return true;
@@ -302,6 +300,8 @@ void BlockManager::Unload()
302300
m_last_blockfile = 0;
303301
m_dirty_blockindex.clear();
304302
m_dirty_fileinfo.clear();
303+
304+
m_have_pruned = false;
305305
}
306306

307307
bool BlockManager::WriteBlockIndexDB()
@@ -364,8 +364,8 @@ bool BlockManager::LoadBlockIndexDB()
364364
}
365365

366366
// Check whether we have ever pruned block & undo files
367-
m_block_tree_db->ReadFlag("prunedblockfiles", fHavePruned);
368-
if (fHavePruned) {
367+
m_block_tree_db->ReadFlag("prunedblockfiles", m_have_pruned);
368+
if (m_have_pruned) {
369369
LogPrintf("LoadBlockIndexDB(): Block files have previously been pruned\n");
370370
}
371371

@@ -391,10 +391,10 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
391391
return nullptr;
392392
}
393393

394-
bool IsBlockPruned(const CBlockIndex* pblockindex)
394+
bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
395395
{
396396
AssertLockHeld(::cs_main);
397-
return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
397+
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
398398
}
399399

400400
// If we're using -prune with -reindex, then delete block files that will be ignored by the

src/node/blockstorage.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
4545
extern std::atomic_bool fImporting;
4646
extern std::atomic_bool fReindex;
4747
/** Pruning-related variables and constants */
48-
/** True if any block files have ever been pruned. */
49-
extern bool fHavePruned;
5048
/** True if we're running in -prune mode. */
5149
extern bool fPruneMode;
5250
/** Number of MiB of block files that we're trying to stay below. */
@@ -147,7 +145,7 @@ class BlockManager
147145
/** Clear all data members. */
148146
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
149147

150-
CBlockIndex* AddToBlockIndex(const CBlockHeader& block) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
148+
CBlockIndex* AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
151149
/** Create a new block index entry for a given block hash */
152150
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
153151

@@ -171,15 +169,18 @@ class BlockManager
171169
//! Returns last CBlockIndex* that is a checkpoint
172170
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
173171

172+
/** True if any block files have ever been pruned. */
173+
bool m_have_pruned = false;
174+
175+
//! Check whether the block associated with this index entry is pruned or not.
176+
bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
177+
174178
~BlockManager()
175179
{
176180
Unload();
177181
}
178182
};
179183

180-
//! Check whether the block associated with this index entry is pruned or not.
181-
bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
182-
183184
void CleanupBlockRevFiles();
184185

185186
/** Open a block file (blk?????.dat) */

src/node/chainstate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
4949

5050
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
5151

52-
// LoadBlockIndex will load fHavePruned if we've ever removed a
52+
// LoadBlockIndex will load m_have_pruned if we've ever removed a
5353
// block file from disk.
5454
// Note that it also sets fReindex based on the disk flag!
5555
// From here on out fReindex and fReset mean something different!
@@ -65,7 +65,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
6565

6666
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
6767
// in the past, but is now trying to run unpruned.
68-
if (fHavePruned && !fPruneMode) {
68+
if (chainman.m_blockman.m_have_pruned && !fPruneMode) {
6969
return ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX;
7070
}
7171

src/node/interfaces.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ class NodeImpl : public Node
212212
bool getHeaderTip(int& height, int64_t& block_time) override
213213
{
214214
LOCK(::cs_main);
215-
if (::pindexBestHeader) {
216-
height = ::pindexBestHeader->nHeight;
217-
block_time = ::pindexBestHeader->GetBlockTime();
215+
auto best_header = chainman().m_best_header;
216+
if (best_header) {
217+
height = best_header->nHeight;
218+
block_time = best_header->GetBlockTime();
218219
return true;
219220
}
220221
return false;
@@ -644,7 +645,7 @@ class ChainImpl : public Chain
644645
bool havePruned() override
645646
{
646647
LOCK(cs_main);
647-
return node::fHavePruned;
648+
return m_node.chainman->m_blockman.m_have_pruned;
648649
}
649650
bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
650651
bool isInitialBlockDownload() override {

src/rest.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <univalue.h>
3838

3939
using node::GetTransaction;
40-
using node::IsBlockPruned;
4140
using node::NodeContext;
4241
using node::ReadBlockFromDisk;
4342

@@ -295,18 +294,18 @@ static bool rest_block(const std::any& context,
295294
CBlock block;
296295
const CBlockIndex* pblockindex = nullptr;
297296
const CBlockIndex* tip = nullptr;
297+
ChainstateManager* maybe_chainman = GetChainman(context, req);
298+
if (!maybe_chainman) return false;
299+
ChainstateManager& chainman = *maybe_chainman;
298300
{
299-
ChainstateManager* maybe_chainman = GetChainman(context, req);
300-
if (!maybe_chainman) return false;
301-
ChainstateManager& chainman = *maybe_chainman;
302301
LOCK(cs_main);
303302
tip = chainman.ActiveChain().Tip();
304303
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
305304
if (!pblockindex) {
306305
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
307306
}
308307

309-
if (IsBlockPruned(pblockindex))
308+
if (chainman.m_blockman.IsBlockPruned(pblockindex))
310309
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
311310

312311
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
@@ -333,7 +332,7 @@ static bool rest_block(const std::any& context,
333332
}
334333

335334
case RESTResponseFormat::JSON: {
336-
UniValue objBlock = blockToJSON(block, tip, pblockindex, tx_verbosity);
335+
UniValue objBlock = blockToJSON(chainman.m_blockman, block, tip, pblockindex, tx_verbosity);
337336
std::string strJSON = objBlock.write() + "\n";
338337
req->WriteHeader("Content-Type", "application/json");
339338
req->WriteReply(HTTP_OK, strJSON);

0 commit comments

Comments
 (0)