Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_sendheaders.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test behavior of headers messages to announce blocks. | """Test behavior of headers messages to announce blocks. | ||||
Setup: | Setup: | ||||
- Two nodes: | - Two nodes: | ||||
- node0 is the node-under-test. We create two p2p connections to it. The | - node0 is the node-under-test. We create two p2p connections to it. The | ||||
▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | def test_nonnull_locators(self, test_node, inv_node): | ||||
test_node.wait_for_block(new_block_hashes[-1]) | test_node.wait_for_block(new_block_hashes[-1]) | ||||
for i in range(3): | for i in range(3): | ||||
# Mine another block, still should get only an inv | # Mine another block, still should get only an inv | ||||
tip = self.mine_blocks(1) | tip = self.mine_blocks(1) | ||||
inv_node.check_last_announcement(inv=[tip], headers=[]) | inv_node.check_last_announcement(inv=[tip], headers=[]) | ||||
test_node.check_last_announcement(inv=[tip], headers=[]) | test_node.check_last_announcement(inv=[tip], headers=[]) | ||||
if i == 0: | if i == 0: | ||||
# Just get the data -- shouldn't cause headers announcements to resume | self.log.debug( | ||||
"Just get the data -- shouldn't cause headers announcements to resume") | |||||
test_node.send_get_data([tip]) | test_node.send_get_data([tip]) | ||||
test_node.wait_for_block(tip) | test_node.wait_for_block(tip) | ||||
elif i == 1: | elif i == 1: | ||||
# Send a getheaders message that shouldn't trigger headers announcements | self.log.debug( | ||||
# to resume (best header sent will be too old) | "Send a getheaders message that shouldn't trigger headers announcements to resume (best header sent will be too old)") | ||||
test_node.send_get_headers( | test_node.send_get_headers( | ||||
locator=[fork_point], hashstop=new_block_hashes[1]) | locator=[fork_point], hashstop=new_block_hashes[1]) | ||||
test_node.send_get_data([tip]) | test_node.send_get_data([tip]) | ||||
test_node.wait_for_block(tip) | test_node.wait_for_block(tip) | ||||
elif i == 2: | elif i == 2: | ||||
test_node.send_get_data([tip]) | test_node.send_get_data([tip]) | ||||
test_node.wait_for_block(tip) | test_node.wait_for_block(tip) | ||||
# This time, try sending either a getheaders to trigger resumption | self.log.debug( | ||||
# of headers announcements, or mine a new block and inv it, also | "This time, try sending either a getheaders to trigger resumption of headers announcements, or mine a new block and inv it, also triggering resumption of headers announcements.") | ||||
# triggering resumption of headers announcements. | |||||
if j == 0: | if j == 0: | ||||
test_node.send_get_headers(locator=[tip], hashstop=0) | test_node.send_get_headers(locator=[tip], hashstop=0) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
else: | else: | ||||
test_node.send_block_inv(tip) | test_node.send_block_inv(tip) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
# New blocks should now be announced with header | # New blocks should now be announced with header | ||||
tip = self.mine_blocks(1) | tip = self.mine_blocks(1) | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |