Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_compactblocks.py
Show First 20 Lines • Show All 409 Lines • ▼ Show 20 Lines | class CompactBlocksTest(BitcoinTestFramework): | ||||
# Test that bitcoind requests compact blocks when we announce new blocks | # Test that bitcoind requests compact blocks when we announce new blocks | ||||
# via header or inv, and that responding to getblocktxn causes the block | # via header or inv, and that responding to getblocktxn causes the block | ||||
# to be successfully reconstructed. | # to be successfully reconstructed. | ||||
def test_compactblock_requests(self, node, test_node, version): | def test_compactblock_requests(self, node, test_node, version): | ||||
# Try announcing a block with an inv or header, expect a compactblock | # Try announcing a block with an inv or header, expect a compactblock | ||||
# request | # request | ||||
for announce in ["inv", "header"]: | for announce in ["inv", "header"]: | ||||
block = self.build_block_on_tip(node) | block = self.build_block_on_tip(node) | ||||
with mininode_lock: | |||||
test_node.last_message.pop("getdata", None) | |||||
if announce == "inv": | if announce == "inv": | ||||
test_node.send_message(msg_inv([CInv(2, block.sha256)])) | test_node.send_message(msg_inv([CInv(2, block.sha256)])) | ||||
wait_until(lambda: "getheaders" in test_node.last_message, | wait_until(lambda: "getheaders" in test_node.last_message, | ||||
timeout=30, lock=mininode_lock) | timeout=30, lock=mininode_lock) | ||||
test_node.send_header_for_blocks([block]) | test_node.send_header_for_blocks([block]) | ||||
else: | else: | ||||
test_node.send_header_for_blocks([block]) | test_node.send_header_for_blocks([block]) | ||||
wait_until(lambda: "getdata" in test_node.last_message, | test_node.wait_for_getdata([block.sha256], timeout=30) | ||||
timeout=30, lock=mininode_lock) | |||||
assert_equal(len(test_node.last_message["getdata"].inv), 1) | |||||
assert_equal(test_node.last_message["getdata"].inv[0].type, 4) | assert_equal(test_node.last_message["getdata"].inv[0].type, 4) | ||||
assert_equal( | |||||
test_node.last_message["getdata"].inv[0].hash, block.sha256) | |||||
# Send back a compactblock message that omits the coinbase | # Send back a compactblock message that omits the coinbase | ||||
comp_block = HeaderAndShortIDs() | comp_block = HeaderAndShortIDs() | ||||
comp_block.header = CBlockHeader(block) | comp_block.header = CBlockHeader(block) | ||||
comp_block.nonce = 0 | comp_block.nonce = 0 | ||||
[k0, k1] = comp_block.get_siphash_keys() | [k0, k1] = comp_block.get_siphash_keys() | ||||
coinbase_hash = block.vtx[0].sha256 | coinbase_hash = block.vtx[0].sha256 | ||||
comp_block.shortids = [ | comp_block.shortids = [ | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | def test_incorrect_blocktxn_response(self, node, test_node, version): | ||||
msg.block_transactions = BlockTransactions( | msg.block_transactions = BlockTransactions( | ||||
block.sha256, [ordered_txs[5]] + ordered_txs[7:]) | block.sha256, [ordered_txs[5]] + ordered_txs[7:]) | ||||
test_node.send_and_ping(msg) | test_node.send_and_ping(msg) | ||||
# Tip should not have updated | # Tip should not have updated | ||||
assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock) | assert_equal(int(node.getbestblockhash(), 16), block.hashPrevBlock) | ||||
# We should receive a getdata request | # We should receive a getdata request | ||||
wait_until(lambda: "getdata" in test_node.last_message, | test_node.wait_for_getdata([block.sha256], timeout=10) | ||||
timeout=10, lock=mininode_lock) | |||||
assert_equal(len(test_node.last_message["getdata"].inv), 1) | |||||
assert test_node.last_message["getdata"].inv[0].type == 2 | assert test_node.last_message["getdata"].inv[0].type == 2 | ||||
assert_equal( | |||||
test_node.last_message["getdata"].inv[0].hash, block.sha256) | |||||
# Deliver the block | # Deliver the block | ||||
test_node.send_and_ping(msg_block(block)) | test_node.send_and_ping(msg_block(block)) | ||||
assert_equal(int(node.getbestblockhash(), 16), block.sha256) | assert_equal(int(node.getbestblockhash(), 16), block.sha256) | ||||
def test_getblocktxn_handler(self, node, test_node, version): | def test_getblocktxn_handler(self, node, test_node, version): | ||||
# bitcoind will not send blocktxn responses for blocks whose height is | # bitcoind will not send blocktxn responses for blocks whose height is | ||||
# more than 10 blocks deep. | # more than 10 blocks deep. | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |