0

我尝试使用fabric node sdk调用Fabric v1.2的服务发现功能,但出现以下错误:

2018-12-12 11:51:26.413 UTC [endorser] callChaincode -> INFO 05d [mychannel][16a59ced] Entry chaincode: name:"mycc" 
2018-12-12 11:51:30.138 UTC [chaincode] ProcessStream -> ERRO 05e handling chaincode support stream: rpc error: code = Canceled desc = context canceled
receive failed
github.com/hyperledger/fabric/core/chaincode.(*Handler).ProcessStream
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/handler.go:408
github.com/hyperledger/fabric/core/chaincode.(*ChaincodeSupport).HandleChaincodeStream
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:182
github.com/hyperledger/fabric/core/chaincode.(*ChaincodeSupport).Register
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:187
github.com/hyperledger/fabric/core/chaincode/accesscontrol.(*interceptor).Register
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/accesscontrol/interceptor.go:57
github.com/hyperledger/fabric/protos/peer._ChaincodeSupport_Register_Handler
    /opt/gopath/src/github.com/hyperledger/fabric/protos/peer/chaincode_shim.pb.go:1066
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).processStreamingRPC
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:1160
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).handleStream
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:1253
github.com/hyperledger/fabric/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1
    /opt/gopath/src/github.com/hyperledger/fabric/vendor/google.golang.org/grpc/server.go:680
runtime.goexit
    /opt/go/src/runtime/asm_amd64.s:2361
2018-12-12 11:52:00.041 UTC [endorser] callChaincode -> INFO 05f [mychannel][16a59ced] Exit chaincode: name:"mycc"  (33628ms)

但是,我完全可以确保我已经实例化了我的链码,如果我不使用,我通常可以调用它service discovery.

这是我的服务发现代码:

let client = await helper.getClientForOrg(orgName);
let channel = client.newChannel(channelName);
channel.addPeer(client.getPeer("peer0.org1.example.com"));
await channel.initialize({discover:true, asLocalhost:true});

let request = {
  chaincodeId: chaincodeName,
  fcn: functionName,
  args: args,
  transientMap: transient
};
logger.debug("Make query");
let response_payloads = await channel.queryByChaincode(request);

我哪里错了?在我使用之前有一些代码service discovery

let client = await helper.getClientForOrg(orgName);

let channel = client.newChannel(channelName);
// assign orderer to channel
channel.addOrderer(client.getOrderer(ordererName));
// assign peers to channel
peers.forEach(function (peerName) {
  channel.addPeer(client.getPeer(peerName));
});

let request = {
  targets: peers,
  chaincodeId: chaincodeName,
  fcn: functionName,
  args: args,
  transientMap: transient
};
logger.debug("Make query");
let response_payloads = await channel.queryByChaincode(request);
4

1 回答 1

0

我自己解决了。这可能是某种网络错误。

现在我将peer1.org1.example.com, peer0.org2.example.com,的端口更改peer1.org2.example.com为 8051, 9051, 10051, 11051。根据节点 sdk官方文档,我设置了asLocalhost = true.

这是我可以为我工作的代码:

let channel = client.newChannel(channelName);
channel.addPeer(client.getPeer("peer0.org1.example.com"));
await channel.initialize({discover: true, asLocalhost: true});

let tx_id = client.newTransactionID();
tx_id_string = tx_id.getTransactionID();
let request = {
  args: args,
  chaincodeId: chaincodeName,
  chainId: channelName,
  fcn: functionName,
  txId: tx_id,
  transientMap: transient
};
let results = await channel.sendTransactionProposal(request);

希望这可以帮助其他人。

于 2018-12-15T09:39:27.340 回答