修改后如何升级链码?

时间:2017-11-16 13:11:55

标签: hyperledger-fabric hyperledger

我是hyperledger的新手,正在通过示例here。我试图玩链码,但现在卡在我想要升级链码的部分

我试图在docker peer node中执行peer chaincode升级:

peer chaincode upgrade -n tuna-app -p github.com/tuna-app

但最终会出现错误

 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]])

3 个答案:

答案 0 :(得分:3)

您需要指定要升级链码的通道名称,还需要指定args和新版本。此外,您必须指定订购服务端点,以便peer cli能够提交升级事务:

peer chaincode upgrade -n tuna-app -v 2.0 \
               -c '{"Args":[""]}' \
               -p github.com/tuna-app -C mychannel \
               -o orderer:7051

您可以找到更多here

答案 1 :(得分:1)

这是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

您当然需要与peer0.org1共享一些证书,当然也需要链代码本身(在js或go中),这里有一些docker-compose.yml部分:

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

然后您可以通过以下方式查看日志:

docker logs dev-peer0.org1.example.com-mycc-v3 -f

我要说的是,在开发中升级链码所需的时间与重新创建整个区块链所需的时间相同(不提取新图像-应该从./runApp.sh脚本中删除该图像)。

答案 2 :(得分:0)

您可以简单地尝试在通道上安装新的链码,然后实例化新安装的链码。

安装链码:

docker-compose --file ./dockercompose/docker-compose-a.yaml run --rm "cli.a.example.com" bash -c "CORE_PEER_ADDRESS=peer0.a.example.com:7051 peer chaincode install -n abc -v 1.0 -p /opt/chaincode/node/javascript -l node"

实例化链码:

docker-compose --file ./dockercompose/docker-compose-a.yaml run --rm "cli.a.example.com" bash -c "CORE_PEER_ADDRESS=peer0.a.example.com:7051 peer chaincode instantiate -n abc -v 1.0 -c '{\"Args\":[]}' -o orderer.example.com:7050 -C common  --tls --cafile /etc/hyperledger/crypto/orderer/tls/ca.crt"