Skip to content

Commit 999c8be

Browse files
committed
Merge pull request #6148
ae6f957 Enable block relay when pruning (Suhas Daftuar) 0da6ae2 Do not inv old or missing blocks when pruning (Suhas Daftuar)
2 parents 6264e5b + ae6f957 commit 999c8be

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,9 +2315,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
23152315
int nBlockEstimate = 0;
23162316
if (fCheckpointsEnabled)
23172317
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints());
2318-
// Don't relay blocks if pruning -- could cause a peer to try to download, resulting
2319-
// in a stalled download if the block file is pruned before the request.
2320-
if (nLocalServices & NODE_NETWORK) {
2318+
{
23212319
LOCK(cs_vNodes);
23222320
BOOST_FOREACH(CNode* pnode, vNodes)
23232321
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
@@ -4198,6 +4196,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
41984196
LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
41994197
break;
42004198
}
4199+
// If pruning, don't inv blocks unless we have on disk and are likely to still have
4200+
// for some reasonable time window (1 hour) that block relay might require.
4201+
const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus().nPowTargetSpacing;
4202+
if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
4203+
{
4204+
LogPrint("net", " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
4205+
break;
4206+
}
42014207
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
42024208
if (--nLimit <= 0)
42034209
{

0 commit comments

Comments
 (0)