Blockchain fabric samples: Latest chaincode not getting picked by by ./startFabric.sh - hyperledger-fabric

I am running Docker Toolbox on Windows. I have downloaded fabric samples from https://github.com/hyperledger/fabric-samples. Modified the fabcar chaincode.
The first time I ran ./startFabric.sh to bring up the local blokchain network, the chaincode is getting picked up well and fine.
Now I make further changes to fabcar chaincode. But this time, my latest chaincode changes are not being picked up by the blockchain network. I still see old log messages and responses.
I have tried the following options already:
1) clearing up docker containers
2) restarting docker toolbox.
3) rerunning ./startFabric.sh from scratch.
The only time my chaincode changes are picked up is the "first ever time" when i use that particular chaincode. Thereafter the first chaincode somehow resides in the memory forever.
Please let me know what I am doing wrong.
Thanks!

After changing chaincode in fabric-samples/chaincode/fabcar/go/fabcar.go (this is where you change the chaincode, I presume), you have to go build fabcar.go so that latest compiled code gets into the peer.

./startFabric.sh add a new docker image and use it as chaincode container.
To run updated chaincode, remove this container and execute ./startFabric.sh again.
docker rmi -f dev-peer0.org1.example.com-docchain-1.0-961b279a2d42ac81dd6585a11d9fad6bfe4f000a2c3d0cdc9be4bd1ecdf5610d

Related

Error deploying Fabric test-network fabcar chaincode

I am following the documentation (https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html) to deploy a test network for Fabric on Ubuntu 16.04 on Amazon Lightsail. All commands have been executed successfully with results as expected until
./network.sh deployCC -l javascript
The following error message is received:
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction 2554869d3683a7e77202f448aa201fd2f97243faa4ff5dd4839eb8d3175cf53b: could not launch chaincode fabcar_1:bec08b518fdb2bda0a0fb41a4a6f996a87ba08887583febedbc791cba7e91537: chaincode registration failed: container exited with 0" !!!!!!!!!!!!!!! Invoke execution on peer0.org1 peer0.org2 failed !!!!!!!!!!!!!!!!
Any assistance will be tremendously appreciated.
K
For fabcar sample, you can use startFabric.sh script inside fabcar to deploy chaincode with the language that you want. Specifically run ./startFabric.sh javascript in your case.
This script generally runs ./network.sh with some additional network cleanups.
everything is working as expected now. The issue had been with system sizing - increasing the memory to 4GB RAM fixed it
Thank you everyone for your suggestions.
K
I am assuming that you are doing a fresh installation.First stop all the containers if it's not stop.
docker stop $(docker ps -a -q)
After that remove the unused volume using the command.
docker volume prune
or docker system prune to remove any unused data.
You have to remove the certificates manually(if it's not deleted).First of all execute the ./network.sh down command.Then go into the test-network/organizations and remove the content of peerOrganizations and ordererOrganizations
Then move to the fabric-ca directory and remove the content of org1 ,org2 and ordererOrg, keep in mind that in here you don't have to remove any .yaml file.
And remove the fabcar.tar.gz package in test network.
Now start the network using the commands below:
./network.sh up createChannel -ca -c mychannel -s couchdb -i 2.0.0
./network.sh deployCC -l javascript
I have the same problem with javascript chaincode (it works 2 days ago, having the same error now), but deployCC with golang (weirdly) doesn't have this problem. So if using javascript is not a requirement you can also just run ./network.sh deployCC
Shut down your network. Then start it again. Then create a channel and deploy your chaincode. It will work.
I was getting same error because I created a named channel first and tried to deployed code there with -c. But when I shutdown and performed all steps again with default "mychannel" and it worked fine for me.

BNA install request timeout

So I've started hyperledger fabric following this tutorial:
https://medium.com/coinmonks/hyperledger-fabric-cluster-on-multiple-hosts-af093f00436
Everything seems to be working fine, but now I want to install my bna on it.
I do it using command:
composer network install --card PeerAdmin#hlfv1 --archiveFile my-network#0.0.1.bna
But after some time I get request time out error:
Error: Error trying install business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: REQUEST_TIMEOUT
Command failed
I've tried adding this to my peer's environment:
- CORE_CHAINCODE_STARTUPTIMEOUT=1200s
However, it seems that it had no effect and timeout occurs earlier than 1200s after the launch of command.
Also, I checked all of my container's docker logs but didn't find any errors.
I guess for some reason timeout time is either not being increased or there's some connection error while installing the network.
I expect bna to be installed just as in the tutorial. To be clear, if I install network as in the tutorial, everything works just fine, but now I need hyperledger fabric to run in different machines and use different peers.
Hyperledger composer can't connect to the hyperledger fabric network.
I also had a lot of these issues.
My tip: Restart everything and try again.
This often resolves the problem. Hope this helps.
Happy coding :)
As a note, Composer is all but dead. We are no longer actively maintaining, or developing it. So changes to the Fabric codebase can have negative effects against Composer.

