Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_tx_with_script, | create_tx_with_script, | ||||
) | ) | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlockHeader, | CBlockHeader, | ||||
CInv, | CInv, | ||||
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, | mininode_lock, | ||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"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 mininode_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(2, 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 mininode_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") | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |