Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_compactblocks.py
Show First 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | def test_compactblock_construction(self, node, test_node): | ||||
# Store the raw block in our internal format. | # Store the raw block in our internal format. | ||||
block = FromHex(CBlock(), node.getblock( | block = FromHex(CBlock(), node.getblock( | ||||
"{:064x}".format(block_hash), False)) | "{:064x}".format(block_hash), False)) | ||||
for tx in block.vtx: | for tx in block.vtx: | ||||
tx.calc_sha256() | tx.calc_sha256() | ||||
block.rehash() | block.rehash() | ||||
# Wait until the block was announced (via compact blocks) | # Wait until the block was announced (via compact blocks) | ||||
wait_until(test_node.received_block_announcement, | wait_until(lambda: "cmpctblock" in test_node.last_message, | ||||
timeout=30, lock=p2p_lock) | timeout=30, lock=p2p_lock) | ||||
# Now fetch and check the compact block | # Now fetch and check the compact block | ||||
header_and_shortids = None | header_and_shortids = None | ||||
with p2p_lock: | with p2p_lock: | ||||
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) | ||||
# Now fetch the compact block using a normal non-announce getdata | # Now fetch the compact block using a normal non-announce getdata | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
inv = CInv(MSG_CMPCT_BLOCK, block_hash) | inv = CInv(MSG_CMPCT_BLOCK, block_hash) | ||||
test_node.send_message(msg_getdata([inv])) | test_node.send_message(msg_getdata([inv])) | ||||
wait_until(test_node.received_block_announcement, | wait_until(lambda: "cmpctblock" in test_node.last_message, | ||||
timeout=30, lock=p2p_lock) | timeout=30, lock=p2p_lock) | ||||
# Now fetch and check the compact block | # Now fetch and check the compact block | ||||
header_and_shortids = None | header_and_shortids = None | ||||
with p2p_lock: | with p2p_lock: | ||||
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( | def check_compactblock_construction_from_block( | ||||
self, header_and_shortids, block_hash, block): | self, header_and_shortids, block_hash, block): | ||||
▲ Show 20 Lines • Show All 365 Lines • ▼ Show 20 Lines | def test_end_to_end_block_relay(self, node, listeners): | ||||
block, _ = self.build_block_with_transactions(node, utxo, 10) | block, _ = self.build_block_with_transactions(node, utxo, 10) | ||||
[listener.clear_block_announcement() for listener in listeners] | [listener.clear_block_announcement() for listener in listeners] | ||||
node.submitblock(ToHex(block)) | node.submitblock(ToHex(block)) | ||||
for listener in listeners: | for listener in listeners: | ||||
wait_until(lambda: listener.received_block_announcement(), | wait_until(lambda: "cmpctblock" in listener.last_message, | ||||
timeout=30, lock=p2p_lock) | timeout=30, lock=p2p_lock) | ||||
with p2p_lock: | with p2p_lock: | ||||
for listener in listeners: | for listener in listeners: | ||||
assert "cmpctblock" in listener.last_message | |||||
listener.last_message["cmpctblock"].header_and_shortids.header.calc_sha256( | listener.last_message["cmpctblock"].header_and_shortids.header.calc_sha256( | ||||
) | ) | ||||
assert_equal( | assert_equal( | ||||
listener.last_message["cmpctblock"].header_and_shortids.header.sha256, block.sha256) | listener.last_message["cmpctblock"].header_and_shortids.header.sha256, block.sha256) | ||||
# Test that we don't get disconnected if we relay a compact block with valid header, | # Test that we don't get disconnected if we relay a compact block with valid header, | ||||
# but invalid transactions. | # but invalid transactions. | ||||
def test_invalid_tx_in_compactblock(self, node, test_node): | def test_invalid_tx_in_compactblock(self, node, test_node): | ||||
▲ Show 20 Lines • Show All 170 Lines • Show Last 20 Lines |