Hyperledger Fabric "evaluateTransaction" ERROR - hyperledger-fabric

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.

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.

How to install custom chaincode?

I want to install custom chaincode on my hyperledger fabric channel. I put my chaincode.go file besides of my .yaml files .when I run this command :
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
I got this error:
Error: error getting chaincode code mycc: path to chaincode does not
exist: /opt/gopath/src/github.com/chaincode/chaincode_example02/go
I do not know where is opt/gopath or how to address the chaincode.go file?
please help me
When you launch your network (if you are using the first-network template), you bring up a container 'CLI', you can find it in docker-compose-cli.yaml
This container is used to operate on the differents nodes of the architecture.
You need to create a volume who match your chaincode path like so
Then, when the container 'cli' goes up, you can enter into it with
docker exec -it cli bash
Now you can navigate to your path and see your chaincode directory.
And do your command :
peer chaincode install -n mycc -v 1.0 -p path/define/in/your/volume/section/to/your/chaincode

create new channel and join peers

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).

Hyperledger Composer v0.16.0 network start error

I'm trying Hyperledger Composer v0.16.0. According to this procedure, I want to Deploy BNA to Fabric network on cloud. but following error occurs.
Kindly let me know how I can solve it.
command:
composer network start --card PeerAdmin#myfabric --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile trade-network.bna --file networkadmin.card
result:
tarting business network from archive: trade-network.bna
Business network definition:
Identifier: trade-network#0.1.13
Description: Commodities Trading Business Network
Processing these Network Admins:
userName: admin
✖ Starting business network definition. This may take a minute...
Error: Error trying to instantiate composer runtime. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: chaincode error (status: 500, message: chaincode instantiation policy violated(Failed to authenticate policy))
Error: No valid responses from any peers may be b/c you don't ./startFabric (in fabric-tools folder) or may be the .acl file (permissions.acl) have error (try change it to the beginning version).
The error 'Error: Error trying to instantiate composer runtime.' Suggests you have not run the composer runtime install command e.g.
composer runtime install -c PeerAdmin#fabric-network -n tutorial-network
Or that the command did not complete successfully.
The other possibility is that your fabric has stopped or is not contactable.
The runtime must be installed on fabric for the network to start.
"composer runtime install -c PeerAdmin#hlfv1 -n "
The Steps:
1) ./startFabric.sh,
2) ./createPeerAdminCard.sh,
3) composer runtime install -c PeerAdmin#hlfv1 -n ,
4) composer network start -a ./#0.0.1.bna -A admin -S adminpw -c PeerAdmin#hlfv1
there seems to be some challenges / bug with the use of composer
Composer Updates : 0.19.0 Changes:
End of March developers of Composer framework released version 0.19.0. Although there are multiple new features (mostly under the covers) in this release, it also introduced some BREAKING changes :( So what does that mean? It means that:
Some of the composer CLI commands have become obsolete or have changed
BNA Installation commands have changed ( install + start )
Following Composer CLI commands have been removed
runtime install, network deploy, network update, network undeploy
BNA upgrade requires an install of new version followed by
Composer card commands standardised to use -c or --card. Earlier some commands used -n and some used -c
Some of the Composer API have changed
That error can mean that the identity you are using to perform a network start doesn't have channel admin authority and thus is not authorised to perform a network start. I would suggest you check with whoever created your Hyperledger Fabric environment and channel to find out who the right identities are for administrative authority on the channel and build a card with the appropriate crypto material representing that identity in order to perform a network start.
1. ./stopFabric.sh
2. export FABRIC_VERSION=hlfv11
3. ./startFabric.sh
4. ./createPeerAdminCard.sh
5. install network
6. start network
Please create a new card with your business network name. Hopefully it will work:
composer network start --card PeerAdmin#myfabric --networkAdmin admin --networkAdminEnrollSecret adminpw --archiveFile trade-network.bna --file trade-network.card
I came up with a solution to my problem, which is similar to yours, it might be useful to you too:
I noticed that with other networks it works properly so, there is a problem with the DNS:
Edit or create /etc/docker/daemon.json in your machine and add:
{ "dns": ["your dns", "8.8.8.8"] }
Stop Fabric, restart Docker, Start Fabric
Repeat composer install and composer start
Well i was getting the similar error :-
Upgrading business network definition. This may take a minute...
Error: Error trying to upgrade business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: could not find chaincode with name 'airlinev9')
Command failed
My composer version: v0.19.4
What I was trying to do:-
I was trying the update my BNA to a newer version. But got the error which i shown you above.
What I did to solve the issue :-
I first deleted the previous card using the command :-
composer card delete -c admin#airlinev9
And then start the BNA with (already created, installed):-
composer network start -c PeerAdmin#hlfv1 -n airlinev9 -V 0.0.3 -A
admin -S adminpw
And it worked for me.
I am SUPER new to HyperLedger hence I am not sure on how it worked out me but just in case might work for you too so try it out. I did only 2 things((on fabric-tool directory) :
1) ./startFabric.sh
2) ./createPeerAdminCard.sh
Ok I agree I lied. Not 2 things but 3.
3) Retry .bna association as expected normally.
I hope it works for you too :)

Hyperledger Fabric CLI docker container

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

Resources