fabric生产环境搭建之番外:channel及configtx.yaml解析

fabric里面的分层设计

一个成熟的区块链架构,往往支持底层链和上层业务逻辑的分离,底层链,指的是网络通讯,交易同步,出块机制,共识等单纯的区块链技术。而上层业务逻辑,指的是基于底层区块链技术,搭建的业务逻辑。

比如比特币,底层是区块链技术,上层业务逻辑是共享账本。以太坊,底层是区块链技术,上层业务逻辑是智能合约。

一些比较优秀的区块链技术从设计之初,就考虑了分层问题,可以基于底层区块链技术,自定义任意的上层业务逻辑,比如tendermint。

fabric也是从分层的角度进行设计,但其文档并不过于强调,以至于难以理解。fabric的底层区块链系统,就是由order节点组成的区块链网络,而他的业务系统,则是一个个的application。fabric里面叫做application channel。和其他区块链不同的是,fabric的application,由单独的网络节点(也就是peer节点)组成。

配置分类

fabric的配置分为底层区块链的配置和上层application的配置,在fabric里统称为channel配置

底层区块链的配置,叫做system channel的配置,主要包括order节点的共识配置,出块机制等,也包括consortium配置,指示哪些组织具备创建普通channel的权利

系统的初始化配置保存在创世区块中,也就是genesis block。

【v.23】开始,增加了一个新模式,可以不再需要显实配置system channel

上层application的配置,叫做application channel配置。具体与单个具体的application相关,主要配置本application的访问策略,组织成员等

application的配置保存在一个交易中

配置文件

configtx.yaml用于配置channel, 包括系统channel和application channel。

配置工具

configtxgen是配置channel的工具,该工具读取configtx.yaml的配置内容,形成创世区块的输出,或者形成application tx的输出

创世区块(底层链配置)创建例子:

configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block

configtxgen利用configtx.yaml profile段名称为TwoOrgsOrdererGenesis的配置,创建了system channel, 输出保存在genesis.block中

application创建例子:

configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel1.tx -channelID channel1

configtxgen利用configtx.yaml profile段名称为TwoOrgsChannel的配置,创建了application channel, 输出保存在channel1.tx中

配置属性

任意一个channel的配置属性,都是以下属性的子集:

&ConfigGroup{
    Groups: map<string, *ConfigGroup> {
        "Application":&ConfigGroup{
            Groups:map<String, *ConfigGroup> {
                {{org_name}}:&ConfigGroup{
                    Values:map<string, *ConfigValue>{
                        "MSP":msp.MSPConfig,
                        "AnchorPeers":peer.AnchorPeers,
                    },
                },
            },
        },
        "Orderer":&ConfigGroup{
            Groups:map<String, *ConfigGroup> {
                {{org_name}}:&ConfigGroup{
                    Values:map<string, *ConfigValue>{
                        "MSP":msp.MSPConfig,
                    },
                },
            },

            Values:map<string, *ConfigValue> {
                "ConsensusType":orderer.ConsensusType,
                "BatchSize":orderer.BatchSize,
                "BatchTimeout":orderer.BatchTimeout,
                "KafkaBrokers":orderer.KafkaBrokers,
            },
        },
        "Consortiums":&ConfigGroup{
            Groups:map<String, *ConfigGroup> {
                {{consortium_name}}:&ConfigGroup{
                    Groups:map<string, *ConfigGroup> {
                        {{org_name}}:&ConfigGroup{
                            Values:map<string, *ConfigValue>{
                                "MSP":msp.MSPConfig,
                            },
                        },
                    },
                    Values:map<string, *ConfigValue> {
                        "ChannelCreationPolicy":common.Policy,
                    }
                },
            },
        },
    },

    Values: map<string, *ConfigValue> {
        "HashingAlgorithm":common.HashingAlgorithm,
        "BlockHashingDataStructure":common.BlockDataHashingStructure,
        "Consortium":common.Consortium,
        "OrdererAddresses":common.OrdererAddresses,
    },
}

除开values属性,我们发现一个channel中,主要的子属性有三个:

  • Orderer
  • Application
  • Consortiums

1. Consortiums

Consortiums是属于system channel的配置,描述哪些组织可以创建channel

在configtx.yaml中格式如:

SampleSingleMSPKafka:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            OrdererType: kafka
            Organizations:
                - *SampleOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *SampleOrg

2. Orderer

Orderer属于system channel和application共有的配置,如果配置在system channel中,描述的是本网络所有的orderer节点,以及其共识

如果配置在application channel中,描述的是本application采用哪些orderer节点出块。fabric支持application channel指定出块的orderer节点。但这个节点必须是system channel中orderer的子集。也就是说比如整个网络有A,B,C,D,E五个orderer节点,Channel1可以指定A,B,C为本channel的出块节点。Channel2可以制定B,D为本channel的出快节点等

在configtx.yaml中,往往不为Application channel的profile配置orderer属性,此时系统会默认采用全局的orderer配置,也就是system channel中的orderer配置

在configtx.yaml中格式如:

SampleSingleMSPKafka:
        <<: *ChannelDefaults
        Orderer:
            <<: *OrdererDefaults
            OrdererType: kafka
            Organizations:
                - *SampleOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *SampleOrg

3. Application

Application属于Application Channel的属性

Application描述的是,哪些组织属于本channel, 属于本channel的组织可以往本channel发布智能合约,应用channel访问策略

在某些system channel profile定义中,会看到Application的定义,这是fabirc的某个测试版本引入的,正常使用时并不需要这样做

在configtx.yaml中格式如:

SampleSingleMSPChannel:
        <<: *ChannelDefaults
        # consotium指明本appliction会使用哪个consortium
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - <<: *SampleOrg

