Skip to content

Commit 0da6ae2

Browse files
committed
Do not inv old or missing blocks when pruning
When responding to a getblocks message, only return inv's as long as we HAVE_DATA for blocks in the chain, and only for blocks that we aren't likely to delete in the near future.
1 parent 4848218 commit 0da6ae2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
41534153
LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
41544154
break;
41554155
}
4156+
// If pruning, don't inv blocks unless we have on disk and are likely to still have
4157+
// for some reasonable time window (1 hour) that block relay might require.
4158+
const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus().nPowTargetSpacing;
4159+
if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
4160+
{
4161+
LogPrint("net", " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
4162+
break;
4163+
}
41564164
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
41574165
if (--nLimit <= 0)
41584166
{

0 commit comments

Comments
 (0)