Search code examples
hyperledger-fabrichyperledger-chaincode

The changed code in chaincode does not take effort after restart the BYFN network?


I'm writing chaincode application using the provided byfn network in hyperledger fabric V1.4. When i add or delete some codes, i shutdown the byfn network and remove the docker container, and then restart the byfn network, install and instantiate the code using the same name and version as before. I found if using the same version as before, the changed code does not take effort.

I think it is not the same as i expected since i shutdown the network and remove the container. I use docker volume ls and inspect command, found the file under net_peer0.org1.example.com cleard when the byfn network down, so there was no exsiting previous version of codes. I wonder why the changed code doesn't take effort and why it works after i upgrade to a new version which has not been used before.

The docker compose file is the same as provided by the byfn tutorial:

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

Is the feature of hyperledger fabric 1.4 or there is something wrong in my operation? Currently i debug by adding output in the code and see them in dev_peer.org.example.com containers, Is there a better way to develop chaincode in hyperledger?


Update

I install the chaincode named master with version 1.0 in peer0.org1 and peer0.org2 from the cli container. I instantiated master in peer0.org2 from the cli container. And i use docker logs peerX.orgX.example.com command to get the log of every peer container.

The log is as follows:

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

Solution

  • While starting the byfn network hyperledger uses dev-peer where chaincode would be installed.

    Updating the chaincode can be done in two ways

    1.Instantiate with a new chaincode version.this can be done in the startfabric.sh itself

    2.Remove the existing images of the dev-peers.

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

    Do revert in it doesnt work!