"gRPC failure=Status{code=UNAVAILABLE, description=io exception" when invoking 'channel.sendTransactionProposal'

huangapple go评论70阅读模式
英文:

"gRPC failure=Status{code=UNAVAILABLE, description=io exception" when invoking 'channel.sendTransactionProposal'

问题

在启用TLS并尝试向对等节点发送事务提案时,出现以下gRPC错误。

从这里参考了代码:https://developer.ibm.com/tutorials/hyperledger-fabric-java-sdk-for-tls-enabled-fabric-network/
我已在所有对等节点和整个网络上启用了TLS。我尝试直接在代码中提供证书/PEM字符串,但仍然出现相同的异常。

我在这里漏掉了什么?我直接从Eclipse运行客户端应用程序。
提前谢谢您。

------------------------- 代码开始 ---------------

HFClient hfClient = HFClient.createNewInstance();
hfClient.setCryptoSuite(cryptoSuite);
hfClient.setUserContext(admin_registar);

String peer_name = "peer0.org1.example.com";
String peer_url = "grpcs://localhost:7051"; // 确保端口为peer1的端口
String peerTLSCertFileName = "crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt";    // 获取TLS证书
 
Properties peerProperties = new Properties();
peerProperties.setProperty("pemFile", peerCertFile.getAbsolutePath());
peerProperties.setProperty("allowAllHostNames", "true");
Path peerPath = Paths.get(peerTLSCertFileName);        
peerProperties.put("pemBytes", Files.readAllBytes(peerPath));
peerProperties.setProperty("sslProvider", "openSSL");    // 设置TLS属性
peerProperties.setProperty("negotiationType", "TLS");    // 设置TLS属性
Peer peer = hfClient.newPeer(peer_name, peer_url, peerProperties);

// --- 向HFClient添加Orderer的类似代码 ---

Channel channel = hfClient.newChannel("mychannel");
channel.addPeer(peer);
channel.addOrderer(orderer);
channel.initialize();

TransactionProposalRequest request = hfClient.newTransactionProposalRequest();
String cc = "fabcar"; // 链码名称
ChaincodeID ccid = ChaincodeID.newBuilder().setName(cc).build();

request.setChaincodeID(ccid);
request.setFcn("createCar"); // 链码调用函数名称
String[] arguments = {"CAR11", "VgW", "Poglo", "Ggrey", "Margy"}; // 链码函数所需的参数
request.setArgs(arguments);
request.setProposalWaitTime(3000);
Collection<ProposalResponse> responses = channel.sendTransactionProposal(request); // 引发异常的这一行

------------------------- 代码结束 ---------------

上述代码的最后一行出现了以下异常:

线程中的异常 "main" org.hyperledger.fabric.sdk.exception.ProposalException: org.hyperledger.fabric.sdk.exception.TransactionException: org.hyperledger.fabric.sdk.exception.ProposalException: 针对对等体 peer0.org1.example.com 获取通道 mychannel 的配置块失败。状态失败,详细信息:通道通道{id: 3, 名称: mychannel} 发送事务提案与事务:353dde2899c1993b9e643ac32b7b9c27ae4eeda1aaa17bc13f1c35f91795a9f7 到 Peer{id: 1, 名称: peer0.org1.example.com, channelName: mychannel, url: **grpcs://localhost:7051} 失败,原因:gRPC 失败=状态{code=UNAVAILABLE, description=io异常}
通道管道:[SslHandler#0, ProtocolNegotiators$ClientTlsHandler#0, WriteBufferingAndExceptionHandler#0, DefaultChannelPipeline$TailContext#0], 原因=javax.net.ssl.SSLHandshakeException: 通用OpenSslEngine问题

英文:

Getting below gRPC error when tls is enabled and tried to send transaction proposal to peer.

Taken reference code from here: https://developer.ibm.com/tutorials/hyperledger-fabric-java-sdk-for-tls-enabled-fabric-network/
I have enabled TLS on all peers and on overall network. I tried by giving certificate/pem string directly also in code. But, same exception.

What I am missing here? I am running client application from Eclipse directly.
Thank you in advance.

------------------------- Code starts ---------------

HFClient hfClient = HFClient.createNewInstance();
hfClient.setCryptoSuite(cryptoSuite);
hfClient.setUserContext(admin_registar);

String peer_name = &quot;peer0.org1.example.com&quot;;
String peer_url = &quot;grpcs://localhost:7051&quot;; // Ensure that port is of peer1
String peerTLSCertFileName = &quot;crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt&quot;;	***// Taking TLS certitifcate***
 
Properties peerProperties = new Properties();
peerProperties.setProperty(&quot;pemFile&quot;, peerCertFile.getAbsolutePath());
peerProperties.setProperty(&quot;allowAllHostNames&quot;, &quot;true&quot;);
Path peerPath = Paths.get(peerTLSCertFileName);        ;
peerProperties.put(&quot;pemBytes&quot;, Files.readAllBytes(peerPath));
**peerProperties.setProperty(&quot;sslProvider&quot;, &quot;openSSL&quot;);	// SETTING TLS properties
peerProperties.setProperty(&quot;negotiationType&quot;, &quot;TLS&quot;);	// SETTING TLS properties**
Peer peer = hfClient.newPeer(peer_name, peer_url, peerProperties);

&lt;&lt; --- Similar code to add Orderer to HFClient ---&gt;&gt;

Channel channel = hfClient.newChannel(&quot;mychannel&quot;);
channel.addPeer(peer);
channel.addOrderer(orderer);
channel.initialize();

TransactionProposalRequest request = hfClient.newTransactionProposalRequest();
String cc = &quot;fabcar&quot;; // Chaincode name
ChaincodeID ccid = ChaincodeID.newBuilder().setName(cc).build();

request.setChaincodeID(ccid);
request.setFcn(&quot;createCar&quot;); // Chaincode invoke funtion name
String[] arguments = {&quot;CAR11&quot;, &quot;VgW&quot;, &quot;Poglo&quot;, &quot;Ggrey&quot;, &quot;Margy&quot;}; // Arguments that Chaincode function takes
request.setArgs(arguments);
request.setProposalWaitTime(3000);
**Collection&lt;ProposalResponse&gt; responses = channel.sendTransactionProposal(request); // this is line throwing exception**

------------------------- Code ends ---------------

Below exception is at last line of code above:

Exception in thread "main" org.hyperledger.fabric.sdk.exception.ProposalException: org.hyperledger.fabric.sdk.exception.TransactionException: org.hyperledger.fabric.sdk.exception.ProposalException: getConfigBlock for channel mychannel failed with peer peer0.org1.example.com. Status FAILURE, details: Channel Channel{id: 3, name: mychannel} Sending proposal with transaction: 353dde2899c1993b9e643ac32b7b9c27ae4eeda1aaa17bc13f1c35f91795a9f7 to Peer{ id: 1, name: peer0.org1.example.com, channelName: mychannel, url: grpcs://localhost:7051} failed because of: gRPC failure=Status{code=UNAVAILABLE, description=io exception
Channel Pipeline: [SslHandler#0, ProtocolNegotiators$ClientTlsHandler#0, WriteBufferingAndExceptionHandler#0, DefaultChannelPipeline$TailContext#0], cause=javax.net.ssl.SSLHandshakeException: General OpenSslEngine problem
at

答案1

得分: 2

I was getting this issue when I had not run the CreateChannel command.

java -cp blockchain-client.jar org.example.network.CreateChannel

英文:

I was getting this issue when I had not run the CreateChannel command.

java -cp blockchain-client.jar org.example.network.CreateChannel

huangapple
  • 本文由 发表于 2020年1月6日 23:21:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定