I have couple a questions regarding HF CLI docker container and some of CLI commands.
First of all, can someone explain the purpose of this container in context of docker container which is started alongside other docker containers required for HF ecosystem. How can I for example query my business network organisations, different peers, and chain-code status on those peers?
Second of all, when I install a chain code issuing peer chaincode install CLI command, to which peer is that code installed (if i have 5 peers attached to org1.example.com organisation, on which peer aforementioned command will install the targeted chain code)?
And third of all, if I have just one organization in my business network specification which handles multiple peers and channels, when I try to instantiate the installed code issuing peer chaincode instantiate command, how to specify the endorsement policy (http://hyperledger-fabric.readthedocs.io/en/latest/endorsement-policies.html) which has just one organisation in endorsement expression after the -P parameter?
Thank you for your help!
EDIT 1:
Just one update regarding 3rd answer. In you have one organisation maintaining peers and channels when instantiating chaincode, you can omit the endorsing policy parameter (-p). In that case transaction will be endorsed if any peer endorses it
Lots of great questions.
the "cli" container's purpose is to run a peer process as a CLI . It is a bit confusing that the same process is both a client and a server, we may change that. Basically, when you run the peer chaincode commands, you are running the CLI. The peer node commands are the server commands. The cli container in our samples runs a script (scripts/script.sh) which in turn executes a series of CLI commands against the peer nodes.
If you examine scripts/script.sh, you will find a setGlobals function that sets a few environment variables, including CORE_PEER_ADDRESS. This is the peer (server) to which the peer (CLI) will communicate when installing the chaincode.
Actually, after further research, this is not possible, unfortunately. The gate syntax isn't yet implemented. You would need to simulate multiple orgs for this.
Re the second part of this question.
Entering the CLI
docker exec -it cli bash
The bootstrapped peer for CLI is peer0.org1.example.com
Check which PEER you are on:
echo $CORE_PEER_ADDRESS
returns
peer0.org1.example.com:7051
Change to peer1.org1:
export CORE_PEER_ADDRESS=peer1.org1.example.com:8051
Also applies to LOCALMSPID, MSPCONFIGPATH, etc
Related
Hyperledger Fabric provides peer, peer chaincode commands: https://hyperledger-fabric.readthedocs.io/en/release-2.3/commands/peerchaincode.html
I have setup on different VMs. I am using commands like:
peer chaincode query on terminal on one vm
It should show the chaincode for the current value on a peer’s ledger.
Instead I get command not found error. What am i missing?
That is because the terminal doesn't know where to find the peer command. You have to set the $PATH environment variable to indicate the location of the peer binary file. From the doc
You may want to add that to your PATH environment variable so that these can be picked up without fully qualifying the path to each binary. e.g.: export PATH=/bin:$PATH
We know the chaincode is installed on every endoser peer, and only instantiated on one endoser peer.
1, so other peer will copy dev* image of chaincode and run it when needed?
Also, I found, when using composer to deploy/upgrade the chaincode, every endoser peer will run a ccenv docker container,
2, just the ccenv to build the chaincode, why not just use one peer to build the image and copy to other peer?
3, the ccenv build the chaincode, will be included in install step or the instantiate step for more clear instruction?
because i found too many ccenv run at the same time, often fails with one of them.
Fabric is a distributed system and therefore the expectation is that Peers are run as independent components not on the same machine in the same docker network for example (this will not be a valid deployment scenario, only a development scenario). This is why each peer needs to build and run it's instance of a chaincode container, you can't have one peer build the chaincode as the other peers being in their own environment will have no access to it
Hyperledger Composer will send instantiate requests to all peers on the channel so all those peers at instantiate time will build a version of the chaincode so it can run the instantiate transaction simulation.
ccenv is the container image that has the required components in order to build chaincode, it is not used to run chaincode.
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?
The CLI container is used to run below:
peer create channel
List item
peer join channel
peer install chaincode
peer instantiate chaincode
peer invoke chaincode
peer query chaincode
However the same can be achieved without creating a docker CLI container.So what is the actual purpose of it?
The Hyperledger Fabric CLI (peer command) can be run natively, without a docker container. For purposes of the samples, though, we can run the whole sample in the cloud, if one wishes. It just simplifies things a bit and allows us to be more prescriptive of the environment.
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