Skip to content

Commit 7977a11

Browse files
committed
Merge #9058: Fixes for p2p-compactblocks.py test timeouts on travis (#8842)
dac53b5 Modify getblocktxn handler not to drop requests for old blocks (Russell Yanofsky) 55bfddc [qa] Fix stale data bug in test_compactblocks_not_at_tip (Russell Yanofsky) 47e9659 [qa] Fix bug in compactblocks v2 merge (Russell Yanofsky)
2 parents 46027e8 + dac53b5 commit 7977a11

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
300300
assert(segwit_tx_generated) # check that our test is not broken
301301

302302
# Wait until we've seen the block announcement for the resulting tip
303-
tip = int(self.nodes[0].getbestblockhash(), 16)
304-
assert(self.test_node.wait_for_block_announcement(tip))
303+
tip = int(node.getbestblockhash(), 16)
304+
assert(test_node.wait_for_block_announcement(tip))
305305

306306
# Now mine a block, and look at the resulting compact block.
307307
test_node.clear_block_announcement()
@@ -589,8 +589,8 @@ def test_incorrect_blocktxn_response(self, node, test_node, version):
589589
assert_equal(int(node.getbestblockhash(), 16), block.sha256)
590590

591591
def test_getblocktxn_handler(self, node, test_node, version):
592-
# bitcoind won't respond for blocks whose height is more than 15 blocks
593-
# deep.
592+
# bitcoind will not send blocktxn responses for blocks whose height is
593+
# more than 10 blocks deep.
594594
MAX_GETBLOCKTXN_DEPTH = 10
595595
chain_height = node.getblockcount()
596596
current_height = chain_height
@@ -623,11 +623,17 @@ def test_getblocktxn_handler(self, node, test_node, version):
623623
test_node.last_blocktxn = None
624624
current_height -= 1
625625

626-
# Next request should be ignored, as we're past the allowed depth.
626+
# Next request should send a full block response, as we're past the
627+
# allowed depth for a blocktxn response.
627628
block_hash = node.getblockhash(current_height)
628629
msg.block_txn_request = BlockTransactionsRequest(int(block_hash, 16), [0])
630+
with mininode_lock:
631+
test_node.last_block = None
632+
test_node.last_blocktxn = None
629633
test_node.send_and_ping(msg)
630634
with mininode_lock:
635+
test_node.last_block.block.calc_sha256()
636+
assert_equal(test_node.last_block.block.sha256, int(block_hash, 16))
631637
assert_equal(test_node.last_blocktxn, None)
632638

633639
def test_compactblocks_not_at_tip(self, node, test_node):
@@ -648,6 +654,8 @@ def test_compactblocks_not_at_tip(self, node, test_node):
648654
node.generate(1)
649655
wait_until(test_node.received_block_announcement, timeout=30)
650656
test_node.clear_block_announcement()
657+
with mininode_lock:
658+
test_node.last_block = None
651659
test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
652660
success = wait_until(lambda: test_node.last_block is not None, timeout=30)
653661
assert(success)

src/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,7 +5495,19 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54955495
}
54965496

54975497
if (it->second->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) {
5498+
// If an older block is requested (should never happen in practice,
5499+
// but can happen in tests) send a block response instead of a
5500+
// blocktxn response. Sending a full block response instead of a
5501+
// small blocktxn response is preferable in the case where a peer
5502+
// might maliciously send lots of getblocktxn requests to trigger
5503+
// expensive disk reads, because it will require the peer to
5504+
// actually receive all the data read from disk over the network.
54985505
LogPrint("net", "Peer %d sent us a getblocktxn for a block > %i deep", pfrom->id, MAX_BLOCKTXN_DEPTH);
5506+
CInv vInv;
5507+
vInv.type = State(pfrom->GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK;
5508+
vInv.hash = req.blockhash;
5509+
pfrom->vRecvGetData.push_back(vInv);
5510+
ProcessGetData(pfrom, chainparams.GetConsensus(), connman);
54995511
return true;
55005512
}
55015513

0 commit comments

Comments
 (0)