I want to use gRPC in fabric chaincode to achieve cross-chain communcation instead of using fabric SDK. But when I invoke chaincode function on fabric-sample/test-network, it always occurs errors.
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction eb5e480bd4075a767f56ae263741ca0f5f19620ef88952e26b7f1952bdbe83cd: could not launch chaincode chaincode_1.2:d3f97f15a635e73d3de230c8e5899e5fb95a68cf897c03e19f9e4eeca7ca3fd5: chaincode registration failed: container exited with 2"
Who can tell me what cause this error? My chaincode has bug or gRPC cannot be used in chaincode function?
my chaincode about gRPC:
func (s *SmartContract) begin(ctx contractapi.TransactionContextInterface) error {
server.Main()
return nil
}
func (s *SmartContract) client(ctx contractapi.TransactionContextInterface) error {
// client.Clientfunc is the client main function
client.Clientfunc(Xt, R, sign, m)
}
server.go
func Main() {
listen, err := net.Listen("tcp", ":9090")
if err != nil {
fmt.Printf("failed to listen: %v", err)
return
}
grpcServer := grpc.NewServer()
pb.RegisterSendServiceServer(grpcServer, &server{})
err2 := grpcServer.Serve(listen)
if err2 != nil {
fmt.Printf("failed to serve: %v", err2)
return
}
}
client.go
func Clientfunc(Xt *btcec.PublicKey, R *btcec.PublicKey, s *big.Int, m []byte) []byte {
conn, err := grpc.Dial("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
client := pb.NewSendServiceClient(conn)
output := &pb.SignInput{
XtX: Xt.X().Int64(),
XtY: Xt.Y().Int64(),
M: m,
RX: R.X().Int64(),
RY: R.Y().Int64(),
S: s.Int64(),
}
resp, _ := client.Send(context.Background(), output)
return resp.GetM()
}