I am new to hyperledger and is going through the example here . I am tried to play around the chaincode but is now stuck at the part where I am suppose to upgrade the chaincode
I have tried to execute the peer chaincode upgrade within the docker peer node:
peer chaincode upgrade -n tuna-app -p github.com/tuna-app
but end up with the error
Error getting (testchainid) orderer endpoint: Error endorsing GetConfigBlock: rpc error: code = Unknown desc = chaincode error (status: 500, message: "GetConfigBlock" request failed authorization check for channel [testchainid]: [Failed to get policy manager for channel [testchainid]])
You need to specify the channel name for which you'd like to upgrade the chaincode, also need to specify args and new version. Moreover you have to specify the ordering service endpoints so peer cli will be able to submit the upgrade transaction:
peer chaincode upgrade -n tuna-app -v 2.0 \
-c '{"Args":[""]}' \
-p github.com/tuna-app -C mychannel \
-o orderer:7051
You can find more here.
Here you have some basic script in bash:
#!/bin/bash
PRV_VERSION='v2';
VERSION='v3';
CONTAINER_IDS=$(docker ps -a | grep "mycc-$PRV_VERSION" | awk '{print $1}')
docker rm -f $CONTAINER_IDS
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org1.example.com/msp" peer0.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org1.example.com/msp" peer1.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org2.example.com/msp" peer0.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org2.example.com/msp" peer1.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
sleep 10;
ORDERER_CA=/etc/hyperledger/organizations/users/Admin@example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org1.example.com/msp" \
peer0.org1.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
ORDERER_CA=/etc/hyperledger/organizations/users/Admin@example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin@org2.example.com/msp" \
peer0.org2.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
You need of course share some certs to your peer0.org1 and of course the chaincode itself (in js or go), here you have some docker-compose.yml part:
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.org1.example.com
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
ports:
- 7051:7051
- 7053:7053
volumes:
- ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/crypto/peer
- ./channel/crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/peer/users
- ./channel/crypto-config/ordererOrganizations/example.com/users:/etc/hyperledger/organizations/users
- ./src/github.com/example_cc/node:/etc/hyperledger/chaincode
Then you can check the logs by:
docker logs dev-peer0.org1.example.com-mycc-v3 -f
I need to say, that upgrading chaincode in development take the same amount of time as just recreate whole blockchain (without pulling new images - this should be removed from ./runApp.sh script).