Chaincode labs excercise:
- Increase the for loop count by 1
for _ in range(11):
# Use the blocktools functionality to manually build a block.
# Calling the generate() rpc is easier, but this allows us to exactly
# control the blocks and transactions.
block = create_block(self.tip, create_coinbase(height+1), self.block_time)
block.solve()
block_message = msg_block(block)
# Send message is used to send a P2P message to the node over our P2PInterface
peer_messaging.send_message(block_message)
self.tip = block.sha256
blocks.append(self.tip)
self.block_time += 1
height += 1
- Check if the node[1] hit blockheight 12 instead of 11. Connect node[1] and node[2] and sync them.
self.log.info("Wait for node1 to reach current tip (height 12) using RPC")
self.nodes[1].waitforblockheight(12)
self.log.info("Connect node2 and node1")
self.connect_nodes(1, 2)
self.log.info("Wait for node2 to receive all the blocks from node1")
self.sync_all()
- Once the nodes sync, log the block height on node[2]
self.log.info("check node[2] hit blockheight 12")
self.log.info("node[2] block height is %s ", self.nodes[2].getblockcount())
This was just the faster way to do it, we could also just mine the block separately after the for loop
# Disconnect nodes
self.nodes[0].disconnect_p2ps()
# Create a block, solve it and send a peer_message
block = create_block(self.tip, create_coinbase(height+1), self.block_time)
block.solve()
block_message = msg_block(block)
peer_messaging.send_message(block_message)
self.tip = block.sha256
blocks.append(self.tip)
self.block_time += 1
height += 1
# Connnect nodes again and sync them
self.connect_nodes(1, 2)
self.sync_all()
# Check the block count on node2
self.log.info("node[2] block height is %s ", self.nodes[2].getblockcount())