I have few basic doubts regarding creating a channel in fabric. I was trying to set up the first network with individual commands.
I came across multiple commands for creating channel but unable to understand the difference
a. sudo docker exec peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c composerchannel -f /etc/configtx/composer-channel.tx — tls true — cafile /etc/configtx/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
b. peer channel create -o orderer.example.com:7050 -c mychannel1 -f ./channel-artifacts/channel1.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA
Does channel need to be created under an orderer container or peer container?
in the above command I can see peer0.org1.example.com with exec, is it given to create the channel inside the peer container?
In the command b peer0.org1.example.com is not given, is it because we run this command inside CLI?
I just wanted to understand how to works with the channel creation syntax?
I can see why this can be confusing. At a high level:
In order to create a channel, you need to submit a configuration
transaction to an orderer node (aka "create channel").
In order for peers to receive blocks from a channel and to invoke
chaincode on a channel, you need to call the "join channel API" on
each peer.
The confusing part is that there is only a single CLI (command-line interface) for performing both actions and it is actually the peer executable.
So when you call peer channel create ... you are actually sending a configuration transaction to an ordering node.
You can either execute the peer ... commands inside a container which has the peer executable ( that's the docker exec ... you show above ) or you can run the peer binary on a host system and do the same thing (the second option you show above runs it within the CLI container).
Related
I am trying to develop a supply chain application using Hyperledger Fabric.
During development, I am using Hyperledger Fabric Test Network and I added a 3. organization using "addOrg3.sh" command. All the codes I used when I start the network are listed below.
cd ../test-network
./network.sh down
docker rm -f $(docker ps -aq)
./network.sh up createChannel -ca -s couchdb
cd addOrg3
./addOrg3.sh up -c mychannel -ca -s couchdb
export FABRIC_CFG_PATH=$PWD
../../bin/configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json
cd ..
./network.sh deployCC -ccn SupplychainContract -ccp ../supply-chain/chaincode/ -ccl javascript -ccep "OR('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
cd ../supply-chain/server
rm -r ./wallet/*
node enrollAdmin.js org1 admin adminpw
node enrollAdmin.js org2 admin adminpw
node enrollAdmin.js org3 admin adminpw
chmod 777 wallet
chmod 777 ./wallet/*
However, on the running project, while using a wallet belonging to the org3 network, I can run submitTransaction command on the chaincode without any problem, but when I try to run the evaluateTransaction command, it gives an error as follows.
ERROR MESSAGE: 2022-12-07T12:45:38.620Z - error: \[SingleQueryHandler\]: evaluate: message=Query failed. Errors: \["Error: Peer peer0.org3.example.com:11051 is not running chaincode SupplychainContract"\], stack=FabricError: Query failed. Errors: \["Error: Peer peer0.org3.example.com:11051 is not running chaincode SupplychainContract"\]
When I call the related method using submitTransaction , there is no problem. if i use docker-compose -f ./compose/docker/docker-compose-org3.yaml up -d while raising the network, it conflicts with another container produced by addOrg3.sh .
How can I solve this problem?
I think the issue you are seeing is because the default query handler implementation prefers the client's org peers, and it also returns (either a result or an error) from the first peer it is able to successfully invoke. Your org3 client evaluates the transaction on the org3 peer, which responds with an error saying the smart contract is not deployed there.
The submit implementation is more complex and will use service discovery to identify peer that can satisfy the endorsement policy for a given chaincode, so will not attempt to use the org3 peer.
Using Fabric v2.2, your best options are probably either:
Deploy the chaincode on the org3 peer; or
Implement your own query handler that provides appropriate behaviour.
This tutorial page describes how to configure an alternative query handler and how to write a custom query handler:
https://hyperledger.github.io/fabric-sdk-node/release-2.2/tutorial-query-peers.html
A possible approach would be for your handler to use all network peers and to keep trying peers until it either receives an endorsed response or has tried all available peers.
If you can use Fabric v2.4 (or later), you should consider using the Fabric Gateway client API instead. This will just work without any additional configuration.
I clone the project fabric-samples to my file names HYFA.
I created the file names init.sh and copy the content of link https://github.com/hyperledger/fabric-samples/blob/release-1.3/scripts/bootstrap.sh to it.
perform init.sh to download binary file and docker images.
Then I follow the official Docs Building Your First Network to config when I execute peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --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
Above command returns below error
Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
How can I solve this question?
I just got the same error and what I did was prune my containers and such (restart network in short). It works again. This may not be the solution for you but please add more details :)
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 am working on this tutorial http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
To Create and Join Channel i am trying to run following peer command :
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
I am connected to container as well after executing docker exec -it cli bash. Even i have tried ./peer but i am still getting no peer directory exist or peer command not found
This may be due to relative path is not correct, where peer binary is stored. You can find it inside hyperledger/fabric/build/bin. Once you locate the peer binary export it using.
e.g. export PATH=$PATH:$GOPATH/src/github.com/hyperledger/fabric/build/bin/
Then try to create channel using commands you are using.
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