Kapil Sachdeva

Bootstrapping the Hyperledger Fabric Network (Part 5)


Here is a brief summary of what we have accomplished so far:

  • Part 1 - Generated the crypto material for the various participants.
  • Part 2 - Generated the genesis block for the Orderer node and started ordering service (solo node).
  • Part 3 - Generated the configuration transaction block to create a new channel.
  • Part 4 - Signed the configuration block and created the new channel.

We have created a channel and ordering service has a record of it as well but we need instruct the peers to join the channel and before we could do that we need to start the peer containers as well.

When you used npm run start-orderer it is starting the docker-compose configuration specified in docker-compose-orderer.yaml file.

I have added a new docker-compose.yaml file that specifies the peers to start and as well as inherit the configuration for orderer from docker-compose-orderer.yaml file. So from now onwards we would not use the npm run start-orderer command line. In order to start all the containers you would use following command:

# Deletes the production folder & Start all the containers (orderer, and peers of all organizations)
npm run start-containers

To stop all the containers use:

# Stop all the containers
npm run stop-containers

After successful issuance of npm run start-containers you should be able to see following by issuing docker ps -a command

$ docker ps -a
CONTAINER ID        IMAGE                        COMMAND             CREATED             STATUS              PORTS                                              NAMES
53c08da6ccbc        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 6 seconds        0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.ksachdeva-exp.com
e556c2066079        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 6 seconds        0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp     peer0.org2.ksachdeva-exp.com
7115ff0db9be        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 6 seconds        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp     peer0.org1.ksachdeva-exp.com
ecdb93e7e8d6        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 5 seconds        0.0.0.0:12051->7051/tcp, 0.0.0.0:12053->7053/tcp   peer1.org3.ksachdeva-exp.com
9c8b364b0b50        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 7 seconds        0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp     peer1.org1.ksachdeva-exp.com
509ce81e3748        hyperledger/fabric-orderer   "orderer"           9 seconds ago       Up 7 seconds        0.0.0.0:7050->7050/tcp                             orderer.ksachdeva-exp.com
45de91356f00        hyperledger/fabric-peer      "peer node start"   9 seconds ago       Up 7 seconds        0.0.0.0:11051->7051/tcp, 0.0.0.0:11053->7053/tcp   peer0.org3.ksachdeva-exp.com

So now we have 2 peers per organization and 1 orderer node running in the docker containers.

In order to instruct the peers to join the channel here are the steps we are supposed to perform for every organization:

  1. Create the Client object that has the user context set to the admin of the desired organization.
  2. Create the Channel object and the provide the instance of Orderer to it.
  3. Channel would obtain the genesis block from the ordering service.
  4. Get the Peer objects for the desired organization.
  5. Send the transactionId, genesis block of channel, list of peers to Channel object

Above mentioned steps are demonstrated by the src/join-channel.ts script and here is the relevant code snippets that are descriptive enough to understand what is happening.

async function joinOrgPeersToChannel(org: Organization) {

  const client = await getClient(org);
  const orderer = await getOrderer(client);

  console.log('Creating a Channel object ..');
  const channel = client.newChannel(config.CHANNEL_NAME);

  console.log('Specifying the orderer to connect to ..');
  channel.addOrderer(orderer);

  console.log('Getting the genesis block for the ${CHANNEL_NAME} ..');
  const genesis_block = await channel.getGenesisBlock({
    txId: client.newTransactionID()
  });

  console.log('Getting the peers ..');
  const peers = await getPeers(client, org);

  const proposalResponse = await channel.joinChannel({
    txId: client.newTransactionID(),
    block: genesis_block,
    targets: peers
  });

  console.log(proposalResponse);
}

async function main() {

  await joinOrgPeersToChannel(Organization.ORG1);
  await joinOrgPeersToChannel(Organization.ORG2);
  await joinOrgPeersToChannel(Organization.ORG3);

}

main();

Running the script src/join-channel.ts can be done by issuing following command:

npm run join-channel

Look in the production folder and you should see various new folders & files that have been created. Majority of them are leveldb databases so the contents of the files would not make sense.


Similar Posts

Comments