美文网首页区块链研习社区块链区块链爱好者
Hyperledger fabric如何动态添加组织

Hyperledger fabric如何动态添加组织

作者: golang推广大使 | 来源:发表于2018-11-06 14:54 被阅读1次

动态添加组织机构

前一篇文章介绍了如何搭建一个联盟链,里面的应用通道是cha,通道里的组织机构有blockchain.baidu.com,blockchain.qq.com和blockchain.sina.com.cn3个组织机构。假定现在有个新的组织机构要加入,该如何操作呢?本文将对此展开详细描述。
本文涉及的环境请参考https://www.jianshu.com/p/aa85c5b68f6f搭建。

添加一个新的组织分为以下几步:

  1. 获取当前通道的配置
  2. 给新的组织生成节点、用户、tls和ca的秘钥文件
  3. 计算新加组织导致的配置变更与原来的配置的差异,生成配置更新交易
  4. 用现有多个组织的Admin用户对配置更新交易进行签名
  5. 提交配置更新交易
  6. 新组织加入到原有的通道中

本文用脚本中写好的函数来完成其中的一些繁琐步骤,请直接参考下面的描述完成操作

修改configtx.yaml,使其Organizations包含下面的部分

    - &bcbaiducom
        # DefaultOrg defines the organization which is used in the sampleconfig
        # of the fabric.git development environment
        Name: bcbaiducomMSP

        # ID to load the MSP definition as
        ID: bcbaiducomMSP

        MSPDir: crypto-config/peerOrganizations/bc.baidu.com/msp

        AnchorPeers:
            # AnchorPeers defines the location of peers which can be used
            # for cross org gossip communication.  Note, this value is only
            # encoded in the genesis block in the Application section context
            - Host: peer0.bc.baidu.com
              Port: 7051
        Policies: &bcbaiducomPolicies
            Readers:
                Type: Signature
                Rule: "OR('bcbaiducomMSP.member')"
                # If your MSP is configured with the new NodeOUs, you might
                # want to use a more specific rule like the following:
                # Rule: "OR('bcbaiducomMSP.admin', 'bcbaiducomMSP.peer', 'bcbaiducomMSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('bcbaiducomMSP.member')"
                # If your MSP is configured with the new NodeOUs, you might
                # want to use a more specific rule like the following:
                # Rule: "OR('bcbaiducomMSP.admin', 'bcbaiducomMSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('bcbaiducomMSP.admin')"

新建crypto.yaml,写入如下内容

PeerOrgs:
  - Name: bc.baidu.com
    Domain: bc.baidu.com
    Specs:
          - Hostname: peer0
          - Hostname: peer1
    Users:
      Count: 2

将上面两个文件拷贝到hyperledger-cli.yaml所启动的容器内的工作目录里

docker exec -it $containerName bash 进入用hyperledger-cli.yaml所启动的容器中,执行下面的命令

source scripts/switchenv.sh
getConfig cha baidu.com  # 获取当前通道的配置,并将配置解码并写入到文件 config_cha.json
addOrg bcbaiducomMSP crypto.yaml org.json cha #计算出更新通道配置以便添加新组织到通道中所需要提交的配置更新
#上面的命令执行完毕后会有一个org3_update_in_envelope.pb文件生成

由于通道配置的修改需要多个组织的Admin用户签名才可完成交易,所以接下来我们要用不同组织的Admin用户签署交易

请参考下面的步骤完成多个组织的Admin用户签名

source scripts/switchenv.sh
switchEnv 0 blockchain.baidu.com baidu.com #以blockchain.baidu.com的签名为例
peer channel signconfigtx -f org3_update_in_envelope.pb

等现有通道大多数Admin用户都完成签名后可以执行下面的步骤提交配置交易

source scripts/switchenv.sh
UpdateConfig cha baidu.com

至此,配置交易已经执行完毕,接下来的步骤与新建channel后加入channel的操作一样。
可以用peer channel fetch config config_block.pb -o orderer0.baidu.com:7050 -c cha --tls --cafile $ORDERER_CA获取通道配置,用peer channel join -c config_block.pb来加入通道。

本文用到的yaml文件和脚本请加入扣扣群:871978651获取

相关文章

网友评论

    本文标题:Hyperledger fabric如何动态添加组织

    本文链接:https://www.haomeiwen.com/subject/bdtwaftx.html