Can you kill a smart contract in Hyperledger Fabric

Can you delete hyperledger fabric smart contract like the kill function in ethereum?
To kill a chaincode(Smart contract) you need to follow following steps:
Kill chaincode containers belonging to respective chaincode version, which you want to kill. You may kill containers using following command:-
docker rm -f [Chaincode docker container's ids separated by space]
Delete chaincode images, using following command:-
docker rmi [Chaincode images ids]
Delete the chaincode from the file system of each peer under /var/hyperledger/production/chaincodes
Right now this is the procedure to uninstall a chaincode, in future there will be stop and start command to stop and resume a smart contract respectively. You may checkout the same in official documentation:-
Hyperledger fabric chaincode lifecycle
You can remove the containers and images for your smartcontract, but if you go to the peer container the foulder /var/hyperledger/production/chaincodes is empty.
If you run hyperledger explorer you will see that the contract remains and if you want install again with same name obtains an error, so the question is where and how you can remove this link in hyperledger 2.3?

Fabric Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection

There was an Hyperledger Fabric error updating the anchor peer in the Building Your First Network document. This error is as follows.
Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: x509: certificate signed by unknown authority
I need your help.
I fixed by bringing the network down (byfn.sh down)
and then up again (byfn.sh up).
Please see this link for more information:
How to fix "FAILED to execute End-2-End Scenario" in Hyperledger Fabric?
x509: certificate signed by unknown authority
This error is due to the certificate format mismatch, It happed to me when I used v1.0 cryptogen tool for certificate generation and ran the network with v1.1 Fabric containers.
So, try to update the cryptogen tool from here -> http://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html#binaries.
I don't know what version you were using so, I assumed it would be v1.1. So, please specify the Hyperledger Fabric version you were using.
One of the problems could be that you have an old version of the Hyperledger Example and you are pointing to an old version of the Cryptogen tool. So if you download a newer example, when you generate the crypto-config it will generate it with the old version of the cryptogen tool, this could make your orderer container to stop, cause can validate the certificate generated.
This is because the differents versions of the cryptogen tool generate different metadata.
My suggest is to check if the cryptogen version that you are using is the one contained in your downloaded image of your example. If you had run lot of tests, clean all the docker images and containers, that always help.
If nothing of that works, I wrote a tutorial based on the basic-network example and how to run it in multiple hosts, maybe you can take some information from there.
https://medium.com/1950labs/setup-hyperledger-fabric-in-multiple-physical-machines-d8f3710ed9b4
Please, feel free to ask, if you have doubts!
This error is due to channel capabilities are set as true for v.1.4.0 so you should change it to false so that it can run for every version of the fabric.
Try:
docker ps -a
to find container ID of hyperledger orderer and peer images. Then try:
docker rm *container_ID*
to remove them. After you can run ./network.sh up createChannel.
so for this error i tried doing byfn.sh down and byfn.sh up but after that it threw another error, which i solved by first killing all the containers, removing them, cleaning all images and volumes that already exist and restarted the tutorial. to kill and remove processes and images and cleaning my system.
https://medium.com/coinmonks
docker kill $(docker ps -q)
docker rm $(docker ps -qa)
docker system prune -a
docker volumes prune -a
delete fabric-samples directory and start from the beginning and you're ready to go.

Unable to modify Chaincode in hyperledger fabric

I downloaded the fabric-sample example from the command in linux,
given in the document "http://hyperledger-fabric.readthedocs.io/en/v1.0.0-beta/getting_started.html#install-prerequisites"
I followed the document to start the network, and script.sh
is running successfully.
now when I am modifying the chain code from my local system at "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
chaincode modification is not reflecting in the output.
please suggest me, how to run my own chaincode.
If your target is to run your own chaincode, the recommended way is to follow the chaincode developers guide here. Normally, the chaincode is started and maintained by peer, but this chaincode dev mode allows user to start chaincode for easier testing and development. If you are starting by modifying existing chaincode, you may omit the code-building section and concentrate on the other steps (creating proper directories, building them etc)
When you start your network, you get some Peers and an Orderer. In that step you copy the chaincode that it's in the predefined directory, i.e. a predefined chaincode is copied for you. You define that directory in the docker-compose-cli.yaml file, in the line - ./chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode So, if you want to change the chaincode that is copies to your Blockchain, you should change in that directory.
So, any change that you do in your local machine won't have any effect on the chaincode of the Peer. If you want to run your own chaincode, you have to define it previously, before starting up your network. Then, you will hava it in the corresponding docker container.
You can develope your own chaincode and pass it to the cli container by executing the following command:
docker cp yourchaincode.go cli:/opt/gopath/src/github.com/hyperledger/fabric/examples/mychaincode/yourchaincode.go

Resources