Changeset View
Changeset View
Standalone View
Standalone View
test/functional/sendheaders.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 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 p2p connections to node0. One p2p connection should only ever | - Two nodes, two p2p connections to node0. One p2p connection should only ever | ||||
receive inv's (omitted from testing description below, this is our control). | receive inv's (omitted from testing description below, this is our control). | ||||
Second node is used for creating reorgs. | Second node is used for creating reorgs. | ||||
test_null_locators | |||||
================== | |||||
Sends two getheaders requests with null locator values. First request's hashstop | |||||
value refers to validated block, while second request's hashstop value refers to | |||||
a block which hasn't been validated. Verifies only the first request returns | |||||
headers. | |||||
test_nonnull_locators | |||||
===================== | |||||
Part 1: No headers announcements before "sendheaders" | Part 1: No headers announcements before "sendheaders" | ||||
a. node mines a block [expect: inv] | a. node mines a block [expect: inv] | ||||
send getdata for the block [expect: block] | send getdata for the block [expect: block] | ||||
b. node mines another block [expect: inv] | b. node mines another block [expect: inv] | ||||
send getheaders and getdata [expect: headers, then block] | send getheaders and getdata [expect: headers, then block] | ||||
c. node mines another block [expect: inv] | c. node mines another block [expect: inv] | ||||
peer mines a block, announces with header [expect: getdata] | peer mines a block, announces with header [expect: getdata] | ||||
d. node mines another block [expect: inv] | d. node mines another block [expect: inv] | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Test logic begins here | # Test logic begins here | ||||
inv_node.wait_for_verack() | inv_node.wait_for_verack() | ||||
test_node.wait_for_verack() | test_node.wait_for_verack() | ||||
# Ensure verack's have been processed by our peer | # Ensure verack's have been processed by our peer | ||||
inv_node.sync_with_ping() | inv_node.sync_with_ping() | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
self.test_null_locators(test_node) | |||||
self.test_nonnull_locators(test_node, inv_node) | |||||
def test_null_locators(self, test_node): | |||||
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0]) | |||||
tip_hash = int(tip["hash"], 16) | |||||
self.log.info( | |||||
"Verify getheaders with null locator and valid hashstop returns headers.") | |||||
test_node.clear_last_announcement() | |||||
test_node.get_headers(locator=[], hashstop=tip_hash) | |||||
assert_equal(test_node.check_last_announcement( | |||||
headers=[tip_hash]), True) | |||||
self.log.info( | |||||
"Verify getheaders with null locator and invalid hashstop does not return headers.") | |||||
block = create_block(int(tip["hash"], 16), create_coinbase( | |||||
tip["height"] + 1), tip["mediantime"] + 1) | |||||
block.solve() | |||||
test_node.send_header_for_blocks([block]) | |||||
test_node.clear_last_announcement() | |||||
test_node.get_headers(locator=[], hashstop=int(block.hash, 16)) | |||||
test_node.sync_with_ping() | |||||
assert_equal(test_node.block_announced, False) | |||||
test_node.send_message(msg_block(block)) | |||||
def test_nonnull_locators(self, test_node, inv_node): | |||||
tip = int(self.nodes[0].getbestblockhash(), 16) | tip = int(self.nodes[0].getbestblockhash(), 16) | ||||
# PART 1 | # PART 1 | ||||
# 1. Mine a block; expect inv announcements each time | # 1. Mine a block; expect inv announcements each time | ||||
self.log.info( | self.log.info( | ||||
"Part 1: headers don't start before sendheaders message...") | "Part 1: headers don't start before sendheaders message...") | ||||
for i in range(4): | for i in range(4): | ||||
old_tip = tip | old_tip = tip | ||||
▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines |