Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def setup_network(self): | ||||
self.setup_nodes() | self.setup_nodes() | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections | # Setup the p2p connections | ||||
# test_node connects to node0 (not whitelisted) | # test_node connects to node0 (not whitelisted) | ||||
test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
# min_work_node connects to node1 (whitelisted) | # min_work_node connects to node1 (whitelisted) | ||||
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) | min_work_node = self.nodes[1].add_p2p_connection(P2PInterface()) | ||||
test_node.wait_for_verack() | |||||
min_work_node.wait_for_verack() | |||||
# 1. Have nodes mine a block (leave IBD) | # 1. Have nodes mine a block (leave IBD) | ||||
[n.generate(1) for n in self.nodes] | [n.generate(1) for n in self.nodes] | ||||
tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] | tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes] | ||||
# 2. Send one block that builds on each tip. | # 2. Send one block that builds on each tip. | ||||
# This should be accepted by node0 | # This should be accepted by node0 | ||||
blocks_h2 = [] # the height 2 blocks on each node's chain | blocks_h2 = [] # the height 2 blocks on each node's chain | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# work). | # work). | ||||
# The node should have requested the blocks at some point, so | # The node should have requested the blocks at some point, so | ||||
# disconnect/reconnect first | # disconnect/reconnect first | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
self.nodes[1].disconnect_p2ps() | self.nodes[1].disconnect_p2ps() | ||||
test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
test_node.wait_for_verack() | |||||
test_node.send_message(msg_block(block_h1f)) | test_node.send_message(msg_block(block_h1f)) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
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") | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Only wait a short while so the test doesn't take forever if we do get | # Only wait a short while so the test doesn't take forever if we do get | ||||
# disconnected | # disconnected | ||||
test_node.sync_with_ping(timeout=1) | test_node.sync_with_ping(timeout=1) | ||||
except AssertionError: | except AssertionError: | ||||
test_node.wait_for_disconnect() | test_node.wait_for_disconnect() | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | test_node = self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
test_node.wait_for_verack() | |||||
# We should have failed reorg and switched back to 290 (but have block 291) | # We should have failed reorg and switched back to 290 (but have block 291) | ||||
assert_equal(self.nodes[0].getblockcount(), 290) | assert_equal(self.nodes[0].getblockcount(), 290) | ||||
assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) | assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash) | ||||
assert_equal(self.nodes[0].getblock( | assert_equal(self.nodes[0].getblock( | ||||
block_291.hash)["confirmations"], -1) | block_291.hash)["confirmations"], -1) | ||||
# Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected | # Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected | ||||
Show All 16 Lines |