Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_unrequested_blocks.py
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
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() | ||||
tip_entry_found = False | tip_entry_found = False | ||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == block_h1f.hash: | if x['hash'] == block_h1f.hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
tip_entry_found = True | tip_entry_found = True | ||||
assert(tip_entry_found) | assert tip_entry_found | ||||
assert_raises_rpc_error(-1, "Block not found on disk", | assert_raises_rpc_error(-1, "Block not found on disk", | ||||
self.nodes[0].getblock, block_h1f.hash) | self.nodes[0].getblock, block_h1f.hash) | ||||
# 4. Send another two block that build on the fork. | # 4. Send another two block that build on the fork. | ||||
block_h2f = create_block( | block_h2f = create_block( | ||||
block_h1f.sha256, create_coinbase(2), block_time) | block_h1f.sha256, create_coinbase(2), block_time) | ||||
block_time += 1 | block_time += 1 | ||||
block_h2f.solve() | block_h2f.solve() | ||||
test_node.send_message(msg_block(block_h2f)) | test_node.send_message(msg_block(block_h2f)) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
# Since the earlier block was not processed by node, the new block | # Since the earlier block was not processed by node, the new block | ||||
# can't be fully validated. | # can't be fully validated. | ||||
tip_entry_found = False | tip_entry_found = False | ||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == block_h2f.hash: | if x['hash'] == block_h2f.hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
tip_entry_found = True | tip_entry_found = True | ||||
assert(tip_entry_found) | assert tip_entry_found | ||||
# But this block should be accepted by node since it has equal work. | # But this block should be accepted by node since it has equal work. | ||||
self.nodes[0].getblock(block_h2f.hash) | self.nodes[0].getblock(block_h2f.hash) | ||||
self.log.info("Second height 2 block accepted, but not reorg'ed to") | self.log.info("Second height 2 block accepted, but not reorg'ed to") | ||||
# 4b. Now send another block that builds on the forking chain. | # 4b. Now send another block that builds on the forking chain. | ||||
block_h3 = create_block( | block_h3 = create_block( | ||||
block_h2f.sha256, create_coinbase(3), block_h2f.nTime+1) | block_h2f.sha256, create_coinbase(3), block_h2f.nTime+1) | ||||
block_h3.solve() | block_h3.solve() | ||||
test_node.send_message(msg_block(block_h3)) | test_node.send_message(msg_block(block_h3)) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
# Since the earlier block was not processed by node, the new block | # Since the earlier block was not processed by node, the new block | ||||
# can't be fully validated. | # can't be fully validated. | ||||
tip_entry_found = False | tip_entry_found = False | ||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == block_h3.hash: | if x['hash'] == block_h3.hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
tip_entry_found = True | tip_entry_found = True | ||||
assert(tip_entry_found) | assert tip_entry_found | ||||
self.nodes[0].getblock(block_h3.hash) | self.nodes[0].getblock(block_h3.hash) | ||||
# But this block should be accepted by node since it has more work. | # But this block should be accepted by node since it has more work. | ||||
self.nodes[0].getblock(block_h3.hash) | self.nodes[0].getblock(block_h3.hash) | ||||
self.log.info("Unrequested more-work block accepted") | self.log.info("Unrequested more-work block accepted") | ||||
# 4c. Now mine 288 more blocks and deliver; all should be processed but | # 4c. Now mine 288 more blocks and deliver; all should be processed but | ||||
# the last (height-too-high) on node (as long as it is not missing any headers) | # the last (height-too-high) on node (as long as it is not missing any headers) | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
test_node.send_message(headers_message) | test_node.send_message(headers_message) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
tip_entry_found = False | tip_entry_found = False | ||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == block_292.hash: | if x['hash'] == block_292.hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
tip_entry_found = True | tip_entry_found = True | ||||
assert(tip_entry_found) | assert tip_entry_found | ||||
assert_raises_rpc_error(-1, "Block not found on disk", | assert_raises_rpc_error(-1, "Block not found on disk", | ||||
self.nodes[0].getblock, block_292.hash) | self.nodes[0].getblock, block_292.hash) | ||||
test_node.send_message(msg_block(block_289f)) | test_node.send_message(msg_block(block_289f)) | ||||
test_node.send_message(msg_block(block_290f)) | test_node.send_message(msg_block(block_290f)) | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
self.nodes[0].getblock(block_289f.hash) | self.nodes[0].getblock(block_289f.hash) | ||||
Show All 39 Lines |