fabric-1.0动态加入组织

fabric的组织配置信息一般是提前写在configtx.yaml文件中的,通过configtx.yaml生成系统创世区块和通道文件。而系统启动和通道创建是通过创世区块和通道文件进行的,因此要在fabric系统运行时添加组织则是非常困难的。

还好,fabric-1.0提供了configtxlator工具,为动态修改fabric通道信息提供可能。本文将介绍如何利用configtxlator为fabric-1.0网络动态添加组织。

运行fabric网络

本文利用fabric-sample项目中的first-network作为测试的示例。文档参考

下载fabric-sample

从github上克隆fabric-sample项目

$ git clone https://github.com/hyperledger/fabric-samples.git
$ cd fabric-samples

下载镜像和binary包

$ curl -sSL https://goo.gl/eYdRbX | bash

这一步可能需要翻墙,可以从这里下载,然后运行,或者

$ curl -sSL http://oui195df4.bkt.clouddn.com/download-bin.sh | bash

这一步会拉取fabric-1.0的镜像和binary包

生成证书和通道文件

为了测试添加组织,先利用cryptogen工具生成三个组织的证书。
修改first-network,添加org3

crypto-org3

生成证书和通道文件

$ ./byfn.sh -m generate

证书文件在crypto-config文件夹里,通道文件在channel-artifacts文件夹中

启动两个组织的fabric网络

执行

$ ./byfn.sh -m up

启动包括两个组织的fabric网络,cli容器会执行scripts/script.sh脚本进行创建mychannel通道,加入通道,部署chaincode,调用和查询chaincode等。

在系统channel中添加org

参考configtxlator工具的文档

启动configtxlator服务

$ configtxlator start

获取系统通道的配置

设置MSP为Orderer


$ export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin\@example.com/msp/
$ export CORE_PEER_LOCALMSPID=OrdererMSP

获取通道

# peer channel fetch config config_block.pb -o orderer.example.com:7050 -c testchainid

生成添加组织的增量文件

  • 将配置信息区块转换为可读的json文件
$ curl -X POST --data-binary @config_block.pb http://127.0.0.1:7059/protolator/decode/common.Block > config_block.json
  • 获取config区域
$ jq .data.data[0].payload.data.config config_block.json > config.json
  • 修改config.json,添加org3信息

这一步可以利用configtxgen工具生成org3的配置信息,并将配置信息添加到config.json文件中,修改后的文件保存为updated_config.json,部分内容如图:

updated-config

  • 将original config和updated config打包成proto文件
$ curl -X POST --data-binary @config.json http://127.0.0.1:7059/protolator/encode/common.Config > config.pb

$ curl -X POST --data-binary @updated_config.json http://127.0.0.1:7059/protolator/encode/common.Config > updated_config.pb
  • 生成增量文件
$ curl -X POST -F original=@config.pb -F updated=@updated_config.pb http://127.0.0.1:7059/configtxlator/compute/update-from-configs -F channel=testchainid > config_updat
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值