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
Related
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.
I am able to call the chaincode functionality by peer chaincode invoke as:
`peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"function":"initLedger","Args":["one", "two"]}`
But I want to pass javascript object as argument like:
`peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"function":"initLedger","Args":[ {property1:"one"}, {property2:"two"}]}`
but this fails with invalid character 'p' looking for beginning of object key string. I have tried few other permutations but all without success.
the documentation says about -c as:
-c, --ctor string Constructor message for the chaincode in JSON format (default "{}")
Can come one tell correct syntax to pass the object.
EDIT 1:
For the sake of completeness following
peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"function":"initLedger","Args": [{"property1":"one", "property2":"two"} ]}'
returns Error: Chaincode argument error: json: cannot unmarshal array into Go struct field strArgs.Args of type string
I think you might be using an old format of the invoke command, so I'm suggesting a new format like this including your stringified JSON object:
peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"Args":["initLedger","{\"property1\":\"one\",\"property2\":\"two\"}"]}'
But if you need to use your format then perhaps:
peer chaincode invoke -o localhost:7050 -C mychannel -n pmc -c '{"function":"initLedger", "Args": ["{\"property1\":\"one\",\"property2\":\"two\"}"]}'
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')
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
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.