No peers defined in the channel that have the ledger query role. Failed to execute the transaction - hyperledger-fabric

No peers defined in the channel that have the ledger query role. Failed to execute the transaction: Error: No peers defined in the channel that have the ledger query role.
When I remove particular chaincode in the start.sh file, It is working fine. I'm adding one more chaincode to the channel, when deploying the chaincode it is showing 200. But when I try to query the chaincode, I'm getting this error.
Here is the error message that I'm getting
I checked with the config.yaml file. Everything good. Working fine with other chaincodes.

The client-side error you are seeing has nothing to do with chaincode. It is a failure to identify any peers (with the ledger query role) in your connection profile for the channel name you have specified, only if you are not using service discovery to locate network nodes. You probably need to check:
Which connection profile you are specifying when calling gateway.connect().
Exactly which channel name you are specifying in your client application when calling gateway.getNetwork().
That this channel name is defined in your connection profile.
There are peers defined for this channel in your connection profile.
The peer definitions don't explicitly disable the the ledger query role.
The error message you are seeing only exists in the v1.4 legacy Node client SDK, which is no longer supported. If at all possible, I would recommend using Fabric v2.4 (or later) and the newer Fabric Gateway client API.

Related

How to select endorsing peers when submitting transaction in GO SDK

I have a Hyperledger-Fabric network with two organisations: Org1 and Org2. Discovery is enabled.
When I run a Gateway client and submit a transaction, it always be endorsed by peer0.peer.org1.com.
In particular scenario, I may want to select particular peer to endorse the transaction.
Noticed that there is a function in Go SDK, called channel.WithTargetEndpoints(), I thought that i could use this function to append RequestOption. When I used any target peers from org1, the transaction could be processed successfully, however, when I tried to specify peers from org2, it didnt work.
Guess my user certificate was signed by org1. NetworkPeerConfig can fetch the peer configuration based on a key (name or URL). However, user within org1 cannot fetch the peer configuration for org2's peers.
How to select endorsing peers when submitting transaction in GO SDK?
If you're using the gateway package to submit the transaction, then you should use WithEndorsingPeers as the optional argument.

Is it possible to list endorsing peers of a chaincode in the application?

In Hyperledger ledger, how could I list endorsing peers of a specific chaincode?
I have a channel with 5 peers but I need that only three of them endorse a transaction while the other two need only to access to same ledger.
You can use the discovery service to get the endorsing peer. Here you can find some information:
https://hyperledger-fabric.readthedocs.io/en/latest/discovery-overview.html
Hyperledger fabric has a CLI tool to query the discovery service:
https://hyperledger-fabric.readthedocs.io/en/latest/discovery-cli.html
For node.js applications, you can follow the tutorial here:
https://hyperledger.github.io/fabric-sdk-node/release-1.4/tutorial-discovery.html
With the latest Fabric Client SDKs (personally using GO client), you don't need to deal with endorsement policies. Client SDK already does this dirty work for you. It extracts:
Which organizations' endorsements are required for this chaincode, key (key level endorsement policy can be defined as well), etc.
Which peers currently exist in the system and what are their MSPs (from discovery service).
According to these information, client SDK builds a set of necessary peers then sends your transaction request to all. It waits response from requested endorsers. Once it collects all responses, it sends to orderer and so on.
If you have a special case which you need to manually set endorsing peers of your choice (I had one use case about private collections so I had to use this approach) check out discovery service API of your client SDK.

Calling submit after evaluate in fabric gatway :Migration from Fabric SDK to Fabric Gaetway

I am trying to migrate my code from Fabric SDK to Fabric Gaetway. Currently for sending the transaction , I construct TransactionProposalRequest object and send it to fabric using channel.sendTransactionProposal method.As a response, I get the Collection of TransactionProposalResponse back ,then I make a check whether 50% of them are successful ,if they are I go ahead and submit the transaction to orderer.
Now when I am migrating to high level API using fabric gateway, I see two methods "evaluateTransaction" and "submitTransaction" ,first one just sends to peers collect the endorsements without submitting it to orderer. second one would first collect the endorsements and then submit it to orderer and hence save it to ledger.
My requirement is
To be able to first check the endorsement response and if the 50% of them are success responses ,then proceed submitting it to orderer.
How can I achieve this using new API? If I call "evaluateTransaction" method first and check for responses and then call "submitTransaction" if its the way I expected, it would end up endorsing the same transaction twice as submit also collects endorsements first internally.
Any pointers on this would help.
If you use discovery then submitTransaction will only ever contact enough peers for simulation to satisfy your endorsement policy. If any peers cannot be contacted then it should try to get endorsements from other peers in the same org in order to collect enough endorsements to satisfy your endorsement policy and thus be able to submit to the orderer.
Therefore using discovery you shouldn't have to worry about checking for 50% of the responses anymore.

how does a sdk client of one org send transaction request to another org endorsing peer

I have a case where I have hyperledger fabric network two orgs with one endorser peers on each org. there is a write policy that says, 'both the orgs to sign the transaction to commit the ledger'. in this case how can a client app of one org send transaction request to both the orgs' endorsers? Can a client have identity info from both the orgs which I thing not suggestible.
Please suggest with resource links covered this case.
Hyperledger fabric has Service Discovery Api for it.
Service discovery helps render configurations dynamically which are required to propose transaction,execute chaincode on peer and get endorsement policy associated with chaincode.
Bellow are the links to help you over it.
read the docs explaination for discovery service
node.sdk discovery service tutorial

what is application signature in hyperledger fabric and how to set it?

what is Application's own signature in this context, and how can someone using hyperledger fabric node SDK can set the application's signature?
the application that you are talking about is simply a client app which talks to the ledger. The issue here is not the client app, the issue here is that you need a proper endorsement policy which establishes how anything goes onto the ledger.
Imagine this scenario ...
you have 2 orgs, Org1 and Org2, both owning one peer, P1 belongs to Org1, P2 belongs to Org2 and both peers joined on a channel, let's call it defaultchannel.
you deploy and instantiate your chaincode and set a basic endorsement policy which is 1-Of.
Each org has a client application, running against their own peer. When Org1 submits a transaction to the ledger, its validity is endorsed by itself, but not by the second org, because your policy requires only one to accomplish this. Basically in any network where you have more than one org, you really want a proper endorsement policy. 2-Of would work in the case of our example as any transaction would need to be validated by both orgs and that gives the ledger much better integrity.
Bottom line, your fabric network needs to be properly built and protected, especially in a production environment and this allows it to be protected by any client apps which have rights to interact with it. Your network being protected means that it doesn't matter how a client app is built and what it tries to do, it won't be able to bypass mechanisms such as the endorsement mechanisms.

Resources