4

I am trying to do a transaction from java fabric SDK. I am able to query the data properly from the node but while doing a transaction I am getting the following error:

org.hyperledger.fabric.sdk.exception.ServiceDiscoveryException: The channel is not configured with any peers with the 'discover' role
    at org.hyperledger.fabric.sdk.Channel.sendTransactionProposalToEndorsers(Channel.java:3955) ~[fabric-sdk-java-1.4.5.jar:na]
    at org.hyperledger.fabric.gateway.impl.TransactionImpl.sendTransactionProposal(TransactionImpl.java:155) ~[fabric-gateway-java-1.4.0.jar:na]
    at org.hyperledger.fabric.gateway.impl.TransactionImpl.submit(TransactionImpl.java:91) ~[fabric-gateway-java-1.4.0.jar:na]
    at org.hyperledger.fabric.gateway.impl.ContractImpl.submitTransaction(ContractImpl.java:50) ~[fabric-gateway-java-1.4.0.jar:na]

How do I configure the peers with the 'discover' role?

Paradox
  • 327
  • 3
  • 19

3 Answers3

0

I have been using the node SDK though, but as per the java resources I went through, you must have been using a 'network-config'(.yaml/.json) file to connect your application (via the sdk) with your network. Therein a peer section would be present which is defined as here: https://github.com/hyperledger/fabric-sdk-java/blob/master/src/test/fixture/sdkintegration/network_configs/network-config.yaml#L76, there you should try to add discover: true.

However the point here is , this discover property is true by default, so the case could also be that you may have missed the peer section( although this is a required section, so the chances of this happening,are also bleak) in the network-config file or you might be missing configuring the CORE_PEER_GOSSIP_EXTERNALENDPOINT in your docker file.

Udyan Sharma
  • 134
  • 7
  • Hello, I am having the same problem but I have no network-config.yaml in my Java-sdk client applicaiton. It works ok except that I can't use the discover as I get same error. I joined the channel using the shell "peer join" command. Shall I use any special "peer" command to enable that discover role? – icordoba Feb 12 '20 at 12:09
  • Not the peer command but maybe the [service discovery cli](https://hyperledger-fabric.readthedocs.io/en/release-1.4/discovery-cli.html) might help here. I am not certain about this but after a bit of skimming, I think this has to be, what you are looking for. – Udyan Sharma Feb 13 '20 at 14:59
0

Following the steps will help to access service discovery from client application.

1. Before Running network (peer) add the CORE_PEER_GOSSIP_EXTERNALENDPOINT information to the peer service of docker-compose.yml file. It will be helpful if we set at least one anchor peer to each organization.

services:
  peer1.org1.example.com:
     environment:
        - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:5051
        # Need to change the peer domain and port with your desired value 
        - CORE_PEER_GOSSIP_USELEADERELECTION=true
        - CORE_PEER_GOSSIP_ORGLEADER=false

External endpoint will help peers from other organizations to find the peer.

2. Update the peer information from networkConnection.yml file with discover: true which is used to connect the application with the network.

channels:
  testchannel:
    peers:
      peer1.org1.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
        discover: true

3. Enable discovery during gateway creation from application

Gateway.Builder builder = Gateway.createBuilder();
...     
builder.discovery(true).identity(wallet, userName).networkConfig(connectionProfile);
// Connect to gateway using application specified parameters
gateway = builder.connect();

After running the application it will use discovery service from peer1.org1.example.com peer and will get other organization peers information (e.g peer2.org2.example.com, peer1.org2.example.com) from the channel.

Hope it will solve your problem.

But it will not run with the domains (peer1.org1.example.com, peer1.org2.example.com, peer2.org2.example.com) as the domains has no bind with actual IP. You need to add the route in your /etc/hosts file to test the application (Update 127.0.0.1 with your desired IP).

127.0.0.1 peer1.org1.example.com
127.0.0.1 peer1.org2.example.com
127.0.0.1 peer2.org2.example.com

Run the client application again and check if it works properly.

iOS-Developer84
  • 654
  • 8
  • 19
  • For step 1, may I know what is the purpose of `CORE_PEER_GOSSIP_USELEADERELECTION` and `CORE_PEER_GOSSIP_ORGLEADER`? Are they meant to be used together with `CORE_PEER_GOSSIP_EXTERNALENDPOINT`? – user10931326 Jun 15 '20 at 07:30
  • @user10931326 in short yes. External endpoint is the point where other peers will communicate using discovery. You can find the full details of leader election from the following link https://hyperledger-fabric.readthedocs.io/en/release-2.0/gossip.html#leader-election – iOS-Developer84 Jul 09 '20 at 05:41
0

If you have programatically added the peer, you can set the roles of the peer at the point of adding it. Here is a snippet

newChannel.joinPeer(peer, Channel.PeerOptions.createPeerOptions().setPeerRoles(EnumSet.of(Peer.PeerRole.EVENT_SOURCE, Peer.PeerRole.SERVICE_DISCOVERY))); //Add more roles as you see if

Then when you initialise the channel using newChannel.initialize(), it will reinitiate full network discovery.

Srikumar S
  • 46
  • 3