0

Is there a way to invoke setEndorsingPeers() when calling contract.evaluateTransaction()? Is there any other way to achieve it? The issue I am having is the following:

I am having two organizations and each of them has two peers: peer0 and peer1. However, only the peers peer0 are endorsing peers. So, when querying the state, sometimes the transaction gets to the peers peer1 and an Error is thrown. I've found a workaround at Querying chaincode is only successful in ~3/5 cases with nodejs, but it requires me to promote all the peers to endorsing peers. Is my approach with just committing peers even valid and correct? Thank you in advance.

P.S. No one is responding on the other thread and I believe this is a valid separate issue whose solution is not that workaround.

Nemanja Beric
  • 231
  • 2
  • 11
  • I would recommend you raise a jira about this at jira.hyperledger.org. If you don't use discovery then your connection profile can define the roles of a peer and the default query handlers will only select peers which have the role of `chaincodeQuery` (note unless defined a peer will have all roles). If you use discovery then the peers will have all roles by default unless they can be overridden (don't know on this one). Alternatively you could write your own query handler so long as you can determine which peers to query (eg by checking discovery results but tht may need another jira) – david_k Oct 18 '19 at 16:04
  • @david_k where could I find documentation about query handlers and the chaincode query? – Nemanja Beric Oct 18 '19 at 16:48
  • 1
    There is some info here https://fabric-sdk-node.github.io/release-1.4/tutorial-query-peers.html – david_k Oct 18 '19 at 17:41

1 Answers1

1

I had the same problem. Below is my solution.

1) On the connection profile, make sure to set which peer is endorser/commiter:

    "channels": {
    "mychannel": {
        "orderers": [],
        "peers": {
            "peer0.example.com": {
                "endorsingPeer": true,
                "chaincodeQuery": true,
                "ledgerQuery": true,
                "eventSource": true
            },
            "peer1.example.com": {
                "endorsingPeer": false,
                "chaincodeQuery": false,
                "ledgerQuery": false,
                "eventSource": true
            }
        },
        "chaincodes": []
    }
},

2) Use the fabric-network SDK to query: link

I hope this helps.

Hien Pham
  • 106
  • 8
  • Where should I insert this JSON? Every time when creating Gateway connection? – Nemanja Beric Oct 22 '19 at 09:25
  • Yes, this cpp can be create at first and add to gateway.connect() every time you want to create a new gateway. You can find the connection profile sample [here](https://hyperledger-fabric.readthedocs.io/en/release-1.4/developapps/connectionprofile.html#sample). – Hien Pham Oct 22 '19 at 11:48