0

我正在使用超级账本结构 V1.4 中提供的byfn 网络编写链代码应用程序。当我添加或删除一些代码时,我关闭了 byfn 网络并删除了 docker 容器,然后重新启动了 byfn 网络,使用与以前相同的名称和版本来安装和实例化代码。我发现如果使用与以前相同的版本,更改的代码并不费力。

我认为这与我预期的不一样,因为我关闭了网络并删除了容器。我使用 docker volume ls 和 inspect 命令,发现 net_peer0.org1.example.com 下的文件在 byfn 网络关闭时被清除,因此没有现有的以前版本的代码。我想知道为什么更改后的代码不费力,以及为什么在我升级到以前未使用过的新版本后它可以工作。

docker compose 文件和 byfn 教程提供的一样:

docker-compose-base.yaml

# Copyright IBM Corp. All Rights Reserved. 
# 
# SPDX-License-Identifier: Apache-2.0 
# 

version: '2' 

services: 

  orderer.example.com: 
    container_name: orderer.example.com 
    extends: 
      file: peer-base.yaml 
      service: orderer-base 
    volumes: 
        - ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block 
        - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp 
        - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls 
        - orderer.example.com:/var/hyperledger/production/orderer 
    ports: 
      - 7050:7050 

  peer0.org1.example.com: 
    container_name: peer0.org1.example.com 
    extends: 
      file: peer-base.yaml 
      service: peer-base 
    environment: 
      - CORE_PEER_ID=peer0.org1.example.com 
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 
      - CORE_PEER_LISTENADDRESS=0.0.0.0:7051 
      - CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052 
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052 
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:8051 
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 
      - CORE_PEER_LOCALMSPID=Org1MSP 
    volumes: 
        - /var/run/:/host/var/run/ 
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp 
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls 
        - peer0.org1.example.com:/var/hyperledger/production 
    ports: 
      - 7051:7051 

  peer1.org1.example.com: 
    container_name: peer1.org1.example.com 
    extends: 
      file: peer-base.yaml 
      service: peer-base 
    environment: 
      - CORE_PEER_ID=peer1.org1.example.com 
      - CORE_PEER_ADDRESS=peer1.org1.example.com:8051 
      - CORE_PEER_LISTENADDRESS=0.0.0.0:8051 
      - CORE_PEER_CHAINCODEADDRESS=peer1.org1.example.com:8052 
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:8052 
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:8051 
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051 
      - CORE_PEER_LOCALMSPID=Org1MSP 
    volumes: 
        - /var/run/:/host/var/run/ 
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp 
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls 
        - peer1.org1.example.com:/var/hyperledger/production 

    ports: 
      - 8051:8051 

  peer0.org2.example.com: 
    container_name: peer0.org2.example.com 
    extends: 
      file: peer-base.yaml 
      service: peer-base 
    environment: 
      - CORE_PEER_ID=peer0.org2.example.com 
      - CORE_PEER_ADDRESS=peer0.org2.example.com:9051 
      - CORE_PEER_LISTENADDRESS=0.0.0.0:9051 
      - CORE_PEER_CHAINCODEADDRESS=peer0.org2.example.com:9052 
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:9052 
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:9051 
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org2.example.com:10051 
      - CORE_PEER_LOCALMSPID=Org2MSP 
    volumes: 
        - /var/run/:/host/var/run/ 
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp 
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls 
        - peer0.org2.example.com:/var/hyperledger/production 
    ports: 
      - 9051:9051 

  peer1.org2.example.com: 
    container_name: peer1.org2.example.com 
    extends: 
      file: peer-base.yaml 
      service: peer-base 
    environment: 
      - CORE_PEER_ID=peer1.org2.example.com 
      - CORE_PEER_ADDRESS=peer1.org2.example.com:10051 
      - CORE_PEER_LISTENADDRESS=0.0.0.0:10051 
      - CORE_PEER_CHAINCODEADDRESS=peer1.org2.example.com:10052 
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:10052 
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:10051 
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:9051 
      - CORE_PEER_LOCALMSPID=Org2MSP 
    volumes: 
        - /var/run/:/host/var/run/ 
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp 
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls 
        - peer1.org2.example.com:/var/hyperledger/production 
    ports: 
      - 10051:10051

是 hyperledger fabric 1.4 的特性还是我的操作有问题?目前我通过在代码中添加输出并在 dev_peer.org.example.com 容器中查看它们进行调试,有没有更好的方法在超级账本中开发链代码?


更新

我在 cli 容器中的 peer0.org1 和 peer0.org2 中安装了名为 master 的链代码,版本为 1.0。我从 cli 容器中实例化了 peer0.org2 中的 master。我使用docker logs peerX.orgX.example.com命令来获取每个对等容器的日志。

日志如下:

#### the # statement is added by me to better understanding
### install in cli container
# peer0.org1
root@022d09eec585:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n master -v 1.0 -l java -p /opt/gopath/src/github.com/chaincode/master-liuqi/java/
2019-07-31 03:33:28.747 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-07-31 03:33:28.747 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-07-31 03:33:28.754 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 

