蜡笔小鑫爱看雪 2019-06-26
git checkout -b release-1.1 docker pull hyperledger/fabric-baseos:x86_64-0.4.6 docker pull hyperledger/fabric-tools:x86_64-1.1.0-rc1 docker pull hyperledger/fabric-baseimage:x86_64-0.4.6 docker pull hyperledger/fabric-orderer:x86_64-1.1.0-rc1 docker pull hyperledger/fabric-ccenv:x86_64-1.1.0-rc1 docker pull hyperledger/fabric-peer:x86_64-1.1.0-rc1 docker pull hyperledger/fabric-couchdb:x86_64-1.1.0-preview docker tag hyperledger/fabric-baseimage:x86_64-0.4.6 hyperledger/fabric-baseimage docker tag hyperledger/fabric-baseos:x86_64-0.4.6 hyperledger/fabric-baseos docker tag hyperledger/fabric-tools:x86_64-1.1.0-rc1 hyperledger/fabric-tools docker tag hyperledger/fabric-orderer:x86_64-1.1.0-rc1 hyperledger/fabric-orderer docker tag hyperledger/fabric-ccenv:x86_64-1.1.0-rc1 hyperledger/fabric-ccenv docker tag hyperledger/fabric-peer:x86_64-1.1.0-rc1 hyperledger/fabric-peer docker tag hyperledger/fabric-couchdb:x86_64-1.1.0-preview hyperledger/fabric-couchdb
cd /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network vim docker-compose-cli.yaml cli: container_name: cli image: hyperledger/fabric-tools:$IMAGE_TAG tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock #- CORE_LOGGING_LEVEL=INFO - CORE_LOGGING_LEVEL=DEBUG
vim docker-compose-org3.yaml Org3cli: container_name: Org3cli image: hyperledger/fabric-tools:$IMAGE_TAG tty: true stdin_open: true environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock #- CORE_LOGGING_LEVEL=INFO - CORE_LOGGING_LEVEL=DEBUG
./byfn.sh -m generate
./byfn.sh -m up
cd /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/org3-artifacts
PeerOrgs: # --------------------------------------------------------------------------- # Org3 # --------------------------------------------------------------------------- - Name: Org3 Domain: org3.example.com EnableNodeOUs: true Template: Count: 2 Users: Count: 1
../../bin/cryptogen generate --config=./org3-crypto.yaml
PS.如果提示cryptogen找不到,则先执行下面的命令
curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0-rc1
export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/
此命令根据之前的密钥文件生成json的,如果没生成会报以下错误
2018-03-05 14:30:36.084 CST [common/tools/configtxgen] main -> INFO 001 Loading configuration 2018-03-05 14:30:36.086 CST [common/tools/configtxgen] main -> CRIT 002 Error on printOrg: bad org definition for org Org3MSP: 1 - Error loading MSP configuration for org: Org3MSP: could not load a valid ca certificate from directory /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/org3-artifacts/crypto-config/peerOrganizations/org3.example.com/msp/cacerts: stat /opt/gopath/src/github.com/hyperledger/fabric-samples/first-network/org3-artifacts/crypto-config/peerOrganizations/org3.example.com/msp/cacerts: no such file or directory
升级过程需要使用一个配置文件翻译工具configtxlator,将配置文件protobufs翻译为人类可读的json,这个工具提供了一个与sdk无关的REST API.在cli里可以获取到它.另外,这个工具可以计算生成出两个channel配置文件的差别,并生成出配置文件升级交易
docker exec -it cli bash
apt update && apt install -y jq
如果你跟我一样,docker中无法下,则请回宿主机协作搞定
//宿主机 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的行为都请重新配置环境变量
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原有网络的配置文件config.json作为我们配置升级的基准,值得仔细研读
利用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
configtxlator proto_encode --input config.json --type common.Config --output config.pb
configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb
configtxlator compute_update --channel_id $CHANNEL_NAME --original config.pb --updated modified_config.pb --output org3_update.pb
configtxlator proto_decode --input org3_update.pb --type common.ConfigUpdate | jq . > org3_update.json
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,所以必须网络中一半以上的节点同意才能升级.
peer channel signconfigtx -f org3_update_in_envelope.pb
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/[email protected]/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
docker logs -f peer0.org1.example.com
docker-compose -f docker-compose-org3.yaml up -d
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
peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
peer channel join -b mychannel.block
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真正有用,需要升级chaincodeh和背书策略
peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
只有作为背书节点和数据库账本交互的peer需要安装chaincode.没有chaincode容器的peer同样会执行校验逻辑作为提交节点.
peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
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/[email protected]/msp export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 peer chaincode install -n mycc -v 2.0 -p github.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')"
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'Query Result: 90
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'