Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_compactblocks.py
Show First 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | def test_sendcmpct(self, node, test_node, | ||||
node, test_node, lambda p: "cmpctblock" not in p.last_message and "inv" in p.last_message) | node, test_node, lambda p: "cmpctblock" not in p.last_message and "inv" in p.last_message) | ||||
# Test a few ways of using sendcmpct that should NOT | # Test a few ways of using sendcmpct that should NOT | ||||
# result in compact block announcements. | # result in compact block announcements. | ||||
# Before each test, sync the headers chain. | # Before each test, sync the headers chain. | ||||
test_node.request_headers_and_sync(locator=[tip]) | test_node.request_headers_and_sync(locator=[tip]) | ||||
# Now try a SENDCMPCT message with too-high version | # Now try a SENDCMPCT message with too-high version | ||||
sendcmpct = msg_sendcmpct() | test_node.send_and_ping(msg_sendcmpct(announce=True, version=999)) | ||||
sendcmpct.version = 999 # was: preferred_version+1 | |||||
sendcmpct.announce = True | |||||
test_node.send_and_ping(sendcmpct) | |||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" not in p.last_message) | node, test_node, lambda p: "cmpctblock" not in p.last_message) | ||||
# Headers sync before next test. | # Headers sync before next test. | ||||
test_node.request_headers_and_sync(locator=[tip]) | test_node.request_headers_and_sync(locator=[tip]) | ||||
# Now try a SENDCMPCT message with valid version, but announce=False | # Now try a SENDCMPCT message with valid version, but announce=False | ||||
sendcmpct.version = preferred_version | test_node.send_and_ping(msg_sendcmpct(announce=False, | ||||
sendcmpct.announce = False | version=preferred_version)) | ||||
test_node.send_and_ping(sendcmpct) | |||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" not in p.last_message) | node, test_node, lambda p: "cmpctblock" not in p.last_message) | ||||
# Headers sync before next test. | # Headers sync before next test. | ||||
test_node.request_headers_and_sync(locator=[tip]) | test_node.request_headers_and_sync(locator=[tip]) | ||||
# Finally, try a SENDCMPCT message with announce=True | # Finally, try a SENDCMPCT message with announce=True | ||||
sendcmpct.version = preferred_version | test_node.send_and_ping(msg_sendcmpct(announce=True, | ||||
sendcmpct.announce = True | version=preferred_version)) | ||||
test_node.send_and_ping(sendcmpct) | |||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" in p.last_message) | node, test_node, lambda p: "cmpctblock" in p.last_message) | ||||
# Try one more time (no headers sync should be needed!) | # Try one more time (no headers sync should be needed!) | ||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" in p.last_message) | node, test_node, lambda p: "cmpctblock" in p.last_message) | ||||
# Try one more time, after turning on sendheaders | # Try one more time, after turning on sendheaders | ||||
test_node.send_and_ping(msg_sendheaders()) | test_node.send_and_ping(msg_sendheaders()) | ||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" in p.last_message) | node, test_node, lambda p: "cmpctblock" in p.last_message) | ||||
# Try one more time, after sending a version-1, announce=false message. | # Try one more time, after sending a version-1, announce=false message. | ||||
sendcmpct.version = preferred_version - 1 | test_node.send_and_ping(msg_sendcmpct(announce=False, | ||||
sendcmpct.announce = False | version=preferred_version - 1)) | ||||
test_node.send_and_ping(sendcmpct) | |||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" in p.last_message) | node, test_node, lambda p: "cmpctblock" in p.last_message) | ||||
# Now turn off announcements | # Now turn off announcements | ||||
sendcmpct.version = preferred_version | test_node.send_and_ping(msg_sendcmpct(announce=False, | ||||
sendcmpct.announce = False | version=preferred_version)) | ||||
test_node.send_and_ping(sendcmpct) | |||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, test_node, lambda p: "cmpctblock" not in p.last_message and "headers" in p.last_message) | node, test_node, lambda p: "cmpctblock" not in p.last_message and "headers" in p.last_message) | ||||
if old_node is not None: | if old_node is not None: | ||||
# Verify that a peer using an older protocol version can receive | # Verify that a peer using an older protocol version can receive | ||||
# announcements from this node. | # announcements from this node. | ||||
sendcmpct.version = 1 # preferred_version-1 | old_node.send_and_ping(msg_sendcmpct(announce=True, version=1)) | ||||
sendcmpct.announce = True | |||||
old_node.send_and_ping(sendcmpct) | |||||
# Header sync | # Header sync | ||||
old_node.request_headers_and_sync(locator=[tip]) | old_node.request_headers_and_sync(locator=[tip]) | ||||
check_announcement_of_new_block( | check_announcement_of_new_block( | ||||
node, old_node, lambda p: "cmpctblock" in p.last_message) | node, old_node, lambda p: "cmpctblock" in p.last_message) | ||||
# This test actually causes bitcoind to (reasonably!) disconnect us, so do | # This test actually causes bitcoind to (reasonably!) disconnect us, so do | ||||
# this last. | # this last. | ||||
def test_invalid_cmpctblock_message(self): | def test_invalid_cmpctblock_message(self): | ||||
▲ Show 20 Lines • Show All 477 Lines • ▼ Show 20 Lines | def test_invalid_tx_in_compactblock(self, node, test_node): | ||||
assert int(node.getbestblockhash(), 16) is not block.sha256 | assert int(node.getbestblockhash(), 16) is not block.sha256 | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
# Helper for enabling cb announcements | # Helper for enabling cb announcements | ||||
# Send the sendcmpct request and sync headers | # Send the sendcmpct request and sync headers | ||||
def request_cb_announcements(self, peer, node, version=1): | def request_cb_announcements(self, peer, node, version=1): | ||||
tip = node.getbestblockhash() | tip = node.getbestblockhash() | ||||
peer.get_headers(locator=[int(tip, 16)], hashstop=0) | peer.get_headers(locator=[int(tip, 16)], hashstop=0) | ||||
peer.send_and_ping(msg_sendcmpct(announce=True, version=version)) | |||||
msg = msg_sendcmpct() | |||||
msg.version = version | |||||
msg.announce = True | |||||
peer.send_and_ping(msg) | |||||
def test_compactblock_reconstruction_multiple_peers( | def test_compactblock_reconstruction_multiple_peers( | ||||
self, node, stalling_peer, delivery_peer): | self, node, stalling_peer, delivery_peer): | ||||
assert len(self.utxos) | assert len(self.utxos) | ||||
def announce_cmpct_block(node, peer): | def announce_cmpct_block(node, peer): | ||||
utxo = self.utxos.pop(0) | utxo = self.utxos.pop(0) | ||||
block, _ = self.build_block_with_transactions(node, utxo, 5) | block, _ = self.build_block_with_transactions(node, utxo, 5) | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |