Config Generator In Hyperledger Fabric

Table of contents
Reading Time: 2 minutes

Every Ledger starts with a transaction kept inside the block but what will be the first block? Well, the answer is genesis block. Now, another question how to generate this genesis block? For this part we can use the configtxgen tool to generate the initial or genesis block.
The tool is primarily focused on generating the genesis block for bootstrapping the orderer, but it is intended to be enhanced in the future for generating new channel configurations as well as reconfiguring existing channels.

This tool takes the parameter in form of the configtx.yaml file. You can find the sample configtx.yaml file under the directory fabric/sampleconfig/configtx.yaml on github.

Lets explore the configtx.yaml file. This file mainly contains the following sections:-

  • The Profiles section.
  • The Organizations section.
  • The default sections.

The Profile Section :- Profiles can make a good starting point for construction a real deployment profile.Profiles may explicitly declare all configuration, but usually inherit configuration from the defaults Section.

Sample Profile Configuration:-



This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters


Profiles:
OneOrgOrdererGenesis:
Orderer:
<<: *OrdererDefaults
Organizations:
– *OrdererOrg
Consortiums:
SampleConsortium:
Organizations:
– *Org1
OneOrgChannel:
Consortium: SampleConsortium
Application:
<<: *ApplicationDefaults
Organizations:
– *Org1
view raw

Profiles.yaml

hosted with ❤ by GitHub

The Organizations Section :- This section includes a single reference to the MSP definition. Each element in the Organizations section should be tagged with an anchor label such as & orgName which will allow the definition to be referenced in the Profiles sections.

Sample Organizations Configuration:-



This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters


Organizations:
– &OrdererOrg
Name: OrdererOrg
ID: OrdererMSP
MSPDir: crypto-config/ordererOrganizations/example.com/msp
– &Org1
Name: Org1MSP
ID: Org1MSP
MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
AnchorPeers:
– Host: peer0.org1.example.com
Port: 7051

The Default Section :- There are default sections for Orderer and Application configuration, these include attributes like BatchTimeout and are generally used as the base inherited values for the profiles.

Sample Default Configuration:-



This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters


Application: &ApplicationDefaults
Organizations:
Orderer: &OrdererDefaults
OrdererType: solo # Available types are "solo" and "kafka"
Addresses:
– orderer.example.com:7050
BatchTimeout: 2s # Batch Timeout: The amount of time to wait before creating a batch
BatchSize: # Batch Size: Controls the number of messages batched into a block
MaxMessageCount: 10 # Max Message Count: The maximum number of messages to permit in a batch
AbsoluteMaxBytes: 99 MB
PreferredMaxBytes: 512 KB
Kafka:
Brokers:
– 127.0.0.1:9092
Organizations:
view raw

Default.yaml

hosted with ❤ by GitHub

Generating the genesis block for the orderer We can use the configtxgen tool to generate the genesis block for the orderer.

configtxgen -profile -outputBlock orderer_genesisblock.pb

An orderer_genesisblock.pb file is generated to the current directory.This genesis block is used to bootstrap the ordering system channel, which the orderers use to authorize and orchestrate creation of other channels. By default, the channel ID encoded into the genesis block by configtxgen will be testchainid. It is recommended that you modify this identifier to something which will be globally unique.

Creating the Channel For creating the channel we need the following things:-

  • Profile Name
  • Channel Name
  • Tx FileName

configtxgen tool is needed for the creating of channel. We can use the following command to generate the channel.

configtxgen -profile -channelID -outputCreateChannelTx

This will output a marshaled Envelope message which may be sent to broadcast to create a channel.

We can also review the configuration using the following fashion :-

  • Inspecting the Block
  • Inspecting the Channel

Inspecting the Block:-

An Inspect flag is available for inspecting the Block status. -inspectBlock used with the configtxgen tool.

configtxgen -inspectBlock

The output will the JSON that contains all the relevant information required for the Inspection of the block.

Inspecting the Channel:-

An Inspect flag is available for inspecting the Channel status. -inspectChannelCreateTx used with the configtxgen tool.

configtxgen -inspectChannelCreateTx

The output will be the JSON that contains the information about the Channel.

You may even wish to combine the inspection with generation. For example:-

configtxgen -channelID foo -outputBlock foo_genesisblock.pb -inspectBlock foo_genesisblock.pb

Thats all for the Config Generator for the Transaction. Stay Tuned & Happy Coding 🙂

References:- HyperLedger Official Documentation


knoldus-advt-sticker


Written by 

Principal Architect at Knoldus Inc

1 thought on “Config Generator In Hyperledger Fabric3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading