aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@chaincode.com>2016-10-26 14:53:18 -0400
committerRussell Yanofsky <russ@yanofsky.org>2016-11-07 14:35:11 -0500
commitdac53b58b555183ccc0d5e64c428528267cd98b3 (patch)
tree0b5679b91658ac1feb93dcedf6247fa61c04c0c6 /src
parent55bfddcabbf9e8a3743f77167ba4a43aaba9f948 (diff)
downloadbitcoin-dac53b58b555183ccc0d5e64c428528267cd98b3.tar.xz
Modify getblocktxn handler not to drop requests for old blocks
The current getblocktxn implementation drops and ignores requests for old blocks, which causes occasional sync_block timeouts during the p2p-compactblocks.py test as reported in https://github.com/bitcoin/bitcoin/issues/8842. The p2p-compactblocks.py test setup creates many new blocks in a short period of time, which can lead to getblocktxn requests for blocks below the hardcoded depth limit of 10 blocks. This commit changes the getblocktxn handler not to ignore these requests, so the peer nodes in the test setup will reliably be able to sync. The protocol change is documented in BIP-152 update "Allow block responses to getblocktxn requests" at https://github.com/bitcoin/bips/pull/469. The protocol change is not expected to affect nodes running outside the test environment, because there shouldn't normally be lots of new blocks being rapidly added that need to be synced.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5e17ec6251..55e3d934ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5450,7 +5450,19 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
if (it->second->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) {
+ // If an older block is requested (should never happen in practice,
+ // but can happen in tests) send a block response instead of a
+ // blocktxn response. Sending a full block response instead of a
+ // small blocktxn response is preferable in the case where a peer
+ // might maliciously send lots of getblocktxn requests to trigger
+ // expensive disk reads, because it will require the peer to
+ // actually receive all the data read from disk over the network.
LogPrint("net", "Peer %d sent us a getblocktxn for a block > %i deep", pfrom->id, MAX_BLOCKTXN_DEPTH);
+ CInv vInv;
+ vInv.type = State(pfrom->GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK;
+ vInv.hash = req.blockhash;
+ pfrom->vRecvGetData.push_back(vInv);
+ ProcessGetData(pfrom, chainparams.GetConsensus(), connman);
return true;
}