1

I have 4 Orgs:

  • Org1 -- 2 peer
  • Org2 -- 2 peer
  • OrgCam -- 0 peer, 1 client
  • OrgView -- 0 peer, 1 client

Org1's peers have a chaincode installed on them that access some private data only available to Org1.

As a client of OrgCam, I want to access the chaincode installed on Org1's peers.

When I try to do that:

const result = await contract.evaluateTransaction('getPoints','ID1');

This error occurs

2019-05-19T15:20:20.084Z - error: [SingleQueryHandler]: evaluate: message=No peers available to query. Errors: [], stack=FabricError: No peers available to query. Errors: []
    at SingleQueryHandler.evaluate (/home/zanna/fabric-samples/first-network/clientCode/node_modules/fabric-network/lib/impl/query/singlequeryhandler.js:39:17)
    at Transaction.evaluate (/home/zanna/fabric-samples/first-network/clientCode/node_modules/fabric-network/lib/transaction.js:246:29)
    at Contract.evaluateTransaction (/home/zanna/fabric-samples/first-network/clientCode/node_modules/fabric-network/lib/contract.js:172:39)
    at main (/home/zanna/fabric-samples/first-network/clientCode/camera.js:41:39)
    at <anonymous>, name=FabricError
Failed to evaluate transaction: FabricError: No peers available to query. Errors: []

My question is: How can I query the Org1's chaincode even if I'm not a client from Org1?

Zanna_37
  • 122
  • 10
  • Most of the connection information is stored within the connection profile json. Have you tried checking that? – Mrudav Shukla May 20 '19 at 04:39
  • I don't think the `connection.json` is the problem here, when I try to query the Org1 peer with an Org1 client, everything is working. – Zanna_37 May 20 '19 at 09:06

2 Answers2

0

I am a bit confused by your configuration, but I'll try to answer as best as I can.

Lets make it clear

A chaincode does not "belong" to an organization. A chaincode belongs to a channel and has particular endorsement policies.

Considering that, you could say a chaincode belongs to the peers that are member of the channel.

An organization can only interact with a chaincode if it possesses a peer that is member of the channel that has the chaincode.


Answer

You did not provide any information about your channel. Considering you error, I suppose you did not join the OrgCam peer to the channel in which Org1 peer(s) deployed the chaincode.

You OrgCam peer is not part of the channel, you cannot query the chaincode of the channel.

Moreover, you cannot use a OrgCam client certificate to interact with a Org1 peer, because the certificate is not known/accepted by the Org1 peers. Only Org1 explicitly defined clients can interact with org1 peers.

Itération 122442
  • 2,644
  • 2
  • 27
  • 73
  • I know the configuaration can be confusing. It's because I'm trying to cover a particular corner case, but I don't want to digress. With _belong_ I ment _installed_ on Org1's peer. I'll edit the question. – Zanna_37 May 20 '19 at 09:00
  • OrgCam and OrgView don't have any peer at all, they have only clients. Nevertheless I don't think you statement is correct. OrgCam _can_ interact with Org1's peer. Have a look [here](https://hyperledger-fabric.readthedocs.io/en/release-1.4/peers/peers.html#peers-and-organizations), last rows. _Applications connect either to peers in their organization, or peers in another organization, depending on the nature of the ledger interaction that’s required. [...]_ – Zanna_37 May 20 '19 at 09:00
  • @Zanna_37The chaincode to be usable must be installed AND instantiated on the channel. It is normal if you just installed it. For connecting to the organization peer, as I said, it is possible only if the client certificate is well known by the peer. If not, you won't go through. – Itération 122442 May 20 '19 at 09:55
  • The chaincode is installed only on Org1's peers and it is instantiated on the channel. Moreover, I managed to connect to the Org1's peer from OrgCam's client without explicitly specifying any certificate as far as I know. – Zanna_37 May 21 '19 at 16:45
0

I finally managed to do that.

1.

const result = await contract.evaluateTransaction('getPoints','ID1');

must be changed to:

const result = await contract.submitTransaction('getPoints','ID1');

in order to get the information from peers in an external organization.

2.

If private data are in use, it's important that the fields "memberOnlyRead" and "memberOnlyWrite" (1) must be removed or set to false in the collections_config.json file.

example:

[
 {
   "name": "collectionFacepoints",
   "policy": "OR('Org1MSP.member')",
   "requiredPeerCount": 2,
   "maxPeerCount": 2,
   "blockToLive": 0,
   "memberOnlyRead": false
 }
]

3.

In the gateway.connect(connectionProfile, connectionOptions) it is important to add discovery.enable=true to the connectionOptions.

example:

await gateway.connect(
  connectionProfile,
  {
    wallet,
    identity: identityConfig.identityLabel,
    discovery: {
      enabled: true,
      asLocalhost: true
    },
    eventHandlerOptions: {
      strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ALLFORTX
    }
  }
);

4.

Unfortunately it seems that a client from OrgCam cannot directly query a chaincode installed in org1's peers, but It can be done adding an empty (2) OrgCam's peer that act as an anchor peer.


  • (1): "memberOnlyWrite" is not available yet. See here.
  • (2): With "empty" I mean without any chaincode installed on it.
Zanna_37
  • 122
  • 10