HyperLedger fabric chaincode not updated

update chaincode hyperledger fabric
how to deploy chaincode in hyperledger fabric
hyperledger fabric system chaincode plugin
hyperledger fabric sdk
hyperledger fabric tutorial
hyperledger fabric chaincode testing
transactions deploy new chaincode to the hyperledger fabric blockchain
which entity in hyperledger fabric executes the chaincode

I am trying to follow along this sample Hyperledger Fabric code: https://github.com/hyperledger/education/tree/master/LFS171x/fabric-material

Initially I replaced chaincode/tuna-app/tuna-chaincode.go with my go file chaincode/tuna-app/test.go. test.go had changes just in what we initialize in the ledger through its initLedger function call. It worked fine, with no changes required in tuna-app/.startFabric.sh.

Now when I again try to change the ledger through its initLedger function call, its not happening. Even if I comment the function itself, it still shows the old content of the ledger.

How do I update my chaincode with visible changes?

startFabric.sh contains the following code:

set -e

# don't rewrite paths for Windows Git Bash users

starttime=$(date +%s)

if [ ! -d ~/.hfc-key-store/ ]; then
    mkdir ~/.hfc-key-store/

# launch network; create channel and join peer to channel
cd ../basic-network

# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 tuna catches
docker-compose -f ./docker-compose.yml up -d cli

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n tuna-app -v 1.0 -p github.com/test-app
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"

I tried by adding the following line after peer chaincode instantiate :

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

But it gives the following error:

Error: Chaincode version is not provided for upgrade

When I change upgrade statement to:

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"function":"initLedger","Args":[""]}'

Error changes to:

Error: Error endorsing chaincode: rpc error: code = Unknown desc = chaincode error (status: 500, message: version already exists for chaincode with name 'tuna-app')

To make the changes in the chaincode made reflect, following steps were taken: 1. Stop all the containers

docker stop $(docker ps -aq)
  1. Delete all the containers

docker rm -f $(docker ps -aq)

  1. Find the following image when you run docker images One of the output will be this among the other hyperledger binary images.

REPOSITORY TAG, IMAGE ID, CREATED, SIZE: dev-peer0.org1.example.com-tuna-app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b, latest, 0919d7c15f0a, 3 minutes ago, 172MB

Delete it using the following command:

docker rmi 0919d7c15f0a

Run the fabric again using ./startFabric.sh, npm install, node registerAdmin.js, node registerUser.js and node server.js. It should work

Hyperledger fabric overcoming chaincode not updated after code , Sometimes, there is an odd behavior in Hyperledger fabric, the deployed chaincode is not really updated. and you get a version of a previous  Hyperledger Fabric: Cannot update chaincode . 0 votes. startFabric.sh: set-e # don't rewrite paths for Windows Git Bash users export MSYS_NO_PATHCONV = 1 starttime

I would guess you alrwady have version 1.0 installed, thats why its complaining that it already exists. Try it with 1.1 or 2.0 by using -v 2.0 instead of -v 1.0.

Chaincode for Operators - Hyperledger Fabric Docs, Additionally, the Hyperledger Fabric API can be accessed directly via the CLI, which we will use to disable and re-enable a chaincode without having to actually uninstall it. A chaincode may be upgraded any time after it has been installed. If you updated the chaincode definition without changing the chaincode version, the chaincode container will remain the same and you do not need to invoke Init function. Once the new definition has been committed to the channel, each peer will automatically start the new chaincode container.

It's pretty tricky once you miss the sequence. As per my knowledge, deployment of a chaincode in HLF is a two step process.

Step 1. Transfer the source code into the peer ( each chaincode gets a chaincode id which approximately is a function of their name, path and version). This gets signed by your keys and transferred to the all the peers you have chosen as target. ( This step by the way, is called installation. )

Step 2. The source code is compiled, with all the vendor libs ( I'm talking about the GoLang chaincode version here, hoping that it would be same for the other ones too.). A docker image is built and a container gets formed with that binary. ( This is the part which is known as instantiation - which also becomes an Upgrade if it's already done earlier. )

In this process, the step 1 would want the chaincode to be unique. If you have installed once, then if you want to send it again, then make sure you have changed the version number to say abc-1.0 to abc-2.0. This will save you at Installation step.

Once your installation is successful, then it's the matter of when to call for an upgrade and when not. If you have run this container earlier, then right step is to upgrade.

Or the other way around is to do what you did. Clean up and start fresh - which works ok for development, but not for production - as your data goes "poof" with that clean up.

Considerations for getting to v2.0 - Hyperledger Fabric Docs, The new chaincode lifecycle that debuts in v2.0 allows is not strictly required, but it makes sense to update it at this time). Fabric; FAB-17933; Fix cache update logic for installed chaincode info when specifying an empty or uninstalled package ID

when developing chaincode on hyperledger fabric.

1: we have to remove chaincode docker image for testing each change. For Example: name of install chaincode is mycc

#remove container
docker rm -f $(docker ps -aq)
#remove images
docker rmi mycc-0-container id or name

2: you can install chaincode just by changing its name like mycc is currently running then you have to change mycc1 and now you need to use mycc1 and perform your transactions. For Example:

#Already install chaincode has named mycc
#following command will install same chaincode(updated) with chaincodeName
docker exec cli peer chaincode install -n mycc1 -v 0 -p github.com/sacc

Note: now you need to instantiate , invoke and query chaincode with name mycc1.

Hyperledger Fabric: Cannot update chaincode, Hyperledger Fabric: Cannot update chaincode. 0 votes. startFabric.sh: set -e # don't rewrite paths for Windows Git Bash users export  Hello, I would like to know what is the fastest way of developing chaincode and fabric-node-sdk with from the message archives of fabric@lists.hyperledger.org?

Is it possible to update or alter smart contract (chaincode) deployed , we cannot update the installed chaincode for a certain channel, but we can use the chaincode version to distinguish with the newer updated  If the entire channel is not yet ready to upgrade the chaincode, you can use peer environment variables to specify the v1.4 chaincode environment ccenv be used to rebuild the chaincode images. This v1.4 ccenv should still work with a v2.0 peer.

Installing, instantiating, and updating a chaincode, Chaincode is installed on a peer, then instantiated on a channel. dependencies for chaincode that is written in GO in the Hyperledger Fabric documentation. Endorsement policies are not updated automatically when new​  Hyperledger is being chosen by many new innovators to handle their blockchain end of things, due to its high TPS and behaviour as a blockchain as a service plat

Can I query Hyperledger Fabric ledger or update ledger without , update ledger without chaincode in peer? I have simple question about Hyperledger Fabric. so here is my question: I have simple question about Hyperledger  The codebase itself is unit tested (not yet integration tested), coverage around 90 % using the same test values as the Node.js version. I've also included two samples, a very simple AssetHolding and the FabCar sample. Additionally, within the repo, there's a modified fabric-ccenv which includes the .NET Core Runtime to run the Chaincode Shim.