创世区块的Channel、Orderer 和 peer 配置

写在前面的话

你得做完 Hyperledger Fabric 使用 cryptogen 工具定义网络

configtx.yaml

可以看到 configtx.yaml这个文件,内容比较多,删除了一些注释,可以直接看代码:

# first-network/configtx.yaml
###########################定义不同的组织身份 稍后在配置中引用#############################
Organizations:
    - &OrdererOrg    #sampleconfig 排序组织 排序节点所在的组织
        Name: OrdererOrg
        ID: OrdererMSP # 加载MSP 定义ID
        MSPDir: crypto-config/ordererOrganizations/example.com/msp # 包含MSP信息的文件路径   
        # 定义策略集  /Channel///
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Writers:
                Type: Signature
                Rule: "OR('OrdererMSP.member')"
            Admins:
                Type: Signature
                Rule: "OR('OrdererMSP.admin')"

    - &Org1   # 组织1
        Name: Org1MSP
        ID: Org1MSP
        MSPDir: crypto-config/peerOrganizations/org1.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.peer', 'Org1MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org1MSP.admin', 'Org1MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org1MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org1MSP.peer')"

        # leave this flag set to true.
        AnchorPeers:  # 组织1的主节点锚节点,向外通讯,跨组织交流
            - Host: peer0.org1.example.com
              Port: 7051

    - &Org2
        Name: Org2MSP
        ID: Org2MSP
        MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.peer', 'Org2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('Org2MSP.admin', 'Org2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('Org2MSP.admin')"
            Endorsement:
                Type: Signature
                Rule: "OR('Org2MSP.peer')"

        AnchorPeers:
            - Host: peer0.org2.example.com
              Port: 9051

################################################################################
#定义fabric的网络功能,从v1.1.0开始新增板块,做版本说明
Capabilities:
        # 通道功能
    Channel: &ChannelCapabilities
        # 版本说明
        V2_0: true

    # Orderer 排序节点
    Orderer: &OrdererCapabilities
        V2_0: true

    # Application 应用
    Application: &ApplicationCapabilities
        V2_0: true

################################################################################
#   定义了要编码到应用程序相关参数以及创世区块块中的值

Application: &ApplicationDefaults
    # 定义该组织的成员 节点
    Organizations:   
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "MAJORITY Endorsement"

    Capabilities:
        <<: *ApplicationCapabilities
################################################################################
#
#   SECTION: Orderer 配置 性能优化
Orderer: &OrdererDefaults
    OrdererType: etcdraft # etcdraft和solo kafka zookeeper 都是共识机制 新的排序方式
    Addresses:
        - orderer.example.com:7050
    # Batch Timeout: 批处理时间间隔 时间周期 每两秒增加/更新一个区块
    BatchTimeout: 2s 
    BatchSize:
        # Max Message Count: 最大的批处理消息数量
        MaxMessageCount: 10
        # 最大的批处理文件总和大小
        AbsoluteMaxBytes: 99 MB
        # Preferred Max Bytes: 批处理首选最大字节
        PreferredMaxBytes: 512 KB
    Organizations:
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        # 签名验证
        BlockValidation:
            Type: ImplicitMeta
            Rule: "ANY Writers"

################################################################################
#   CHANNEL 通道配置

Channel: &ChannelDefaults
    Policies:
        # Who may invoke the 'Deliver' API 谁会调用 'Deliver' API
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        # Who may invoke the 'Broadcast' API 谁会调用 'Broadcast' API
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        # By default, who may modify elements at this config level 谁会修改
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
    Capabilities:
        <<: *ChannelCapabilities

################################################################################
#   Profile 配置文件
Profiles:

    TwoOrgsChannel:  # 通道配置
        Consortium: SampleConsortium  # 联盟
        <<: *ChannelDefaults  # 通道默认配置
        Application:
            <<: *ApplicationDefaults  #  引用先前的配置
            Organizations: #channel允许谁加入
                - *Org1
                - *Org2
            Capabilities:
                <<: *ApplicationCapabilities # 兼容

    SampleMultiNodeEtcdRaft:  # 排序节点配置
        <<: *ChannelDefaults
        Capabilities:
            <<: *ChannelCapabilities
        Orderer:
            <<: *OrdererDefaults
            OrdererType: etcdraft
            EtcdRaft:
                Consenters:
                - Host: orderer.example.com
                  Port: 7050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
                - Host: orderer2.example.com
                  Port: 8050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer2.example.com/tls/server.crt
                - Host: orderer3.example.com
                  Port: 9050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer3.example.com/tls/server.crt
                - Host: orderer4.example.com
                  Port: 10050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer4.example.com/tls/server.crt
                - Host: orderer5.example.com
                  Port: 11050
                  ClientTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
                  ServerTLSCert: crypto-config/ordererOrganizations/example.com/orderers/orderer5.example.com/tls/server.crt
            Addresses:
                - orderer.example.com:7050
                - orderer2.example.com:8050
                - orderer3.example.com:9050
                - orderer4.example.com:10050
                - orderer5.example.com:11050

            Organizations:
            - *OrdererOrg  # 排序组织
            Capabilities:
                <<: *OrdererCapabilities
        Application:
            <<: *ApplicationDefaults
            Organizations:
            - <<: *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                - *Org1
                - *Org2

创建创世区块

configtxgen -profile SampleMultiNodeEtcdRaft -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
创世区块中包含了各个组织的公钥证书、组织权限信息等,防止被篡改。

创建通道CreateChannel

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
channel.tx 中包含了channel的配置信息

更新通讯的锚节点 AnchorPeer

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP

configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
Org1MSPanchors.tx 中包含了组织一的锚节点 主节点配置

你可能感兴趣的:(hyperledger)