Hyperledger Fabric - Peer unable to join channel - hyperledger-fabric

We are getting an error while trying a peer node to join a channel. Both members have separate peer nodes and separate EC2 machines acting as clients for the network. Member1 has created a channel and joined its peer node to the channel. Member2 has pulled the genesis block from their client but when trying to join the channel, we get the error:
Error: genesis block file not found open ourchannel.block: no such file or directory
despite seeing ourchannel.block in the directory we run the command. The command we're using to join the channel is:
docker exec -e "CORE_PEER_TLS_ENABLED=true" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/home/managedblockchain-tls-chain.pem" \
-e "CORE_PEER_ADDRESS=$PEER" \
-e "CORE_PEER_LOCALMSPID=$MSP" \
-e "CORE_PEER_MSPCONFIGPATH=$MSP_PATH" \
cli peer channel join -b ourchannel.block \
-o $ORDERER --cafile /opt/home/managedblockchain-tls-chain.pem --tls

You only have the genesis block (the file with .block extension) if you create a channel in a separate container, which is cli container in your case. Please check by using ls command inside the cli container.
A simple command to jump into cli container:
docker exec -it cli bash
Just in case you can't find genesis block, you can get it from the orderer (remember to modify the path to the cafile fit your project):
peer channel fetch 0 ourchannel.block -o orderer.example.com:7050 -c ourchannel --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
After this, you can join the channel with peer channel join command.

Simple issue, we had to specify the absolute path to the block file.
Instead of
cli peer channel join -b ourchannel.block
we used
cli peer channel join -b /opt/home/ourchannel.block \
and it worked.

Related

Querying a single value in Hyperledger Fabric is taking 10-20sec

I have just built a Hyperledger Fabric 1.4.4 network on 2 org / nodes / orderers using with Raft https://github.com/Altoros/Ansible-Fabric-Starter
The network is working great, but when I try to select a single value from my custom chaincode, query takes 10-20 secs, quite a lot. I'm using LevelDB.
It is hosted on 2 x t3a-small instances on AWS ( 2vCPU, 2GB Ram )
When it comes to writing a data, it is not so long (258 ms) which is acceptable.
How should I improve the read latency ? Is it just a matter of infrastructure ( vertical scaling for my VMs) or did I forget a configuration ?
At ansible-fabric-starter that you delivered, it seems that the chaincode query function is called through the peer chaincode invoke command.
test_bilateral.yml
...
raw: "docker exec cli.{{ org }}.{{ global_domain }} bash -c 'peer chaincode invoke --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ global_domain }}/tlsca/tlsca.{{ global_domain }}-cert.pem --tls -o orderer{{ orderer_id | default(0) }}.{{ global_domain }}:7050 -C {{ invoke_channel_name }} -n {{ chaincode_name }} -c {{ chaincode_update_json | to_json }}'"
...
test.yml
...
raw: "docker exec cli.{{ org }}.{{ global_domain }} bash -c 'peer chaincode invoke --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ global_domain }}/tlsca/tlsca.{{ global_domain }}-cert.pem --tls -o orderer{{ orderer_id | default() }}.{{ global_domain }}:7050 -C {{ invoke_channel_name }} -n {{ chaincode_name }} -c {{ chaincode_update_json | to_json }}'"
...
In other words, when you see the transaction flow, it is inferred that your query command searches the ledger, sends the result to the orderer, and includes all the latency until the blockchain is updated.
peer chaincode invoke includes the process of reflecting the endorsement of the transaction proposal to the ledger (ordering/block packaing/validationCheck(with mvcc)/eventEmit...).
The query in the chaincode is simply a function in ansible-fabric-starter and should not be confused with the peer chaincode query on the fabric network. Try to run it based on the peer chaincode query command.
here's an additional example to help you understand.
peer chaincode invoke '{"Args":["invoke","a","100"]}'
# stdout : a = 100
# fabric : a = 100, [blockchain]: added block;
peer chaincode query '{"Args":["invoke","a","300"]}'
# stdout : a = 300
# fabric : a = 100
# something... like simulation
peer chaincode invoke '{"Args":["query","a"]}' # this is your situation
# stdout : a = 100
# fabric : a = 100, [blockchain]: added block;
peer chaincode query'{"Args":["query","a"]}' # change like this
# stdout : a = 100
# fabric : a = 100

Endorsement from multiple peers one arg

I have a multiple peer, one org Org1MSP network where I want the transactions to be endorsed by multiple peers.
Is there a way to specify endorsement policy using CLI for e.g. during instantiate chaincode
For e.g.
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n
mycc -v 1.0 -c '{"Args":[]}' -P "OutOf(2, 'Org1MSP.peer')"
Just specify the same org twice with an AND:
AND('Org1MSP.peer', 'Org1MSP.peer')

