Hyperledger Development with in 10 days — Day 4


We had successfully setup the fabric network and ran a simple application on it. Today we are going to see the step by step configuration to set up the network. How to deploy the smart code to the network will be explained in this part.
“Make sure all the prerequisites steps are done”
We have already downloaded the Hyperledger Fabric samples into our machine. In last part, we have worked on the fabcar directory and fabcar application.
In this part, we are going to split the “first-network” directory for the network setup. Let’s open the directory now in a terminal as well as in editor.

Start the network

We can see a file named byfn.sh shell script. This shell script uses the Docker images to quickly bootstrap the Fabric network comprised of 4 peers belongs to two different organizations, and an order now which is used to create blocks in the fabric network.
This script also joins the 4 peers to channel which is used to do transactions privately between organizations. It also instantiates chaincode and execute sthe initial transactions against the deployed chaincode in the channel.
if we see the file,
./byfn.sh -h ("run this command in terminal in first-network directory")
Usage:
  byfn.sh -m up|down|restart|generate [-c <channel name>] [-t <timeout>]
  byfn.sh -h|--help (print this message)
    -m <mode> - one of 'up', 'down', 'restart' or 'generate'
      - 'up' - bring up the network with docker-compose up
      - 'down' - clear the network with docker-compose down
      - 'restart' - restart the network
      - 'generate' - generate required certificates and genesis block
    -c <channel name> - config name to use (defaults to "mychannel")
    -t <timeout> - CLI timeout duration in microseconds (defaults to 10000)

Typically, one would first generate the required certificates and
genesis block, then bring up the network. e.g.:

  byfn.sh -m generate -c 
  byfn.sh -m up -c 
If we are not passing the channel argument, default mychannel will be set as the default name.

Generating Network Artifacts:

We know that, to create the network we need to have the orderer node, create the channel, create the genesis block for the channel, join the peers to channel, generating anchor peer for organization(Anchor nodes are the ones which will be visible to other organization nodes)
./byfn.sh -m generate
Above command does,
  1. Generates certificates for all entities
  2. Creates the genesis block
  3. Creates the ordering service
  4. Configuration transaction to configure the Channel

Bring up the network

./byfn.sh -m up
Above command bring the network up.

Bring down the network

./byfn.sh -m down

Now are going to see the tooling, we used to create the network with this shell commands.

Tools:
  1. Crypto Generator
We have used this binary to create the certificates for our network entities like ordered node, a peer node, MSP. Using this certificates only anyone can interact with blockchain(sign/verify). Peer nodes are registered with orderer node, so transaction validations are done easily.
How does it work?
We have written the config file “cryto-config.yaml”, so it takes this file as input and generates the artifacts accordingly.
  • We have created the certificates for Organizations, Components of organizations.
  • Every organizations have unique root certificate(ca-cert), it groups specific (peers, orderers) to that Org.
  • Then it will be a typical network, where participating Member would use it own Certificate Authority.
  • All network components like peers, orderers will be linked to this Member.
  • Transactions are done using entity’s private key, verified by means of a public key.
(ca-certs/Organization Identity) — — — →Linked with (Peers/orderers)(Has its Private key/Sign certs-to do transactions/validate transaction)
In the same file we can see “count” variable, specifies the number of peers in the Organization. Here we have two peers per Org. Just try to understand the specs in that file.
“After we run the cryptogen tool, the generated certificates and keys will be saved to a folder titled crypto-config.”

2. Configuration Transaction Generator

Next tool we are going to use is “configtxgen tool”. Using this we create four configuration artifacts.
  1. Orderer block — genesis block,
  2. channel configuration transaction
  3. And “two anchor peer transactions”
Anchor Peers — A peer node on a channel that all other peers can discover and communicate with. Each Member on a channel has an anchor peer (or multiple anchor peers to prevent the single point of failure), allowing for peers belonging to different Members to discover all existing peers on a channel.
How does it work?
COnfigtxgen tool consumes the file “configtx.yaml” that contains the definitions of our sample network.
There are three members in that,
  1. Orderer Org
  2. Peer Org1 — Managing two peer nodes
  3. Peer Org2 — Managing two peer nodes
We have defined our consortium with two peer orgs named SampleConsortium.
Also, we can see the profiles in that top, One for TwoOrgsOrdererGenesisand for our channel TwoOrgsChannel
These headers are very important because we will pass them as arguments when we create all the network artifacts.
Two additional specifications are, First — Defining the anchor peers (peer0.org1.example.com & peer0.org2.example.com). We point the MSP location for each member, in turn allowing us to store the root org certificates(ca-cert) in the orderer genesis block. Now any network entity communicating with ordering service can have its digital identity verified.
In crypto-config, generated folder peerOrganization//peers/msp/
Now the above context can be easily understood.
Now all the steps we have seen are done through shell startup scripts. If you are able to achieve that it will give you a better understanding.
In next section, we can see all the steps manually launching from the docker images, generating certs, orderer blocks, channel creation etc.

Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Real-Time Web Interface to MQTT using Socket.io and Node.js

Customize radio buttons and checkboxes with CSS sprites