Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_compactblocks.py
Show First 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | class CompactBlocksTest(BitcoinTestFramework): | ||||
# - No compact block announcements unless sendcmpct is sent. | # - No compact block announcements unless sendcmpct is sent. | ||||
# - If sendcmpct is sent with version > preferred_version, the message is ignored. | # - If sendcmpct is sent with version > preferred_version, the message is ignored. | ||||
# - If sendcmpct is sent with boolean 0, then block announcements are not | # - If sendcmpct is sent with boolean 0, then block announcements are not | ||||
# made with compact blocks. | # made with compact blocks. | ||||
# - If sendcmpct is then sent with boolean 1, then new block announcements | # - If sendcmpct is then sent with boolean 1, then new block announcements | ||||
# are made with compact blocks. | # are made with compact blocks. | ||||
# If old_node is passed in, request compact blocks with version=preferred-1 | # If old_node is passed in, request compact blocks with version=preferred-1 | ||||
# and verify that it receives block announcements via compact block. | # and verify that it receives block announcements via compact block. | ||||
def test_sendcmpct(self, node, test_node, preferred_version, old_node=None): | def test_sendcmpct(self, node, test_node, | ||||
preferred_version, old_node=None): | |||||
# Make sure we get a SENDCMPCT message from our peer | # Make sure we get a SENDCMPCT message from our peer | ||||
def received_sendcmpct(): | def received_sendcmpct(): | ||||
return (len(test_node.last_sendcmpct) > 0) | return (len(test_node.last_sendcmpct) > 0) | ||||
wait_until(received_sendcmpct, timeout=30, lock=mininode_lock) | wait_until(received_sendcmpct, timeout=30, lock=mininode_lock) | ||||
with mininode_lock: | with mininode_lock: | ||||
# Check that the first version received is the preferred one | # Check that the first version received is the preferred one | ||||
assert_equal( | assert_equal( | ||||
test_node.last_sendcmpct[0].version, preferred_version) | test_node.last_sendcmpct[0].version, preferred_version) | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | def test_compactblock_construction(self, node, test_node): | ||||
with mininode_lock: | with mininode_lock: | ||||
assert "cmpctblock" in test_node.last_message | assert "cmpctblock" in test_node.last_message | ||||
# Convert the on-the-wire representation to absolute indexes | # Convert the on-the-wire representation to absolute indexes | ||||
header_and_shortids = HeaderAndShortIDs( | header_and_shortids = HeaderAndShortIDs( | ||||
test_node.last_message["cmpctblock"].header_and_shortids) | test_node.last_message["cmpctblock"].header_and_shortids) | ||||
self.check_compactblock_construction_from_block( | self.check_compactblock_construction_from_block( | ||||
header_and_shortids, block_hash, block) | header_and_shortids, block_hash, block) | ||||
def check_compactblock_construction_from_block(self, header_and_shortids, block_hash, block): | def check_compactblock_construction_from_block( | ||||
self, header_and_shortids, block_hash, block): | |||||
# Check that we got the right block! | # Check that we got the right block! | ||||
header_and_shortids.header.calc_sha256() | header_and_shortids.header.calc_sha256() | ||||
assert_equal(header_and_shortids.header.sha256, block_hash) | assert_equal(header_and_shortids.header.sha256, block_hash) | ||||
# Make sure the prefilled_txn appears to have included the coinbase | # Make sure the prefilled_txn appears to have included the coinbase | ||||
assert len(header_and_shortids.prefilled_txn) >= 1 | assert len(header_and_shortids.prefilled_txn) >= 1 | ||||
assert_equal(header_and_shortids.prefilled_txn[0].index, 0) | assert_equal(header_and_shortids.prefilled_txn[0].index, 0) | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | 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) | ||||
msg = msg_sendcmpct() | msg = msg_sendcmpct() | ||||
msg.version = version | msg.version = version | ||||
msg.announce = True | msg.announce = True | ||||
peer.send_and_ping(msg) | peer.send_and_ping(msg) | ||||
def test_compactblock_reconstruction_multiple_peers(self, node, stalling_peer, delivery_peer): | def test_compactblock_reconstruction_multiple_peers( | ||||
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) | ||||
cmpct_block = HeaderAndShortIDs() | cmpct_block = HeaderAndShortIDs() | ||||
cmpct_block.initialize_from_block(block) | cmpct_block.initialize_from_block(block) | ||||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |