Using configtx.yaml to build a channel configuration

A channel is created by building a channel creation transaction artifact that specifies the initial configuration of the channel. The channel configuration is stored on the ledger, and governs all the subsequent blocks that are added to the channel. The channel configuration specifies which organizations are channel members, the ordering nodes that can add new blocks on the channel, as well as the policies that govern channel updates. The initial channel configuration, stored in the channel genesis block, can be updated through channel configuration updates. If a sufficient number of organizations approve a channel update, a new channel config block will govern the channel after it is committed to the channel.

While it is possible to build the channel creation transaction file manually, it is easier to create a channel by using the configtx.yaml file and the configtxgen tool. The configtx.yaml file contains the information that is required to build the channel configuration in a format that can be easily read and edited by humans. The configtxgen tool reads the information in the configtx.yaml file and writes it to the protobuf format that can be read by Fabric.

Overview

You can use this tutorial to learn how to use the configtx.yaml file to build the initial channel configuration that is stored in the genesis block. The tutorial will discuss the portion of channel configuration that is built by each section of file.

Because different sections of the file work together to create the policies that govern the channel, we will discuss channel policies in their own tutorial.

Building off of the Creating a channel tutorial, we will use the configtx.yaml file that is used to deploy the Fabric test network as an example. Open a command terminal on your local machine and navigate to the test-network directory in your local clone of the Fabric samples:

  1. cd fabric-samples/test-network

The configtx.yaml file used by the test network is located in the configtx folder. Open the file in a text editor. You can refer back to this file as the tutorial goes through each section. You can find a more detailed version of the configtx.yaml file in the Fabric sample configuration.

Organizations

The most important information contained in the channel configuration are the organizations that are channel members. Each organization is identified by an MSP ID and a channel MSP. The channel MSP is stored in the channel configuration and contains the certificates that are used to the identify the nodes, applications, and administrators of an organization. The Organizations section of configtx.yaml file is used to create the channel MSP and accompanying MSP ID for each member of the channel.

The configtx.yaml file used by the test network contains three organizations. Two organizations are peer organizations, Org1 and Org2, that can be added to application channels. One organization, OrdererOrg, is the administrator of the ordering service. Because it is a best practice to use different certificate authorities to deploy peer nodes and ordering nodes, organizations are often referred to as peer organizations or ordering organizations, even if they are in fact run by the same company.

You can see the part of configtx.yaml that defines Org1 of the test network below:

  1. - &Org1
  2. # DefaultOrg defines the organization which is used in the sampleconfig
  3. # of the fabric.git development environment
  4. Name: Org1MSP
  5. # ID to load the MSP definition as
  6. ID: Org1MSP
  7. MSPDir: ../organizations/peerOrganizations/org1.example.com/msp
  8. # Policies defines the set of policies at this level of the config tree
  9. # For organization policies, their canonical path is usually
  10. # /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
  11. Policies:
  12. Readers:
  13. Type: Signature
  14. Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
  15. Writers:
  16. Type: Signature
  17. Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
  18. Admins:
  19. Type: Signature
  20. Rule: "OR('Org1MSP.admin')"
  21. Endorsement:
  22. Type: Signature
  23. Rule: "OR('Org1MSP.peer')"
  24. # OrdererEndpoints is a list of all orderers this org runs which clients
  25. # and peers may to connect to to push transactions and receive blocks respectively.
  26. OrdererEndpoints:
  27. - "orderer.example.com:7050"
  • The Name field is an informal name used to identify the organization.

  • The ID field is the organization’s MSP ID. The MSP ID acts as a unique identifier for your organization, and is referred to by channel policies and is included in the transactions submitted to the channel.

  • The MSPDir is the path to an MSP folder that was created by the organization. The configtxgen tool will use this MSP folder to create the channel MSP. This MSP folder needs to contain the following information, which will be transferred to the channel MSP and stored in the channel configuration:

    • A CA root certificate that establishes the root of trust for the organization. The CA root cert is used to verify if an application, node, or administrator belongs to a channel member.

    • A root cert from the TLS CA that issued the TLS certificates of the peer or orderer nodes. The TLS root cert is used to identify the organization by the gossip protocol.

    • If Node OUs are enabled, the MSP folder needs to contain a config.yaml file that identifies the administrators, nodes, and clients based on the OUs of their x509 certificates.

    • If Node OUs are not enabled, the MSP needs to contain an admincerts folder that contains the signing certificates of the organizations administrator identities.

    The MSP folder that is used to create the channel MSP only contains public certificates. As a result, you can build the MSP folder locally, and then send the MSP to the organization that is creating the channel.

  • The Policies section is used to define a set of signature policies that reference the channel member. We will discuss these policies in more detail when we discuss channel policies.

  • The OrdererEndpoints indicates the orderer node endpoints that this organization makes available to clients and peers. Service discovery uses this information so that clients can pass the appropriate TLS certificates when connecting to an orderer endpoint.

Capabilities

Fabric channels can be joined by orderer and peer nodes that are running different versions of Hyperledger Fabric. Channel capabilities allow organizations that are running different Fabric binaries to participate on the same channel by only enabling certain features. For example, organizations that are running Fabric v1.4 and organizations that are running Fabric v2.x can join the same channel as long as the channel capabilities levels are set to V1_4_X or below. None of the channel members will be able to use the features introduced in Fabric v2.0.

If you examine the configtx.yaml file, you will see three capability groups:

  • Application capabilities govern the features that are used by peer nodes, such as the Fabric chaincode lifecycle, and set the minimum version of the Fabric binaries that can be run by peers joined to the channel.

  • Orderer capabilities govern the features that are used by orderer nodes, such as Raft consensus, and set the minimum version of the Fabric binaries that can be run by ordering nodes that belong to the channel consenter set.

  • Channel capabilities set the minimum version of the Fabric that can be run by peer and ordering nodes.

Because both of the peers and the ordering node of the Fabric test network run version v2.x, every capability group is set to V2_0. As a result, the test network cannot be joined by nodes that run a lower version of Fabric than v2.0. For more information, see the capabilities concept topic.

Application

The application section defines the policies that govern how peer organizations can interact with application channels. These policies govern the number of peer organizations that need to approve a chaincode definition or sign a request to update the channel configuration. These policies are also used to restrict access to channel resources, such as the ability to write to the channel ledger or to query channel events.

The test network uses the default application policies provided by Hyperledger Fabric. If you use the default policies, all peer organizations will be able to read and write data to the ledger. The default policies also require that a majority of channel members sign channel configuration updates and that a majority of channel members need to approve a chaincode definition before a chaincode can be deployed to a channel. The contents of this section are discussed in more detail in the channel policies tutorial.

Orderer

Each channel configuration includes the orderer nodes in the channel consenter set. The consenter set is the group of ordering nodes that have the ability to create new blocks and distribute them to the peers joined to the channel. The endpoint information of each ordering node that is a member of the consenter set is stored in the channel configuration.

The test network uses the Orderer section of the configtx.yaml file to create a single node Raft ordering service.

  • The OrdererType field is used to select Raft as the consensus type:

    1. OrdererType: etcdraft

    Raft ordering services are defined by the list of consenters that can participate in the consensus process. Because the test network only uses a single ordering node, the consenters list contains only one endpoint:

    1. EtcdRaft:
    2. Consenters:
    3. - Host: orderer.example.com
    4. Port: 7050
    5. ClientTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
    6. ServerTLSCert: ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt

    Each ordering node in the list of consenters is identified by their endpoint address and their client and server TLS certificate. If you are deploying a multi-node ordering service, you would need to provide the hostname, port, and the path to the TLS certificates used by each node.

  • You can use the BatchTimeout and BatchSize fields to tune the latency and throughput of the channel by changing the maximum size of each block and how often a new block is created. The BatchSize property includes MaxMessageCount, AbsoluteMaxBytes, and PreferredMaxBytes settings. A block will be cut when any of the BatchTimeout or BatchSize criteria has been met. For AbsoluteMaxBytes it is recommended not to exceed 49 MB, given the default gRPC maximum message size of 100 MB configured on orderer and peer nodes (and allowing for message expansion during communication).

  • The Policies section creates the policies that govern the channel consenter set. The test network uses the default policies provided by Fabric, which require that a majority of orderer administrators approve the addition or removal of ordering nodes, organizations, or an update to the block cutting parameters.

Because the test network is used for development and testing, it uses an ordering service that consists of a single ordering node. Networks that are deployed in production should use a multi-node ordering service for security and availability. To learn more, see Configuring and operating a Raft ordering service.

Channel

The channel section defines that policies that govern the highest level of the channel configuration. For an application channel, these policies govern the hashing algorithm, the data hashing structure used to create new blocks, and the channel capability level. In the system channel, these policies also govern the creation or removal of consortiums of peer organizations.