configtx.yaml格式分析

该文件包含以下几个小节:

  1. Organizations
  2. Capabilities
  3. Application
  4. Orderer
  5. Channel
  6. Profiles

其中只有最后的Profiles是真正起作用的配置,前面的5个小节,都仅仅是设置一些值,这些值在Profiles中被引用。

换句话说,configtx.yaml可以只包含Profiles小节

1. Organizations

设置组织的信息。包括组织的MSP信息(根证书),名称,策略等。

格式如下:

Organizations:
    - &OrdererOrg
        Name: OrdererOrg
        ID: OrdererMSP
        MSPDir: ../organizations/ordererOrganizations/example.com/msp
        Policies:
          Readers:
            Type: Signature
            Rule: OR('OrdererMSP.member')
          Writers:
            Type: Signature
            Rule: OR('OrdererMSP.member')
          Admins:
            Type: Signature
            Rule: OR('OrdererMSP.admin')
        OrdererEndpoints:
          - 'orderer.example.com:7050'

2. Capabilities

设置各模块的版本号,以及一些功能特性的是否开启。

格式如下:

Capabilities:
  Channel:
    V2_0: true
  Orderer:
    V2_0: true
  Application:
    V2_0: true

3. Application

设置Application channel能用到的公共属性,会被在具体channel的profile中被引用。比如一些channel访问策略等。

格式如下:

Application:
  Organizations: null
  Policies: &ref_9
    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:
    V2_0: true

4. Orderer

设置orderer节点能用到的属性。会被 channel的profile引用,往往是被system channel引用。比如设置order节点采用共识类型,order节点的策略,以及order在不同类型下的配置,比如kafka节点,raft模式下的共识节点等。

格式如下:

Orderer:
  OrdererType: etcdraft
  Addresses: &ref_2
    - 'orderer.example.com:7050'
  EtcdRaft: &ref_3
    Consenters:
      - Host: orderer.example.com
        Port: 7050
        ClientTLSCert: >-
          ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
        ServerTLSCert: >-
          ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt
  BatchTimeout: 2s
  BatchSize: &ref_4
    MaxMessageCount: 10
    AbsoluteMaxBytes: 99 MB
    PreferredMaxBytes: 512 KB
  Organizations: null
  Policies: &ref_6
    Readers:
      Type: ImplicitMeta
      Rule: ANY Readers
    Writers:
      Type: ImplicitMeta
      Rule: ANY Writers
    Admins:
      Type: ImplicitMeta
      Rule: MAJORITY Admins
    BlockValidation:
      Type: ImplicitMeta
      Rule: ANY Writers

5. Channel

设置Application channel和System channel都可能用到的一些公共属性,供具体的channel profile引用。

格式如下:

Channel:
  Policies: &ref_0
    Readers:
      Type: ImplicitMeta
      Rule: ANY Readers
    Writers:
      Type: ImplicitMeta
      Rule: ANY Writers
    Admins:
      Type: ImplicitMeta
      Rule: MAJORITY Admins
  Capabilities: &ref_1
    V2_0: true

6. Profiles

设置具体的channel配置,引用前面1~5小节的值,主要配置以下几个属性:

  • 本channel的orderer节点,即本channel采用哪些orderer节点,采用什么共识
  • 本channel的Application配置,即本channel有哪些组织,组织管理员等
  • System channel还会配置Consortiums属性,表明哪些组织可以创建Application Channel。因此,只要profile中包含Consortiums配置的,该profile针对的就是system channel。一般而言,system channel会定义多个consortium。application可根据实际情况,通过application channel的consortium,指定其中一个,作为application的实际consortium

格式如下:

Profiles:
  TwoOrgsOrdererGenesis:
    Policies: *ref_0
    Capabilities: *ref_1
    Orderer:
      OrdererType: etcdraft
      Addresses: *ref_2
      EtcdRaft: *ref_3
      BatchTimeout: 2s
      BatchSize: *ref_4
      Organizations:
        - *ref_5
      Policies: *ref_6
      Capabilities:
        V2_0: true
    Consortiums:
      SampleConsortium:
        Organizations:
          - *ref_7
          - *ref_8


  TwoOrgsChannel:
    Consortium: SampleConsortium
    Policies: *ref_0
    Capabilities: *ref_1
    Application:
      Organizations:
        - *ref_7
        - *ref_8
      Policies: *ref_9
      Capabilities:
        V2_0: true

Ref

  • https://hyperledger-fabric.readthedocs.io/en/release-2.2/config_update.html?highlight=OrdererAddresses#sample-channel-configuration
  • https://hyperledger-fabric.readthedocs.io/en/release-2.2/configtx.html?highlight=OrdererAddresses#permitted-configuration-groups-and-values
  • https://hyperledger-fabric.readthedocs.io/en/release-2.2/create_channel/create_channel_config.html
  • https://stackoverflow.com/questions/61078815/setting-a-subset-of-orderers-for-raft-application-channel
  • https://lists.hyperledger.org/g/fabric/topic/78943814#9404


《 “fabric生产环境搭建之番外:channel及configtx.yaml解析” 》 有 4 条评论

  1. buy clomid liquid Since you underwent evaluation and that was the only abnormality found, that is good because most patients with recurrent miscarriage due to spontaneous abnormalities will eventually be successful

  2. 53 prohibits acting as pilot- in- command or in any other capacity as a required pilot flight crewmember, while that person can i get cytotec at walmart

  3. priligy and viagra combination Clomid is a prescription medication, so it is not legal to use without a prescription in most countries

  4. buy priligy 30mg People who know me will help me out and we laugh about it

回复 agodelo 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825