Error in starting Hyperledger fabcar sample application

I am trying to run fab car sample application from http://hyperledger-fabric.readthedocs.io/en/release-1.1/write_first_app.html
when ./startFabric.sh node trying to create channel with below command
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
It gives error as
flag provided but not defined: -e
What am I doing wrong here?
The Fabric samples require Docker 17.06.2-ce or later

Getting error when adding new Peer to basicnetwork-Tuna App

We are using Tuna-App to setup basicnetwork along with tuna-app, and trying to add additional peer. Here is the source code of tuna-app
https://github.com/hyperledger/education/tree/master/LFS171x/fabric-material
We are able to add the Peer to the basicnetwork. We verified docker containers, all peer0, peer1, cli, ca, orderer, coughdb, coughdb2, and tuna-app-1.0 are running.
Peer0 sucessfully got added to channel with following command:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block
We are trying to add Peer1 to the same channel with command:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer1.org1.example.com peer channel join -b mychannel.block
it throws an error:
genesis block file not found open mychannel.block: no such file or directory
Please help me. How can we resolve this issue?
Enter the cli container:
docker exec -it cli bash
In that terminal, export the required variables:
export CHANNEL_NAME=mychannel
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
Add the peer to the channel:
peer channel join -b mychannel.block
Try the below commands:
docker exec peer1.org1.example.com peer channel fetch 0 mychannel.block -o orderer.example.com:7050 -c mychannel
docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#$org1.example.com/msp" peer1.org1.example-swarm.com peer channel join -b mychannel.block
Create channel from the CLI container. As in firstnetwork.
Because mychannel.block is available only in peer0.
You can't join the channel from peer1 since no mychannel.block file is available.

Error while trying to join peer to channel in fabric

I am trying to build a fabric network with two channels. One peer is able to join the channel but while trying to join the second peer to channel getting following error:
Error: genesis block file not found open mychannel.block: no such file or directory
this is my code used for channel creation and joining peers:
Creating channel:
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org2.example.com/msp" peer0.org2.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
Joining peers:
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org2.example.com/msp" peer0.org2.example.com peer channel join -b mychannel.block
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block
Please correct if something is wrong.
i run in the same situation and find a solution.
Since the mychannel.block is known only to peer0.org2.example.com container, all the joins have to be done from there.
For the second peer you can issue:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" -e "peer0.org1.example.com:7051" peer0.org2.example.com peer channel join -b mychannel.block
M
The issue is that mychannel.block is only available within the peer0.org2.example.com container (since that is the container where you ran the channel create command). The peer0.org1.example.com container does not have access to mychannel.block and that's why you get the error.
What you will need to do is to actually have to do is mount a shared volume for both containers and make sure that you when you run channel create that mychannel.block is output in the shared volume
I had the same problem, but the scenario was slightly different: I had two peers (peer0 and peer1) in one org (org1). I used the following commands to join them to the same channel, and it works:
//Join peer0.org1.example.com to the channel
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e
"CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp"
peer0.org1.example.com peer channel join -b mychannel.block
//Join peer1.org1.example.com to the channel.
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e
"CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" -e "CORE_PEER_ADDRESS=peer1.org1.example.com:7051" peer0.org1.example.com peer
channel join -b mychannel.block
you need to check your docker-compose.yaml file to see how you're mapping volumes in there
in the definitions of the two peers, ensure there is a common mapped volume, for example in peer0 you may have something like this;
volumes:
- /var/run/:/host/var/run/
- ./:/etc/hyperledger/configtx
- ./crypto-config/peers/peer0/msp:/etc/hyperledger/peer/msp
- ./crypto-config/users/user0/msp:/etc/hyperledger/msp/users
and in your peer1 you may have;
volumes:
- /var/run/:/host/var/run/
- ./:/etc/hyperledger/configtx
- ./crypto-config/peers/peer1/msp:/etc/hyperledger/peer/msp
- ./crypto-config/users/user1/msp:/etc/hyperledger/msp/users
You can see here there are two shared volume mappings, the first two in each definition point to the sample place.
So to be clear, the volume mapping is defined as follows:
[path on local machine]:[path to map in docker image]
This issue is due to mychannel.block was not found in peer0.org1.example.com
You can copy mychannel.block from peer0.org2.example.com to peer0.org1.example.com
try these commands
docker cp peer0.org2.example.com:/opt/gopath/src/github.com/hyperledger/fabric/mychannel.block mychannel.block
docker cp mychannel.block peer0.org1.example.com:/opt/gopath/src/github.com/hyperledger/fabric/
sudo rm mychannel.block
Now try rejoining peer0.org1.example.com to mychannel.

Resources