The test network uses the default policies provided by Fabric, which require that a majority of orderer service administrators would need to approve updates to these values in the system channel. In an application channel, changes would need to be approved by a majority of orderer organizations and a majority of channel members. Most users will not need to change these values.

Profiles

The configtxgen tool reads the channel profiles in the Profiles section to build a channel configuration. Each profile uses YAML syntax to gather data from other sections of the file. The configtxgen tool uses this configuration to create a channel creation transaction for an applications channel, or to write the channel genesis block for a system channel. To learn more about YAML syntax, Wikipedia provides a good place to get started.

The configtx.yaml used by the test network contains two channel profiles, TwoOrgsOrdererGenesis and TwoOrgsChannel. If you want to create a channel without a system channel by using the osnadmin CLI then you can refer to the SampleAppChannelEtcdRaft

TwoOrgsOrdererGenesis

The TwoOrgsOrdererGenesis profile is used to create the system channel genesis block:

  1. TwoOrgsOrdererGenesis:
  2. <<: *ChannelDefaults
  3. Orderer:
  4. <<: *OrdererDefaults
  5. Organizations:
  6. - *OrdererOrg
  7. Capabilities:
  8. <<: *OrdererCapabilities
  9. Consortiums:
  10. SampleConsortium:
  11. Organizations:
  12. - *Org1
  13. - *Org2

The system channel defines the nodes of the ordering service and the set of organizations that are ordering service administrators. The system channel also includes a set of peer organizations that belong to the blockchain consortium. The channel MSP of each member of the consortium is included in the system channel, allowing them to create new application channels and add consortium members to the new channel.

The profile creates a consortium named SampleConsortium that contains the two peer organizations in the configtx.yaml file, Org1 and Org2. The Orderer section of the profile uses the single node Raft ordering service defined in the Orderer: section of the file. The OrdererOrg from the Organizations: section is made the only administrator of the ordering service. Because our only ordering node is running Fabric 2.x, we can set the orderer system channel capability to V2_0. The system channel uses default policies from the Channel section and enables V2_0 as the channel capability level.

TwoOrgsChannel

The TwoOrgsChannel profile is used by the test network to create application channels:

  1. TwoOrgsChannel:
  2. Consortium: SampleConsortium
  3. <<: *ChannelDefaults
  4. Application:
  5. <<: *ApplicationDefaults
  6. Organizations:
  7. - *Org1
  8. - *Org2
  9. Capabilities:
  10. <<: *ApplicationCapabilities

The system channel is used by the ordering service as a template to create application channels. The nodes of the ordering service that are defined in the system channel become the default consenter set of new channels, while the administrators of the ordering service become the orderer administrators of the channel. The channel MSPs of channel members are transferred to the new channel from the system channel. After the channel is created, ordering nodes can be added or removed from the channel by updating the channel configuration. You can also update the channel configuration to add other organizations as channel members.

The TwoOrgsChannel provides the name of the consortium, SampleConsortium, hosted by the test network system channel. As a result, the ordering service defined in the TwoOrgsOrdererGenesis profile becomes channel consenter set. In the Application section, both organizations from the consortium, Org1 and Org2, are included as channel members. The channel uses V2_0 as the application capabilities, and uses the default policies from the Application section to govern how peer organizations will interact with the channel. The application channel also uses the default policies from the Channel section and enables V2_0 as the channel capability level.

SampleAppChannelEtcdRaft

The SampleAppChannelEtcdRaft profile is provided for customers that prefer to create a channel without a system channel by using the osnadmin CLI. The major difference is that a consortium definition is no longer required. Check out the Create a channel tutorial to learn more about how to use this profile.

  1. SampleAppChannelEtcdRaft:
  2. <<: *ChannelDefaults
  3. Orderer:
  4. <<: *OrdererDefaults
  5. OrdererType: etcdraft
  6. Organizations:
  7. - <<: *SampleOrg
  8. Policies:
  9. <<: *SampleOrgPolicies
  10. Admins:
  11. Type: Signature
  12. Rule: "OR('SampleOrg.member')"
  13. Application:
  14. <<: *ApplicationDefaults
  15. Organizations:
  16. - <<: *SampleOrg
  17. Policies:
  18. <<: *SampleOrgPolicies
  19. Admins:
  20. Type: Signature
  21. Rule: "OR('SampleOrg.member')"

For simplicity, this snippet assumes that the peers and orderers belong to the same organization SampleOrg. For a production deployment however, it is recommended that the peer and ordering nodes belong to separate organizations.