Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | from test_framework.messages import ( | ||||
CBlockHeader, | CBlockHeader, | ||||
CInv, | CInv, | ||||
MSG_BLOCK, | MSG_BLOCK, | ||||
msg_block, | msg_block, | ||||
msg_headers, | msg_headers, | ||||
msg_inv, | msg_inv, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
mininode_lock, | p2p_lock, | ||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
test_node.send_and_ping(msg_block(block_h1f)) | test_node.send_and_ping(msg_block(block_h1f)) | ||||
assert_equal(self.nodes[0].getblockcount(), 2) | assert_equal(self.nodes[0].getblockcount(), 2) | ||||
self.log.info( | self.log.info( | ||||
"Unrequested block that would complete more-work chain was ignored") | "Unrequested block that would complete more-work chain was ignored") | ||||
# 6. Try to get node to request the missing block. | # 6. Try to get node to request the missing block. | ||||
# Poke the node with an inv for block at height 3 and see if that | # Poke the node with an inv for block at height 3 and see if that | ||||
# triggers a getdata on block 2 (it should if block 2 is missing). | # triggers a getdata on block 2 (it should if block 2 is missing). | ||||
with mininode_lock: | with p2p_lock: | ||||
# Clear state so we can check the getdata request | # Clear state so we can check the getdata request | ||||
test_node.last_message.pop("getdata", None) | test_node.last_message.pop("getdata", None) | ||||
test_node.send_message(msg_inv([CInv(MSG_BLOCK, block_h3.sha256)])) | test_node.send_message(msg_inv([CInv(MSG_BLOCK, block_h3.sha256)])) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
with mininode_lock: | with p2p_lock: | ||||
getdata = test_node.last_message["getdata"] | getdata = test_node.last_message["getdata"] | ||||
# Check that the getdata includes the right block | # Check that the getdata includes the right block | ||||
assert_equal(getdata.inv[0].hash, block_h1f.sha256) | assert_equal(getdata.inv[0].hash, block_h1f.sha256) | ||||
self.log.info("Inv at tip triggered getdata for unprocessed block") | self.log.info("Inv at tip triggered getdata for unprocessed block") | ||||
# 7. Send the missing block for the third time (now it is requested) | # 7. Send the missing block for the third time (now it is requested) | ||||
test_node.send_and_ping(msg_block(block_h1f)) | test_node.send_and_ping(msg_block(block_h1f)) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |