Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_compactblocks.py
Show All 19 Lines | from test_framework.messages import ( | ||||
CInv, | CInv, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
FromHex, | FromHex, | ||||
HeaderAndShortIDs, | HeaderAndShortIDs, | ||||
MSG_BLOCK, | MSG_BLOCK, | ||||
MSG_CMPCT_BLOCK, | |||||
msg_block, | msg_block, | ||||
msg_blocktxn, | msg_blocktxn, | ||||
msg_cmpctblock, | msg_cmpctblock, | ||||
msg_getblocktxn, | msg_getblocktxn, | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | def test_compactblock_construction(self, node, test_node): | ||||
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 | ||||
with mininode_lock: | with mininode_lock: | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
inv = CInv(4, block_hash) # 4 == "CompactBlock" | 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(test_node.received_block_announcement, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
# Now fetch and check the compact block | # Now fetch and check the compact block | ||||
header_and_shortids = None | header_and_shortids = None | ||||
with mininode_lock: | with mininode_lock: | ||||
▲ Show 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | def test_compactblocks_not_at_tip(self, node, test_node): | ||||
new_blocks = [] | new_blocks = [] | ||||
for i in range(MAX_CMPCTBLOCK_DEPTH + 1): | for i in range(MAX_CMPCTBLOCK_DEPTH + 1): | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
new_blocks.append(node.generate(1)[0]) | new_blocks.append(node.generate(1)[0]) | ||||
wait_until(test_node.received_block_announcement, | wait_until(test_node.received_block_announcement, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))])) | test_node.send_message(msg_getdata( | ||||
[CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))])) | |||||
wait_until(lambda: "cmpctblock" in test_node.last_message, | wait_until(lambda: "cmpctblock" in test_node.last_message, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
node.generate(1) | node.generate(1) | ||||
wait_until(test_node.received_block_announcement, | wait_until(test_node.received_block_announcement, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
test_node.clear_block_announcement() | test_node.clear_block_announcement() | ||||
with mininode_lock: | with mininode_lock: | ||||
test_node.last_message.pop("block", None) | test_node.last_message.pop("block", None) | ||||
test_node.send_message(msg_getdata([CInv(4, int(new_blocks[0], 16))])) | test_node.send_message(msg_getdata( | ||||
[CInv(MSG_CMPCT_BLOCK, int(new_blocks[0], 16))])) | |||||
wait_until(lambda: "block" in test_node.last_message, | wait_until(lambda: "block" in test_node.last_message, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
with mininode_lock: | with mininode_lock: | ||||
test_node.last_message["block"].block.calc_sha256() | test_node.last_message["block"].block.calc_sha256() | ||||
assert_equal( | assert_equal( | ||||
test_node.last_message["block"].block.sha256, int(new_blocks[0], 16)) | test_node.last_message["block"].block.sha256, int(new_blocks[0], 16)) | ||||
# Generate an old compactblock, and verify that it's not accepted. | # Generate an old compactblock, and verify that it's not accepted. | ||||
▲ Show 20 Lines • Show All 222 Lines • Show Last 20 Lines |