[Fabric]-First-Network (configx.yaml 详细信息)

前言:

建议大家写一次试试,建议在idea一类的工具中编写,方便看到引用关系。

这个我有的地方理解的不很透彻,希望大家指正。或者希望大家补充。

1. 简介

该文件是configtxgen工具用于生成通道创世块 或通道交易的配置文件,configfx.yaml的内容直接决定了所生成的创世块的内容。

2. 主要功能

  1. 生成启动orderer需要的初始区块 ,并支持检查区块内容
  2. 生成创建应用通道需要的配置交易,并支持检查交易内容
  3. 生成锚节点的更新配置交易

3. 具体配置信息

configtx.yaml配置文件一般包含五大配置:ProfilesOrganizationsOrdererApplicationCapabilities

  • 详细信息
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
  - &Org2
     Name: Org2MSP
     ID: Org2MSP
     MSPDir: crypto-config/peerOrganizations/org2.example.com/msp
     AnchorPeers:
       - Host: peer0.org2.example.com
         Port: 7051
  - &Org3
     Name: Org3MSP
     ID: Org3MSP
     MSPDir: crypto-config/peerOrganizations/org3.example.com/msp
     AnchorPeers:
       - Host: peer0.org3.example.com
         Port: 7051
  - &Org4
     Name: Org4MSP
     ID: Org4MSP
     MSPDir: crypto-config/peerOrganizations/org4.example.com/msp
     AnchorPeers:
       - Host: peer0.org4.example.com
         Port: 7051

Orderer: &OrdererDefaults
  OrdererType: solo
  Addresses:
    - orderer.example.com:7050
  BatchTimeout: 2s
  BatchSize:
    MaxMessageCount: 10
    AbsoluteMaxBytes: 98 MB
    PreferredMaxBytes: 512 KB
  Kafka:
    Brokers:
      - 127.0.0.1:9092
  Organizations:
  
Application: &ApplicationDefaults
  Organizations:
  
Profiles:
  FourOrgsOrdererGenesis:
    Orderer:
        <<: *OrdererDefaults
        Organizations:
          - *OrdererOrg
    Consortiums:
        SampleConsortium:
            Organizations:
                - *Org1
                - *Org2
                - *Org3
                - *Org4
  FourOrgsChannel:
    Consortium: SampleConsortium
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *Org1
        - *Org2
        - *Org3
        - *Org4

(1)Profiles部分

profile其实还有好多别的配置,具体的希望大家去百度,这里只提供最简单的这个案例。

configtxgen 工具后面有个指定profile的命令

-profile string
  The profile from configtx.yaml to use for generation. (default "SampleInsecureSolo")
Profiles:
  FourOrgsOrdererGenesis:
    Orderer:
        <<: *OrdererDefaults
        Organizations:
        # 最好自定义(这只是样例名称)
          - *OrdererOrg
    Consortiums:
        SampleConsortium:
        # 定义了peer节点的数量和名称 (要和下面  FourOrgsChannel->Applicatio下的对应)
            Organizations:
                - *Org1
                - *Org2
                - *Org3
                - *Org4
  FourOrgsChannel:
    Consortium: SampleConsortium
    Application:
      <<: *ApplicationDefaults
      Organizations:
        - *Org1
        - *Org2
        - *Org3
        - *Org4

(2)Organizations部分

组织节点信息:定义的是所有的排序服务节点及普通节点根据服务器配置信息。

Organizations:

    - &ExampleCom
        # 节点名称
        Name: ExampleCom
        # 加载的自定于MSPID
        ID: example.com
        # 主要管理员
        AdminPrincipal: Role.ADMIN
        # 定义包含MSP配置的文件系统路径
        MSPDir: ./ordererOrganizations/example.com/msp
        Policies:
            Readers:
                Type: Signature
                Rule: OR('example.com.member')
            Writers:
                Type: Signature
                Rule: OR('example.com.member')
            Admins:
                Type: Signature
                Rule: OR('example.com.admin')
            Endorsement:
                Type: Signature
                Rule: OR('example.com.member')

    - &Org1ExampleCom
        Name: Org1ExampleCom
        ID: org1.example.com
        MSPDir: ./peerOrganizations/org1.example.com/msp
        AdminPrincipal: Role.ADMIN
        # 定义了锚节点,
        AnchorPeers:
            - Host: peer0.org1.example.com
              Port: 7051
        Policies:
            Readers:
                Type: Signature
                Rule: OR('org1.example.com.member')
            Writers:
                Type: Signature
                Rule: OR('org1.example.com.member')
            Admins:
                Type: Signature
                Rule: OR('org1.example.com.admin')
            Endorsement:
                Type: Signature
                Rule: OR('org1.example.com.member')

    - &Org2ExampleCom
        Name: Org2ExampleCom
        ID: org2.example.com
        MSPDir: ./peerOrganizations/org2.example.com/msp
        AdminPrincipal: Role.ADMIN
        AnchorPeers:
            - Host: peer0.org2.example.com
              Port: 7051
        Policies:
            Readers:
                Type: Signature
                Rule: OR('org2.example.com.member')
            Writers:
                Type: Signature
                Rule: OR('org2.example.com.member')
            Admins:
                Type: Signature
                Rule: OR('org2.example.com.admin')
            Endorsement:
                Type: Signature
                Rule: OR('org2.example.com.member')

