问题
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?
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/58709303/the-channel-is-not-configured-with-any-peers-with-the-discover-role