Skip to content

Instantly share code, notes, and snippets.

@niteshbalusu11
Last active June 13, 2023 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niteshbalusu11/156875f335369f68c7733d4343d9fc54 to your computer and use it in GitHub Desktop.
Save niteshbalusu11/156875f335369f68c7733d4343d9fc54 to your computer and use it in GitHub Desktop.
Chaincode labs exercise

Chaincode labs excercise:

  1. 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
  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()
  1. 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())
            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment