添加组织机构
fabric-ca-client -H `pwd`/ca_admin affiliation add com.example.org2
fabric-ca-client enroll -M `pwd`/peerOrganizations/org2.example.com/msp -u http://admin:pass@localhost:7054 -H `pwd`/ca_admin
fabric-ca-client register --id.name Admin@org2.example.com --id.type client --id.affiliation "com.example.org2" --id.attrs '"hf.Registrar.Roles=client,orderer,peer,user","hf.Registrar.DelegateRoles=client,orderer,peer,user",hf.Registrar.Attributes=*,hf.GenCRL=true,hf.Revoker=true,hf.AffiliationMgr=true,hf.IntermediateCA=true,role=admin:ecert' --id.secret=password -H `pwd`/ca_admin
fabric-ca-client enroll -u http://Admin@org2.example.com:password@localhost:7054 -M `pwd`/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
mkdir peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/admincerts/
cp peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/cert.pem peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/admincerts/
mkdir peerOrganizations/org2.example.com/msp/admincerts/
cp peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/cert.pem peerOrganizations/org2.example.com/msp/admincerts
fabric-ca-client register --id.name peer0.org2.example.com --id.type peer --id.affiliation "com.example.org2" --id.attrs '"hf.Registrar.Roles=peer","hf.Registrar.DelegateRoles=peer",hf.Registrar.Attributes=*,hf.GenCRL=true,hf.Revoker=true,hf.AffiliationMgr=true,hf.IntermediateCA=true,role=admin:ecert' --id.secret=password -H `pwd`/peerOrganizations/org2.example.com/users/Admin@org2.example.com
fabric-ca-client enroll -u http://peer0.org2.example.com:password@localhost:7054 -M `pwd`/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp
mkdir `pwd`/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/admincerts
cp peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/cert.pem `pwd`/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/admincerts
获取原始配置区块
添加org
cd org3-artifacts
apt update && apt install -y jq
生成证书
../../bin/cryptogen generate --config=./org3-crypto.yaml
生成org3的json字符串
export FABRIC_CFG_PATH=$PWD && ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
拷贝order证书到org3目录下
cd ../ && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/
../../bin/configtxgen -printOrg Org2MSP -profile configtx.yaml > ../config/Org2MSP.json
docker exec -it cli 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
获取mychannel的配置区块
peer channel fetch config ./channel-artifacts/config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
转为json
configtxlator proto_decode --input ./channel-artifacts/config_block.pb --type common.Block | jq .data.data[0].payload.data.config > ./channel-artifacts/config.json
将org3加入到此json中
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org2MSP":.[1]}}}}}' ./channel-artifacts/config.json ./channel-artifacts/Org2MSP.json > ./channel-artifacts/modified_config.json
转为pb
configtxlator proto_encode --input ./channel-artifacts/config.json --type common.Config --output ./channel-artifacts/config.pb
转为pb
configtxlator proto_encode --input ./channel-artifacts/modified_config.json --type common.Config --output ./channel-artifacts/modified_config.pb
计算pb之间的增量
configtxlator compute_update --channel_id $CHANNEL_NAME --original ./channel-artifacts/config.pb --updated ./channel-artifacts/modified_config.pb --output ./channel-artifacts/org_update.pb
转为json
configtxlator proto_decode --input ./channel-artifacts/org_update.pb --type common.ConfigUpdate | jq . > ./channel-artifacts/org_update.json
加入header信息
echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat ./channel-artifacts/org_update.json)'}}}' | jq . > ./channel-artifacts/org_update_in_envelope.json
转为pb
configtxlator proto_encode --input ./channel-artifacts/org_update_in_envelope.json --type common.Envelope --output ./channel-artifacts/org_update_in_envelope.pb
//如果重复签名会出现错误一定要注意,同时 如果联盟中存在多个组织,需要一半以上的组织同意 才能新加到组织上
org1签名
peer channel signconfigtx -f ./channel-artifacts/org_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
//上传新配置 . update 表示签名后直接上传
peer channel update -f ./channel-artifacts/org_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA