Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p-acceptblock.py
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
for i in range(2): | for i in range(2): | ||||
blocks_h2.append( | blocks_h2.append( | ||||
create_block(tips[i], create_coinbase(2), block_time)) | create_block(tips[i], create_coinbase(2), block_time)) | ||||
blocks_h2[i].solve() | blocks_h2[i].solve() | ||||
block_time += 1 | block_time += 1 | ||||
test_node.send_message(msg_block(blocks_h2[0])) | test_node.send_message(msg_block(blocks_h2[0])) | ||||
white_node.send_message(msg_block(blocks_h2[1])) | white_node.send_message(msg_block(blocks_h2[1])) | ||||
[x.sync_with_ping() for x in [test_node, white_node]] | for x in [test_node, white_node]: | ||||
x.sync_with_ping() | |||||
assert_equal(self.nodes[0].getblockcount(), 2) | assert_equal(self.nodes[0].getblockcount(), 2) | ||||
assert_equal(self.nodes[1].getblockcount(), 2) | assert_equal(self.nodes[1].getblockcount(), 2) | ||||
self.log.info("First height 2 block accepted by both nodes") | self.log.info("First height 2 block accepted by both nodes") | ||||
# 3. Send another block that builds on the original tip. | # 3. Send another block that builds on the original tip. | ||||
blocks_h2f = [] # Blocks at height 2 that fork off the main chain | blocks_h2f = [] # Blocks at height 2 that fork off the main chain | ||||
for i in range(2): | for i in range(2): | ||||
blocks_h2f.append( | blocks_h2f.append( | ||||
create_block(tips[i], create_coinbase(2), blocks_h2[i].nTime + 1)) | create_block(tips[i], create_coinbase(2), blocks_h2[i].nTime + 1)) | ||||
blocks_h2f[i].solve() | blocks_h2f[i].solve() | ||||
test_node.send_message(msg_block(blocks_h2f[0])) | test_node.send_message(msg_block(blocks_h2f[0])) | ||||
white_node.send_message(msg_block(blocks_h2f[1])) | white_node.send_message(msg_block(blocks_h2f[1])) | ||||
[x.sync_with_ping() for x in [test_node, white_node]] | for x in [test_node, white_node]: | ||||
x.sync_with_ping() | |||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == blocks_h2f[0].hash: | if x['hash'] == blocks_h2f[0].hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
for x in self.nodes[1].getchaintips(): | for x in self.nodes[1].getchaintips(): | ||||
if x['hash'] == blocks_h2f[1].hash: | if x['hash'] == blocks_h2f[1].hash: | ||||
assert_equal(x['status'], "valid-headers") | assert_equal(x['status'], "valid-headers") | ||||
self.log.info( | self.log.info( | ||||
"Second height 2 block accepted only from whitelisted peer") | "Second height 2 block accepted only from whitelisted peer") | ||||
# 4. Now send another block that builds on the forking chain. | # 4. Now send another block that builds on the forking chain. | ||||
blocks_h3 = [] | blocks_h3 = [] | ||||
for i in range(2): | for i in range(2): | ||||
blocks_h3.append( | blocks_h3.append( | ||||
create_block(blocks_h2f[i].sha256, create_coinbase(3), blocks_h2f[i].nTime + 1)) | create_block(blocks_h2f[i].sha256, create_coinbase(3), blocks_h2f[i].nTime + 1)) | ||||
blocks_h3[i].solve() | blocks_h3[i].solve() | ||||
test_node.send_message(msg_block(blocks_h3[0])) | test_node.send_message(msg_block(blocks_h3[0])) | ||||
white_node.send_message(msg_block(blocks_h3[1])) | white_node.send_message(msg_block(blocks_h3[1])) | ||||
[x.sync_with_ping() for x in [test_node, white_node]] | for x in [test_node, white_node]: | ||||
x.sync_with_ping() | |||||
# Since the earlier block was not processed by node0, the new block | # Since the earlier block was not processed by node0, the new block | ||||
# can't be fully validated. | # can't be fully validated. | ||||
for x in self.nodes[0].getchaintips(): | for x in self.nodes[0].getchaintips(): | ||||
if x['hash'] == blocks_h3[0].hash: | if x['hash'] == blocks_h3[0].hash: | ||||
assert_equal(x['status'], "headers-only") | assert_equal(x['status'], "headers-only") | ||||
# But this block should be accepted by node0 since it has more work. | # But this block should be accepted by node0 since it has more work. | ||||
self.nodes[0].getblock(blocks_h3[0].hash) | self.nodes[0].getblock(blocks_h3[0].hash) | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |