Skip to content

Commit

Permalink
Merge #9058: Fixes for p2p-compactblocks.py test timeouts on travis (…
Browse files Browse the repository at this point in the history
…#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)
  • Loading branch information
laanwj committed Nov 11, 2016
2 parents 46027e8 + dac53b5 commit 7977a11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 13 additions & 5 deletions qa/rpc-tests/p2p-compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
assert(segwit_tx_generated) # check that our test is not broken

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

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

def test_getblocktxn_handler(self, node, test_node, version):
# bitcoind won't respond for blocks whose height is more than 15 blocks
# deep.
# bitcoind will not send blocktxn responses for blocks whose height is
# more than 10 blocks deep.
MAX_GETBLOCKTXN_DEPTH = 10
chain_height = node.getblockcount()
current_height = chain_height
Expand Down Expand Up @@ -623,11 +623,17 @@ def test_getblocktxn_handler(self, node, test_node, version):
test_node.last_blocktxn = None
current_height -= 1

# Next request should be ignored, as we're past the allowed depth.
# Next request should send a full block response, as we're past the
# allowed depth for a blocktxn response.
block_hash = node.getblockhash(current_height)
msg.block_txn_request = BlockTransactionsRequest(int(block_hash, 16), [0])
with mininode_lock:
test_node.last_block = None
test_node.last_blocktxn = None
test_node.send_and_ping(msg)
with mininode_lock:
test_node.last_block.block.calc_sha256()
assert_equal(test_node.last_block.block.sha256, int(block_hash, 16))
assert_equal(test_node.last_blocktxn, None)

def test_compactblocks_not_at_tip(self, node, test_node):
Expand All @@ -648,6 +654,8 @@ def test_compactblocks_not_at_tip(self, node, test_node):
node.generate(1)
wait_until(test_node.received_block_announcement, timeout=30)
test_node.clear_block_announcement()
with mininode_lock:
test_node.last_block = None
test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))]))
success = wait_until(lambda: test_node.last_block is not None, timeout=30)
assert(success)
Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5495,7 +5495,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;
}

Expand Down

0 comments on commit 7977a11

Please sign in to comment.