# peer0.org2
root@022d09eec585:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n master -v 1.0 -l java -p /opt/gopath/src/github.com/chaincode/master-liuqi/java/
2019-07-31 03:33:31.878 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-07-31 03:33:31.878 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-07-31 03:33:31.884 UTC [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 

### instantiate in cli container
# peer0.org2
root@022d09eec585:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -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 -C mychannel -n master -l java -v 1.0 -c '{"Args":["init","mychannel"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
2019-07-31 03:33:44.978 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-07-31 03:33:44.979 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
root@022d09eec585:/opt/gopath/src/github.com/hyperledger/fabric/peer# 

### log of peer containers(part)
# peer0.org1
2019-07-31 03:33:34.913 UTC [endorser] callChaincode -> INFO 069 [mychannel][f98c11ee] Entry chaincode: name:"mycc" 
2019-07-31 03:33:34.916 UTC [endorser] callChaincode -> INFO 06a [mychannel][f98c11ee] Exit chaincode: name:"mycc"  (3ms)
2019-07-31 03:33:34.916 UTC [comm.grpc.server] 1 -> INFO 06b unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.18.0.7:34946 grpc.code=OK grpc.call_duration=3.875297ms
2019-07-31 03:33:36.936 UTC [gossip.privdata] StoreBlock -> INFO 06c [mychannel] Received block [4] from buffer
2019-07-31 03:33:36.938 UTC [committer.txvalidator] Validate -> INFO 06d [mychannel] Validated block [4] in 2ms
2019-07-31 03:33:36.944 UTC [kvledger] CommitWithPvtData -> INFO 06e [mychannel] Committed block [4] with 1 transaction(s) in 5ms (state_validation=0ms block_commit=3ms state_commit=0ms)
2019-07-31 03:33:48.969 UTC [gossip.privdata] StoreBlock -> INFO 06f [mychannel] Received block [5] from buffer
2019-07-31 03:33:48.971 UTC [committer.txvalidator] Validate -> INFO 070 [mychannel] Validated block [5] in 1ms
2019-07-31 03:33:48.971 UTC [cceventmgmt] HandleStateUpdates -> INFO 071 Channel [mychannel]: Handling deploy or update of chaincode [master]
2019-07-31 03:33:48.975 UTC [kvledger] CommitWithPvtData -> INFO 072 [mychannel] Committed block [5] with 1 transaction(s) in 4ms (state_validation=0ms block_commit=2ms state_commit=0ms)

# peer0.org2
2019-07-31 03:33:34.918 UTC [endorser] callChaincode -> INFO 060 [mychannel][f98c11ee] Entry chaincode: name:"mycc" 
2019-07-31 03:33:34.920 UTC [endorser] callChaincode -> INFO 061 [mychannel][f98c11ee] Exit chaincode: name:"mycc"  (2ms)
2019-07-31 03:33:34.920 UTC [comm.grpc.server] 1 -> INFO 062 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.18.0.7:38430 grpc.code=OK grpc.call_duration=3.319442ms
2019-07-31 03:33:36.936 UTC [gossip.privdata] StoreBlock -> INFO 063 [mychannel] Received block [4] from buffer
2019-07-31 03:33:36.937 UTC [committer.txvalidator] Validate -> INFO 064 [mychannel] Validated block [4] in 1ms
2019-07-31 03:33:36.942 UTC [kvledger] CommitWithPvtData -> INFO 065 [mychannel] Committed block [4] with 1 transaction(s) in 5ms (state_validation=0ms block_commit=3ms state_commit=0ms)
2019-07-31 03:33:44.980 UTC [endorser] callChaincode -> INFO 066 [mychannel][c3207bea] Entry chaincode: name:"lscc" 
2019-07-31 03:33:46.959 UTC [endorser] callChaincode -> INFO 067 [mychannel][c3207bea] Exit chaincode: name:"lscc"  (1979ms)
2019-07-31 03:33:46.960 UTC [comm.grpc.server] 1 -> INFO 068 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.18.0.7:38444 grpc.code=OK grpc.call_duration=1.980230957s
2019-07-31 03:33:48.976 UTC [gossip.privdata] StoreBlock -> INFO 069 [mychannel] Received block [5] from buffer
2019-07-31 03:33:48.977 UTC [committer.txvalidator] Validate -> INFO 06a [mychannel] Validated block [5] in 1ms
2019-07-31 03:33:48.977 UTC [cceventmgmt] HandleStateUpdates -> INFO 06b Channel [mychannel]: Handling deploy or update of chaincode [master]
2019-07-31 03:33:48.981 UTC [kvledger] CommitWithPvtData -> INFO 06c [mychannel] Committed block [5] with 1 transaction(s) in 4ms (state_validation=0ms block_commit=2ms state_commit=0ms)
4

1 回答 1

0

在启动 byfn 网络超级账本时,使用 dev-peer 来安装链码。

更新链码可以通过两种方式完成

1.用一个新的链码版本实例化。这可以自己startfabric.sh完成

2.删除开发者的现有图像。

 docker rmi -f $(docker images dev* -q)

还原它不起作用!

于 2019-07-31T04:28:16.567 回答