aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-09-23 14:04:07 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-09-23 14:04:08 +0200
commit999c8be81a00146cc0ee0f6fb49104e906e08835 (patch)
tree0775a8dd217e9fcd2371508b37738cd5e149119e /src
parent6264e5b378dae3852a1c1e84e5c519a3c581c941 (diff)
parentae6f957a628efeeae47b8a2deee595c2ac5e7640 (diff)
Merge pull request #6148
ae6f957 Enable block relay when pruning (Suhas Daftuar) 0da6ae2 Do not inv old or missing blocks when pruning (Suhas Daftuar)
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4a84714ebc..e27b8444b4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2315,9 +2315,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
int nBlockEstimate = 0;
if (fCheckpointsEnabled)
nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints());
- // Don't relay blocks if pruning -- could cause a peer to try to download, resulting
- // in a stalled download if the block file is pruned before the request.
- if (nLocalServices & NODE_NETWORK) {
+ {
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate))
@@ -4198,6 +4196,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
break;
}
+ // If pruning, don't inv blocks unless we have on disk and are likely to still have
+ // for some reasonable time window (1 hour) that block relay might require.
+ const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus().nPowTargetSpacing;
+ if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
+ {
+ LogPrint("net", " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
+ break;
+ }
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
if (--nLimit <= 0)
{