(3)Orderer部分

Orderer指定了fabric网络的启动类型,区块生成配置及排序服务的地址。

Orderer: &OrdererDefaults

    # 排序节点类型用来指定要启用的排序节点实现,
    # 不同的实现对应不同的共识算法。
    # 目前可用的类型为:solo和kafka
    OrdererType: solo
    Addresses:
        - orderer0.example.com:7050
    
    # 批处理超时
    BatchTimeout: 2s
    
    BatchSize:
        # 最大消息计数:批处理的最大消息数量
        MaxMessageCount: 10
        # 绝对最大字节数:批中序列化消息的绝对最大字节数
        AbsoluteMaxBytes: 98 MB
        #首选最大字节数
        #批量序列化消息允许的首选最大字节数。
        # 大于首选最大字节数的邮件将导致批处理大于首选最大字节数。
        PreferredMaxBytes: 512 KB
    
    #最大通道数
    MaxChannels: 0
    Kafka:
        Brokers:
            - kafka0:9092
            - kafka1:9092
            - kafka2:9092
            - kafka3:9092

    Organizations:

    # 定义本层级的排序节点策略,其权威路径为 /Channel/Orderer/<PolicyName>
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: ANY Readers
        Writers:
            Type: ImplicitMeta
            Rule: ANY Writers
        Admins:
            Type: ImplicitMeta
            Rule: MAJORITY Admins
        # BlockValidation配置项指定了哪些签名必须包含在区块中,以便对等节点进行验证
        BlockValidation:
            Type: ImplicitMeta
            Rule: ANY Writers

    # Capabilities配置描述排序节点层级的能力需求,这里直接引用
    # 前面Capabilities配置段中的OrdererCapabilities配置项
    Capabilities:
        <<: *OrdererCapabilities
区块实在排序服务中生成,最终再通过广播的形式分发到各个peer节点实现数据同步,区块什么时候生成就是通过上面`Batch`配置。

举例:如上面配置。一个区块中

- 达到10条消息体
- 区块大小超过98MB
- 距离上一个区块生成时间达到或超过2s

(4)Application部分

## 了解知识
1. 系统链码 System chaincodes

    系统链码与普通用户具有相同的编程模型,但是与用户链码不同,系统链码内置在对等节点的可执行文件中。
2. LSCC  `the life cycle system chaincode` 

    生命周期系统链码(LSCC)-安装/实例化/更新链码
3. ESCC  `the endorsement system chaincode `

    背书系统链码(ESCC)-通过响应进行数字签名来背书交易
4. VSCC  `the validation system chaincode`

    验证系统链码(VSCC)-根据背书策略验证交易的背书签名集
5. CSCC  `the configuration system chaincode`

    配置系统链码(CSCC)-用于管理通道的配置

