1. Generate the new organization's certificate and the new organization's channel configuration json file
§ 1 Generate certificate
cd org3-artifacts && ../../bin/cryptogen generate --config=./org3-crypto.yaml
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# ---------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
# ---------------------------------------------------------------------------
# Org3
# ---------------------------------------------------------------------------
- Name: Org3
Domain: org3.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$ ../../bin/cryptogen generate --config=./org3-crypto.yaml
org3.example.com
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$ ls -lrt
total 12
-rw-rw-r-- 1 shijianfeng shijianfeng 607 Jan 7 18:44 org3-crypto.yaml
-rw-rw-r-- 1 shijianfeng shijianfeng 1042 Jan 7 18:44 configtx.yaml
drwxr-xr-x 3 shijianfeng shijianfeng 4096 Jan 8 21:53 crypto-config
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$ ls -lrt crypto-config/peerOrganizations/org3.example.com/
total 20
drwxr-xr-x 2 shijianfeng shijianfeng 4096 Jan 8 21:53 tlsca
drwxr-xr-x 2 shijianfeng shijianfeng 4096 Jan 8 21:53 ca
drwxr-xr-x 4 shijianfeng shijianfeng 4096 Jan 8 21:53 peers
drwxr-xr-x 4 shijianfeng shijianfeng 4096 Jan 8 21:53 users
drwxr-xr-x 5 shijianfeng shijianfeng 4096 Jan 8 21:53 msp
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$
§ 2 Generate JSON file of org3 channel configuration
../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
First look at how the channel file is written
#
---
################################################################################
#
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:
- &Org3
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org3MSP
# ID to load the MSP definition as
ID: Org3MSP
MSPDir: crypto-config/peerOrganizations/org3.example.com/msp
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org3.example.com
Port: 7051
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$ ../../bin/configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json
2021-01-08 22:20:05.349 PST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2021-01-08 22:20:05.351 PST [msp] getMspConfig -> INFO 002 Loading NodeOUs
shijianfeng@ubuntu:~/fabric-samples/first-network/org3-artifacts$ vim ../channel-artifacts/org3.json
Organization's read and write permissions to the channel
§ 3 Copy the identity certificate file of the order organization of the original cluster to org3-artifacts/crypto-config/
cd .. && cp -r crypto-config/ordererOrganizations org3-artifacts/crypto-config/
2. Use the new configuration to update the channel
Update the channel configuration execute scripts/step1org3.sh in the container cli
§ 1 Enter the cli container
docker exec -it cli bash
§ 2 Install jq--JSON selector
echo "nameserver 8.8.8.8" | tee -a /etc/resolv.conf&&apt-get -y update&&apt-get -y install jq
§ 3 Set the orderer environment variable
CORE_PEER_LOCALMSPID="OrdererMSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/[email protected]/msp
§ 4 Get the transaction block that configures the existing channel
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
§ 5 Configure the transaction block of the existing channel to be converted into JSON and extract the content of the transaction
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json
jq only took the content of the transaction part and removed the encapsulation part
§ 6 Org3 the conventional configuration, and a channel combined to generate a new format configuration Json
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./channel-artifacts/org3.json > modified_config.json
§ 7 Convert the json configuration of the existing channel to binary
configtxlator proto_encode --input config.json --type common.Config > original_config.pb
§ 8 Convert the configuration file after merging org3 to binary
configtxlator proto_encode --input modified_config.json --type common.Config > modified_config.pb
§ 9 Calculate the difference between the configuration file after merging org3 and the configuration file of the existing channel
configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb > config_update.pb
§ 10. The difference between the configuration file after merging org3 and the configuration file of the existing channel is converted into json format
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate > config_update.json
§ 11. Build transaction json based on the difference between the new and old channel configuration
echo '{"payload":{"header":{"channel_header":{"channel_id":"mychannel", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json
§ 12. Convert the different transaction json of the new and old channel configuration to binary
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope > org3_update_in_envelope.pb
§ 13. Set the environment variable of peer0.org1
CORE_PEER_LOCALMSPID="Org1MSP"
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
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
§ 14. Sign org3_update_in_envelope.pb
peer channel signconfigtx -f org3_update_in_envelope.pb
It must be signed by a member in the channel to update
§ 15. Set the environment variable of peer0.org2
CORE_PEER_LOCALMSPID="Org2MSP"
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
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
Another node commits
§ 16. Update channel (end of step 2)
peer channel update -f org3_update_in_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Exit the container
3. The nodes of the new organization join the updated channel and install the chain code
Nodes of the new organization join the updated channel and install the chain code
§ 1 Start the container of the new organization node
IMAGE_TAG=latest docker-compose -f docker-compose-org3.yaml up -d
§ 2 Enter the container Org3cli
docker exec -it Org3cli bash
§ 3 Get the configuration of the new channel
peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
§ 4 set peer0.org3 environment variables
CORE_PEER_LOCALMSPID="Org3MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
§ 5 peer0.org3 joins the channel
peer channel join -b mychannel.block
§ 6 set peer1.org3 environment variables
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
CORE_PEER_ADDRESS=peer1.org3.example.com:7051
§ 7. peer1.org3 joins the channel
peer channel join -b mychannel.block
§ 8. Set the environment variable of peer0.org3
CORE_PEER_LOCALMSPID="Org3MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
§ 9 install chain code (end of step 3)
peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
Note that the chain code version must be newer than the original, so it is set to 2.0
I should not be installed successfully, let’s look at the reason later
Fourth, the original organization nodes update the chain code version
Update the chaincode version of each node of the original organization
§ 1 Enter the cli container
docker exec -it cli bash
§ 2 Set the environment of peer0.org1
CORE_PEER_LOCALMSPID="Org1MSP"
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
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
§ 3 peer0.org1 install chain code
peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
§ 4. Setting the environment of peer0.org2
CORE_PEER_LOCALMSPID="Org2MSP"
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
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
§ 5 peer0.org2 install chain code
peer chaincode install -n mycc -v 2.0 -l golang -p github.com/chaincode/chaincode_example02/go/
Each organization must have a node to install the chain code
§ 6. Setting up the environment of peer0.org1
CORE_PEER_LOCALMSPID="Org1MSP"
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
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
§ 7 Update chain code version, endorsement strategy (end of step 4)
peer chaincode upgrade -o orderer.example.com:7050 --tls false --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
Here is the instantiation chain code, you only need one place to instantiate it
drop out
Five, the new version of the chain code test after adding nodes
Execute in the container Org3cli./scripts/testorg3.sh
docker exec Org3cli ./scripts/testorg3.sh mychannel 3 golang 10
shijianfeng@ubuntu:~/fabric-samples/first-network$ docker exec Org3cli ./scripts/testorg3.sh mychannel 3 golang 10
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Extend your first network (EYFN) test
Channel name : mychannel
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org3MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
CORE_PEER_ID=Org3cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
===================== Querying on peer0.org3 on channel 'mychannel'... =====================
Attempting to Query peer0.org3 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
2021-01-09 09:54:54.023 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2021-01-09 09:54:54.024 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Query Result: 90
2021-01-09 09:54:55.119 UTC [main] main -> INFO 003 Exiting.....
===================== Query on peer0.org3 on channel 'mychannel' is successful =====================
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org3MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
CORE_PEER_ID=Org3cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
+ res=0
+ set +x
2021-01-09 09:54:55.160 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2021-01-09 09:54:55.160 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2021-01-09 09:54:55.165 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 003 Chaincode invoke successful. result: status:200
2021-01-09 09:54:55.165 UTC [main] main -> INFO 004 Exiting.....
===================== Invoke transaction on peer0.org3 on channel 'mychannel' is successful =====================
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.key
CORE_PEER_LOCALMSPID=Org3MSP
CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/server.crt
CORE_PEER_TLS_ENABLED=true
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/[email protected]/msp
CORE_PEER_ID=Org3cli
CORE_LOGGING_LEVEL=INFO
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
===================== Querying on peer0.org3 on channel 'mychannel'... =====================
Attempting to Query peer0.org3 ...3 secs
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
+ res=0
+ set +x
2021-01-09 09:54:58.234 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2021-01-09 09:54:58.234 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Query Result: 80
2021-01-09 09:54:58.238 UTC [main] main -> INFO 003 Exiting.....
===================== Query on peer0.org3 on channel 'mychannel' is successful =====================
========= All GOOD, EYFN test execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
shijianfeng@ubuntu:~/fabric-samples/first-network$
If the execution is not successful, we will try again later