跳转至

六、新组织加入联盟审核

六、联盟组织生成和提交新 org 配置

通过 step 3~4,已经生成了 Sy 的证书和配置,但这仅仅是在本地文件系统,还未于区块链网络产生关联。为 channel 新加 Org,对 Fabric而言,是以一笔交易的形式提交的。因此要使得这笔交易能顺利完成,需要提交Sy的配置,到channel中,获得权限认证;然后于网络中发起更新的交易。

1、登录联盟管理组织的cli

docker exec -it cli bash

2、安装 jq 工具

jq 是 Linux 下命令行处理 JSON 的工具,可以对 JSON 进行过滤、格式化、修改等等操作。

apt-get -y update && apt-get -y install jq

3、设置orderer TLS CA环境变量(注意:peer对应的节点上需要有orderer节点的证书)

export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fabric.mbfa.cn/orderers/orderer0.fabric.mbfa.cn/msp/tlscacerts/tlsca.fabric.mbfa.cn-cert.pem

4、获取准备加入channel的配置

peer channel fetch config vtm_config_block.pb -o orderer0.fabric.mbfa.cn:7050 -c cfitestchannel --cafile $ORDERER_CA

5、联盟管理组织修改原channel配置文件, 增加新组织

5.1、解码原有网络的配置文件

将准备加入channel的pb格式配置信息转换成json格式
configtxlator proto_decode --input vtm_config_block.pb --type common.Block | jq .data.data[0].payload.data.config > vtm_config.json

生成文件内容类似set2中syorg.json内容

5.2、使用jq工具,合并cfiorg.json与cfi_config.json, 形成增加新组织后的完整json格式的配置更新文件

jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"VtmMSP":.[1]}}}}}' vtm_config.json ./channel-artifacts/vtmorg.json > vtm_modified_config.json

5.3、将 config.json 和 modified_config.json 转为 protobuf 格式

configtxlator proto_encode --input vtm_config.json --type common.Config > vtm_config.pb
configtxlator proto_encode --input vtm_modified_config.json --type common.Config > vtm_modified_config.pb

5.4、根据 config.pb 和 modified_config.pb 计算出 org3_update.pb ,计算出增量更新内容。 (类似于 diff 操作,但是针对 protobuf 格式,因此会多出好多操作。)

configtxlator compute_update --channel_id cfitestchannel --original vtm_config.pb --updated vtm_modified_config.pb > vtm_config_update.pb

5.5、解码 config_update.pb 为 json,然后用 jq 修改,然后在编码为 protobuf 格式,最终输出 syorg_update_in_envelope.pb

configtxlator proto_decode --input cfi_config_update.pb  --type common.ConfigUpdate > cfi_config_update.json
echo '{"payload":{"header":{"channel_header":{"channel_id":"cfitestchannel", "type":2}},"data":{"config_update":'$(cat cfi_config_update.json)'}}}' | jq . > cfi_config_update_in_envelope.json
configtxlator proto_encode --input cfi_config_update_in_envelope.json --type common.Envelope > cfiorg_update_in_envelope.pb

6、为新组织配置签名

为配置交易签名,需要 channel 中的大多数 Org 对其进行签名。 对于 mychannel 而言,已有了 org1,org2,因此新增 org3 时需要 org1、org2 都签名。 签名操作于 cli 中完成,需采用 Anchor Peer,可通过更改环境变量,改变签名者的身份。

6.1、MBFA组织签名

docker exec -it cli bash

组织签名
peer channel signconfigtx -f cfiorg_update_in_envelope.pb

6.2、登录MSC组织CLI继续签名

(下载MBFA签名后的syorg_update_in_envelope.pb上传到msc组织CLI中,参照MBFA将syorg_update_in_envelope.pb进行签名。)

7、提交签名后的配置交易至orderer

注意:需要将syorg_update_in_envelope.pb注意上传到老组织,并逐一叠加签名。然后由生产此pb文件的组织提交更新。

export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fabric.mbfa.cn/orderers/orderer0.fabric.mbfa.cn/msp/tlscacerts/tlsca.fabric.mbfa.cn-cert.pem
peer channel update -f cfiorg_update_in_envelope.pb -c cfitestchannel -o orderer0.fabric.mbfa.cn:7050 --cafile $ORDERER_CA

若成功入链,可以看到以下输出:

2018-11-01 13:45:17.982 UTC [kvledger] CommitWithPvtData -> INFO 066 [mbfastorechannel] Committed block [2] with 1 transaction(s) in 19ms (state_validation=0ms block_commit=13ms state_commit=3ms)

输出显示,当前提交的块号是 6。块 0 是创世块;1~2 是一些初始化;3~4 是实例化与调用 chaincode ,更新配置。

评论