@@ -118,6 +118,7 @@ static const unsigned int MAX_HEADERS_RESULTS = 2000;
118
118
static const int MAX_CMPCTBLOCK_DEPTH = 5 ;
119
119
/* * Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
120
120
static const int MAX_BLOCKTXN_DEPTH = 10 ;
121
+ static_assert (MAX_BLOCKTXN_DEPTH <= MIN_BLOCKS_TO_KEEP, " MAX_BLOCKTXN_DEPTH too high" );
121
122
/* * Size of the "block download window": how far ahead of our current height do we fetch?
122
123
* Larger windows tolerate larger download speed differences between peer, but increase the potential
123
124
* degree of disordering of blocks on disk (which make reindexing and pruning harder). We'll probably
@@ -4366,6 +4367,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4366
4367
return ;
4367
4368
}
4368
4369
4370
+ FlatFilePos block_pos{};
4369
4371
{
4370
4372
LOCK (cs_main);
4371
4373
@@ -4376,15 +4378,21 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4376
4378
}
4377
4379
4378
4380
if (pindex->nHeight >= m_chainman.ActiveChain ().Height () - MAX_BLOCKTXN_DEPTH) {
4379
- CBlock block;
4380
- const bool ret{m_chainman.m_blockman .ReadBlockFromDisk (block, *pindex)};
4381
- assert (ret);
4382
-
4383
- SendBlockTransactions (pfrom, *peer, block, req);
4384
- return ;
4381
+ block_pos = pindex->GetBlockPos ();
4385
4382
}
4386
4383
}
4387
4384
4385
+ if (!block_pos.IsNull ()) {
4386
+ CBlock block;
4387
+ const bool ret{m_chainman.m_blockman .ReadBlockFromDisk (block, block_pos)};
4388
+ // If height is above MAX_BLOCKTXN_DEPTH then this block cannot get
4389
+ // pruned after we release cs_main above, so this read should never fail.
4390
+ assert (ret);
4391
+
4392
+ SendBlockTransactions (pfrom, *peer, block, req);
4393
+ return ;
4394
+ }
4395
+
4388
4396
// If an older block is requested (should never happen in practice,
4389
4397
// but can happen in tests) send a block response instead of a
4390
4398
// blocktxn response. Sending a full block response instead of a
0 commit comments