Generating channel artifacts
To create a network according to an organization's structure, and to bootstrap a channel, we will need to generate the following artifacts:
- A genesis block, containing organization-specific certificates that serve to initialize the Fabric blockchain.
- Channel configuration information.
- Anchor peer configurations for each organization. An anchor peer serves as a fulcrum within an organization, for cross-organization ledger syncing using the Fabric gossip protocol.
Like the crypto-config.yaml file, channel properties are specified in a file labeled configtx.yaml, which in our source code can be found in the network folder. The high-level organization of our trade network can be found in the Profiles section as follows:
Profiles:
FourOrgsTradeOrdererGenesis:
Capabilities:
<<: *ChannelCapabilities
Orderer:
<<: *OrdererDefaults
Organizations:
- *TradeOrdererOrg
Capabilities:
<<: *OrdererCapabilities
Consortiums:
TradeConsortium:
Organizations:
- *ExporterOrg
- *ImporterOrg
- *CarrierOrg
- *RegulatorOrg
FourOrgsTradeChannel:
Consortium: TradeConsortium
Application:
<<: *ApplicationDefaults
Organizations:
- *ExporterOrg
- *ImporterOrg
- *CarrierOrg
- *RegulatorOrg
Capabilities:
<<: *ApplicationCapabilities
As we can see, the channel we are going to create is named FourOrgsTradeChannel, which is defined in the profile. The four organizations participating in this channel are labeled ExporterOrg, ImporterOrg, CarrierOrg, and RegulatorOrg, each of which refers to a subsection defined in the Organizations section. The orderer belongs to its own organization called TradeOrdererOrg. Each organization section contains information about its MSP (ID as well as the location of the cryptographic material, such as keys and certificates), and the hostname and port information for its anchor peers. As an example, the ExporterOrg section contains the following:
- &ExporterOrg
Name: ExporterOrgMSP
ID: ExporterOrgMSP
MSPDir: crypto-config/peerOrganizations/exporterorg.trade.com/msp
AnchorPeers:
- Host: peer0.exporterorg.trade.com
Port: 7051
As you can see, the MSPDir variable (representing a folder) in this specification references the cryptographic material we generated earlier using the cryptogen tool.
To generate the channel artifacts, we use the configtxgen tool. To generate the genesis block (which will be sent to the orderer during network bootstrap), run the following command from the network folder:
configtxgen -profile FourOrgsTradeOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
The FourOrgsTradeOrdererGenesis keyword corresponds to the profile name in the Profiles section. The genesis block will be saved in the genesis.block file in the channel-artifacts folder. To generate the channel configuration, run the following code:
configtxgen -profile FourOrgsTradeChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID tradechannel
The channel we will create is named tradechannel, and its configuration is stored in channel-artifacts/channel.tx. To generate the anchor peer configuration for the exporter organization, run:
configtxgen -profile FourOrgsTradeChannel -outputAnchorPeersUpdate ./channel-artifacts/ExporterOrgMSPanchors.tx -channelID tradechannel -asOrg ExporterOrgMSP
The same process should be repeated for the other three organizations, while changing the organization names in the preceding command.
The environment variable FABRIC_CFG_PATH must be set to point to the folder that contains the configtx.yaml file in order for the configtxgen tool to work. The script file trade.sh (which we will use later) contains the following line to ensure that the YAML file is loaded from the folder in which the command is run:
export FABRIC_CFG_PATH=${PWD}