- 代码
Application: &ApplicationDefaults
    ACLs: &ACLsDefault
        # ACLs配置段为系统中各种资源提供默认的策略。
        # 这里所说的“资源”,可以是系统链码的函数,例如qscc系统链码的GetBlockByNumber方法
        # 也可以是其他资源,例如谁可以接收区块事件。
        # 这个配置段不是用来定义资源或API,而仅仅是定义资源的访问控制策略
        # 
        # 用户可以在通道定义中重写这些默认策略

        #新生命周期系统链码 方法 去 策略 映射 访问控制
        #---New Lifecycle System Chaincode (_lifecycle) function to policy mapping for access control--#

        # _lifecycle系统链码CommitChaincodeDefinition函数的ACL定义
        _lifecycle/CommitChaincodeDefinition: /Channel/Application/Writers

        # _lifecycle系统链码的QueryChaincodeDefinition函数的ACL定义
        _lifecycle/QueryChaincodeDefinition: /Channel/Application/Readers

        # _lifecycle系统链码的QueryNamespaceDefinitions函数的ACL定义  查询命名空间定义
        _lifecycle/QueryNamespaceDefinitions: /Channel/Application/Readers

        #---Lifecycle System Chaincode (lscc) function to policy mapping for access control---#

        # lscc系统链码的getid函数的ACL定义
        lscc/ChaincodeExists: /Channel/Application/Readers

        # lscc系统链码的getdepspec函数的ACL定义
        lscc/GetDeploymentSpec: /Channel/Application/Readers

        # lscc系统链码的getccdata函数的ACL定义
        lscc/GetChaincodeData: /Channel/Application/Readers

        # lscc系统链码的getchaincodes函数的ACL定义
        lscc/GetInstantiatedChaincodes: /Channel/Application/Readers

        #---Query System Chaincode (qscc) function to policy mapping for access control---#

        # qscc系统链码的GetChainInfo函数的ACL定义
        qscc/GetChainInfo: /Channel/Application/Readers

        # qscc系统链码的GetBlockByNumber函数的ACL定义
        qscc/GetBlockByNumber: /Channel/Application/Readers

        # qscc系统 链码的GetBlockByHash函数的ACL定义
        qscc/GetBlockByHash: /Channel/Application/Readers

        # qscc系统链码的GetTransactionByID函数的ACL定义
        qscc/GetTransactionByID: /Channel/Application/Readers

        # qscc系统链码GetBlockByTxID函数的ACL定义
        qscc/GetBlockByTxID: /Channel/Application/Readers
        
        #系统配置链码
        #---Configuration System Chaincode (cscc) function to policy mapping for access control---#

        # cscc系统链码的GetConfigBlock函数的ACl定义
        cscc/GetConfigBlock: /Channel/Application/Readers

        # cscc系统链码的GetConfigTree函数的ACL定义
        cscc/GetConfigTree: /Channel/Application/Readers

        # cscc系统链码的SimulateConfigTreeUpdate函数的ACL定义
        #模拟配置树更新
        cscc/SimulateConfigTreeUpdate: /Channel/Application/Readers
        
        #杂七杂八的
        #---Miscellanesous peer function to policy mapping for access control---#

        # 访问对等节点上的链码的ACL策略定义
        peer/Propose: /Channel/Application/Writers

        # 从链码中访问其他链码的ACL策略定义
        peer/ChaincodeToChaincode: /Channel/Application/Readers

        #---Events resource to policy mapping for access control###---#

        # 发送区块事件的ACL策略定义
        event/Block: /Channel/Application/Readers

        # 发送过滤的区块事件的ACL策略定义
        event/FilteredBlock: /Channel/Application/Readers

    # Organizations是组织的列表,被定义为网络应用程序方面的参与者。
    Organizations:

    # 定义本层级的应用控制策略,其权威路径为 /Channel/Application/<PolicyName>
    Policies: &ApplicationDefaultPolicies
        Readers:
            Type: ImplicitMeta
            Rule: "ANY Readers"
        Writers:
            Type: ImplicitMeta
            Rule: "ANY Writers"
        Admins:
            Type: ImplicitMeta
            Rule: "MAJORITY Admins"
        LifecycleEndorsement:
            Type: ImplicitMeta
            Rule: "ANY Endorsement"
        Endorsement:
            Type: ImplicitMeta
            Rule: "ANY Endorsement"

    # 前面Capabilities配置段中的ApplicationCapabilities配置项
    Capabilities:
        <<: *ApplicationCapabilities 

(5)channel部分

Channel配置段用来定义要写入创世区块或配置交易的通道参数。

Channel: &ChannelDefaults
    # 定义本层级的通道访问策略,其权威路径为 /Channel/<PolicyName>,
    Policies:
        Readers:
            Type: ImplicitMeta
            Rule: ANY Readers
        # Writes策略定义了调用Broadcast API提交交易的许可规则
        Writers:
            Type: ImplicitMeta
            Rule: ANY Writers
        # Admin策略定义了修改本层级配置的许可规则
        Admins:
            Type: ImplicitMeta
            Rule: MAJORITY Admins
    Capabilities:
        <<: *ChannelCapabilities

(6)Capabilities部分

用来定于fabric网络的能力,这是版本V1.0.0引入的一个新的配置段,当与版本v1.0.x的对等节点与排序节点混合组网时不可使用。

Capabilities段定义了fabric程序要加入网络所必须支持的特性。例如,如果添加了一个新的MSP类型,那么更新的程序可能会根据该类型识别并验证签名,但是老版本的程序就没有办法验证这些交易。这可能导致不同版本的fabric程序中维护的世界状态不一致。

因此,通过定义通道的能力,就明确了不满足该能力要求的fabric程序,将无法处理交易,除非升级到新的版本。对于v1.0.x的程序而言,如果在Capabilities段定义了任何能力,即使声明不需要支持这些能力,都会导致其有意崩溃。

就是版本兼容性问题的配置

Capabilities:
    # Global配置同时应用于排序节点和对等节点,并且必须被两种节点同时支持。
    # 将该配置项设置为ture表明要求节点具备该能力
    Global: &ChannelCapabilities
        V1_3: true

    # Orderer配置仅应用于排序节点,不需考虑对等节点的升级。将该配置项
    # 设置为true表明要求排序节点具备该能力
    Orderer: &OrdererCapabilities
        V1_1: true

    # Application配置仅应用于对等网络,不需考虑排序节点的升级。将该配置项
    # 设置为true表明要求对等节点具备该能力
    Application: &ApplicationCapabilities
        V1_3: true

猜你喜欢

转载自blog.csdn.net/m0_56186460/article/details/122283098
今日推荐