5

I'm trying to use the service discovery feature in Fabric 1.4. My network is default, 2 organizations and 2 peers per organization. I try to invoke a chaincode via service discovery feature rather than setting specific target peers. (Before using the service discovery, I set specific endorsers in target properties of transaction proposal request object.)

To use the service discovery, I set discover: true to peers in my connection profile. Then, simply I added below code to my invoke function.

await channel.initialize({ discover: true, asLocalhost: true })

Following the tutorial in fabric-node-sdk document, I changed the ports of each peer to use service discovery in docker-compose network.

Everything works fine including creating the channel, installing chaincode, and instantiating chaincode. Also, invoking the chaincode works fine if I didn't use the service discovery feature.

However, if I added await channel.initialize({ discover: true, asLocalhost: true }) in my invoke function, this initialize function throws an error like below:

Error: No endorsement plan available for {"chaincodes":[{"name":"etri-bcdms-token-chaincode"}]}

(I set my endorsement policy during the instantiation)

In the peer, the below log are printed:

Failed constructing descriptor for chaincode chaincodes:<name:"etri-bcdms-token-chaincode" > ,: cannot satisfy any principal combination

The full code of my invoke function is below:

const client = this._useFabricCA
      ? await getUserClient(orgID, userID)
      : await getOrgAdminClient(orgID)
    if (!client) {
      throw Error(`failed to get the client for ${orgID}`)
    }

    const channel = client.getChannel(channelID)
    if (!channel) {
      throw Error(`failed to get the channel for ${channelID}`)
    }

    // Service discovery
    await channel.initialize({ discover: true, asLocalhost: true })

    const chaincodeSetting = getChaincodeSetting(channelID)
    if (!chaincodeSetting) {
      throw Error(`no chaincode set on the channel ${channelID}`)
    }

    const txID = client.newTransactionID()
    const request: ChaincodeInvokeRequest = {
      // targets: targetList,
      chaincodeId: chaincodeSetting.id,
      fcn,
      args,
      txId: txID
    }

    // Process the endorsement
    const results = await channel.sendTransactionProposal(request)

Is there any advice for this kind of error? Where can I invest to fix this error and use the service discovery? Any advice will be very thankful.

byron1st
  • 969
  • 1
  • 13
  • 35
  • Have you figured out what is causing this? I am having a similar problem. The node chaincode deploys and instantiates but invoke fails because of an issue with the discovery service. The error is: ```Failed constructing descriptor for chaincode chaincodes: ,: cannot satisfy any principal combination``` – Moriarty Apr 04 '19 at 15:40

1 Answers1

2

You must add an anchor peer from each organization in the channel, this solved the problem for me. Anchor peers are required for the service discovery since the service discovery uses gossip protocol

Moriarty
  • 515
  • 3
  • 17
  • How do you specifically add an anchor peer. Using `channel.addPeer()` is what I have done so far. Also what is the use of `channel.initialize()`? – Varun Agarwal Jun 01 '19 at 16:48
  • so I know how to do it using the cli container, about half way down the page it is covered https://hyperledger-fabric.readthedocs.io/en/latest/build_network.html but i do not know how using the node sdk which is what I would like to do – Moriarty Jun 04 '19 at 22:10
  • Check out this repository, this file in particular - https://github.com/IBM/build-blockchain-insurance-app/blob/master/web/www/blockchain/utils.js#L107 .I am learning to use the node SDK by following the functions defined here and then then the 1.4.1 documentation at https://fabric-sdk-node.github.io . Seems like the `initialize` function doesn't do anything itself. It just "wakes" up the container for a peer? – Varun Agarwal Jun 05 '19 at 04:21
  • Thank you for sharing that but I still dont see where anchor peers are added. Adding an anchor peer requires a channel update where the input param is the anchor `*.tx` update – Moriarty Jun 05 '19 at 14:39
  • A few lines above the variable `defaultPeer` is the anchor peer for this sample. However the anchor peer config file that ends with `.tx` is something I amnot sure about either. This sample works fine and doesn't reference that file at any point. – Varun Agarwal Jun 05 '19 at 15:04