升级fabric至v1.0(因为1.0才支持动态添加org,主要用到一个工具:configtxlator,该工具中有个指令只有1.1的支持。原则上是各个版本都支持,只要配置文件能够更新成功)
生成原有4+1配置,并启动网络
./byfn -m generate
./byfn -m up
在当前文件目录下,新建 org*-artifacts 目录,并编写org*的配置:
configtx.yaml:
Organizations:
- &Org3
- Name: Org3MSP
MSPDir: crypto-config/peerOrganizations/org3.example.com/msp
AnchorPeers:
- Host: peer0.org3.example.com
Port: 7051
org3-crypto.yaml:
PeerOrgs:
- Name: Org3
Domain: org3.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
生成org*的秘钥:
../../bin/cryptogen generate --config=./org3-crypto.yaml
PS.如果提示cryptogen找不到,则先执行下面的命令,或者从其他的环境复制一份工具脚本文件
curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0-rc1
生成org*的配置文件
export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
将排序节点相关证书拷贝到org*-artifacts/crypto-config/里,这么做是让新的组织可以连接到排序节点
cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/
升级过程需要使用一个配置文件翻译工具configtxlator,将配置文件protobufs翻译为人类可读的json,这个工具提供了一个与sdk无关的REST API.在cli里可以获取到它.另外,这个工具可以计算生成出两个channel配置文件的差别,并生成出配置文件升级交易
进入cli(另开terminal)
docker exec -it cli bash
cli中安装jq,由于官方的容器都是基于ubuntu的,所以直接使用Ubuntu的安装指令进行安装
apt update && apt install -y jq
如果cli中无法下载,则回宿主机进行操作
//宿主机
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
tar -xvf jq-1.5.tar.gz
docker cp /root/jq-1.5 cli:/opt/gopath/src/github.com/hyperledger/fabric/peer
//回cli
cd jq-1.5/ && ./configure && make && sudo make install
配置环境变量
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem && export CHANNEL_NAME=mychannel
P.S. 任何重启cli的行为都请重新配置环境变量
获取channel的配置文件
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
解码配置文件
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json
4、在原有的配置文件添加org3的配置
利用jq工具生成含有3个orgs的配置文件modified_config.json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json
将config.json转换为protobufs
configtxlator proto_encode --input config.json --type common.Config --output config.pb
modified_config.json 转换为 protobufs
configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
根据config.pb和modified_config.pb计算出升级的org3_update.pb
configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb
解码org3_update.pb -> json
configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json
生成配置升级的json并转换为protobufs
echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
configtxlator proto_encode --input org3_update_in_envelope.json --type common.Envelope --output org3_update_in_envelope.pb
现在我们有个升级交易的pb文件,现在需要必要的Admin用户签名才能真正应用升级,因为现有网络的修改策略为MAJORITY,所以必须网络中一半以上的节点同意才能升级.
org1 提交升级配置的交易
peer channel signconfigtx -f org3_update_in_envelope.pb
切换至org2
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA
org* 加入Channel
启动org3的docker集群
docker-compose -f docker-compose-org3.yaml up -d
进入Org3cli
docker exec -it Org3cli bash
添加环境变量(该环境变量指定的是组织节点链接排序节点时需要指定的证书)
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem && export CHANNEL_NAME=mychannel
加入Channel
peer channel join -b mychannel.block
org3.peer1加入Channel
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt && export CORE_PEER_ADDRESS=peer1.org3.example.com:7051
peer channel join -b mychannel.block
为了使org3真正有用,需要升级chaincode和背书策略
org3Cli里升级chaincode
peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
只有作为背书节点和数据库账本交互的peer需要安装chaincode.没有chaincode容器的peer同样会执行校验逻辑作为提交节点.
org2里升级chaincode
peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
org1里升级chaincode
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
peer chaincode install -n mycc -v 2.0 -pgithub.com/chaincode/chaincode_example02/go/
升级背书策略
peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
7、验证结果
以下省略
所有的流程在1.1的firstnetwork中都可以找到,官方为了方便,脚本都写好了。如果想仔细研究流程,可参考该文件。
fabric1.0中,只需要手工添加组织信息以及根证书等信息。