discovery error when invoking chaincode through go gateway sdk

Issue

I’ve been facing this issue when trying to invoke chaincode through a go application with the gateway sdk. Chaincode is successfully installed on the peers and works through the cli, but I get the following errors when trying to invoke the chaincode with the application:

[fabsdk/client] 2022/03/10 09:27:55 UTC - invoke.(*SelectAndEndorseHandler).Handle -> WARN error getting additional endorsers: error getting additional endorsers: error getting channel response for channel [mychannel]: Discovery status Code: (11) UNKNOWN. Description: error received from Discovery Server: failed constructing descriptor for chaincodes:<name:"kyral" collection_names:"_implicit_org_Org1MSP" > 

I am able to create with the cli and query with the application fine, but not submit any transactions.

The sample fabcar chaincode installed alongside this contract works fine with a nodejs application with discovery enabled. Possibly this is related to private data with our chaincode?

I can confirm that this works fine when using the test network locally, however I am trying to run this on a kubernetes deployed network running the chaincode as an external service.

From other posts about this issue it seems it could be that anchor peers are not set correctly. I have pushed updated anchor peers to the channel. If they weren’t would the fabcar application also not work?

Go Application code:

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "os"
    "path/filepath"

    "github.com/gorilla/mux"
    "github.com/hyperledger/fabric-sdk-go/pkg/core/config"
    "github.com/hyperledger/fabric-sdk-go/pkg/gateway"
)

type NetworkHandler struct {
    contrac *gateway.Contract
}

var (
    ccpPath      = os.Getenv("CCP_PATH")
    credPath     = os.Getenv("CRED_PATH")
    mspID        = os.Getenv("MSP_ID")
    channelName  = os.Getenv("CHANNEL_NAME")
    contractName = os.Getenv("CONTRACT_NAME")
)

func main() {
    r := mux.NewRouter()

    log.Println("====Les a Go====")

    err := os.Setenv("DISCOVERY_AS_LOCALHOST", "false")
    if err != nil {
        log.Fatalf("Error setting DISCOVERY_AS_LOCALHOST environment vairblae %v", err)
    }

    wallet, err := gateway.NewFileSystemWallet("wallet")
    if err != nil {
        log.Fatalf("Failed to create wallet: %v", err)
    }

    if !wallet.Exists("appUser") {
        err = populateWallet(wallet)
        if err != nil {
            log.Fatalf("Failed to populate wallet contents: %v", err)
        }
    }

    //location of connection profile for org1

    gw, err := gateway.Connect(
        gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
        gateway.WithIdentity(wallet, "appUser"),
    )

    if err != nil {
        log.Fatalf("Failed to connect to gateway: %v", err)
    }

    defer gw.Close()

    network, err := gw.GetNetwork(channelName)
    if err != nil {
        log.Fatalf("Failed to get network: %v", err)
    }

    contract := network.GetContract(contractName)
    /*
        log.Println("--> Submit: InitLedger")
        results, err := contract.SubmitTransaction("InitLedger")
        if err != nil {
            log.Fatalf("Failed to Submit transaction: %v", err)
        }
        log.Println(string(results))
    */
    log.Println("Started")
    TestN := NetworkHandler{contrac: contract}

    r.HandleFunc("/getAllOrgVisit", TestN.getAllOrgVisit)

    r.HandleFunc("/readPrivateProperties/{id}", TestN.readPrivateProperties)
    r.HandleFunc("/readPrivatePublicAsset/{id}", TestN.readPrivatePublicProperties)

    r.HandleFunc("/verifyAssetProperties", TestN.verifyAssetProperties).Methods("POST")

    r.HandleFunc("/createPrivate", TestN.createPrivate).Methods("POST")

    r.HandleFunc("/changeDescription", TestN.changeDescription).Methods("PUT")

    log.Fatal(http.ListenAndServe(":1234", r))
    //log.Println("==== application-golang ends ====")
}

func populateWallet(wallet *gateway.Wallet) error {
    log.Println("Populate Wallet")

    certPath := filepath.Join(credPath, "signcerts", "cert.pem")
    // reads the certificate pem
    cert, err := ioutil.ReadFile(filepath.Clean(certPath))
    if err != nil {
        return err
    }

    keyDir := filepath.Join(credPath, "keystore")

    files, err := ioutil.ReadDir(keyDir)

    if err != nil {
        return err
    }

    if len(files) != 1 {
        return fmt.Errorf("keystore folder should have contain one file")
    }
    keyPath := filepath.Join(keyDir, files[0].Name())
    key, err := ioutil.ReadFile(filepath.Clean(keyPath))
    if err != nil {
        return err
    }
    identity := gateway.NewX509Identity(mspID, string(cert), string(key))

    return wallet.Put("appUser", identity)
}

Edit: Connection Profile JSON

{
    "name": "test-network-org1",
    "version": "1.0.0",
    "client": {
        "organization": "Org1",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                }
            }
        }
    },
    "organizations": {
        "Org1": {
            "mspid": "Org1MSP",
            "peers": [
                "peer0-org1"
            ],
            "certificateAuthorities": [
                "ca-org1"
            ]
        }
    },
    "peers": {
        "peer0-org1": {
            "url": "grpcs://peer0-org1:7051",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nMIICGTCCAb+gAwIBAgIUAioln7jNumEBccK1IlsWOQDk5/YwCgYIKoZIzj0EAwIw\naTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEQMA4GA1UEChMHY2Etb3JnMTEQMA4GA1UECxMHY2Etb3JnMTEQMA4GA1UE\nAxMHY2Etb3JnMTAeFw0yMjAzMTAwNjU0MDBaFw0zNzAzMDYwNjU0MDBaMGkxCzAJ\nBgNVBAYTAlVTMREwDwYDVQQIEwhOZXcgWW9yazERMA8GA1UEBxMITmV3IFlvcmsx\nEDAOBgNVBAoTB2NhLW9yZzExEDAOBgNVBAsTB2NhLW9yZzExEDAOBgNVBAMTB2Nh\nLW9yZzEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR+FXBhya/ygMIdIxzZ7x03\nmr0fu8Dm/CS57B9yQZBR43G3vI5e/80gDvTYiGLMJ3D3W19eyxlIytvUoNZOU7Ft\no0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQU2z+hwYSXAFfkG8KJWO1QJGjG2MQwCgYIKoZIzj0EAwIDSAAwRQIhAPOZxwf/\nP93/69jDVN4CsSZu58pa+8AskGXHMIce/ahoAiBRbBmNRrXb/oHxzZYgeUbOpE5J\nQMwvWflb/DuIhjtlYw==\n-----END CERTIFICATE-----\n"
            },
            "grpcOptions": {
                "ssl-target-name-override": "peer0-org1",
                "hostnameOverride": "peer0-org1"
            }
        }
    },
    "certificateAuthorities": {
        "ca-org1": {
            "url": "https://ca-org1:7054",
            "caName": "ca-org1",
            "tlsCACerts": {
                "pem": ["-----BEGIN CERTIFICATE-----\nMIICGTCCAb+gAwIBAgIUAioln7jNumEBccK1IlsWOQDk5/YwCgYIKoZIzj0EAwIw\naTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEQMA4GA1UEChMHY2Etb3JnMTEQMA4GA1UECxMHY2Etb3JnMTEQMA4GA1UE\nAxMHY2Etb3JnMTAeFw0yMjAzMTAwNjU0MDBaFw0zNzAzMDYwNjU0MDBaMGkxCzAJ\nBgNVBAYTAlVTMREwDwYDVQQIEwhOZXcgWW9yazERMA8GA1UEBxMITmV3IFlvcmsx\nEDAOBgNVBAoTB2NhLW9yZzExEDAOBgNVBAsTB2NhLW9yZzExEDAOBgNVBAMTB2Nh\nLW9yZzEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR+FXBhya/ygMIdIxzZ7x03\nmr0fu8Dm/CS57B9yQZBR43G3vI5e/80gDvTYiGLMJ3D3W19eyxlIytvUoNZOU7Ft\no0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQU2z+hwYSXAFfkG8KJWO1QJGjG2MQwCgYIKoZIzj0EAwIDSAAwRQIhAPOZxwf/\nP93/69jDVN4CsSZu58pa+8AskGXHMIce/ahoAiBRbBmNRrXb/oHxzZYgeUbOpE5J\nQMwvWflb/DuIhjtlYw==\n-----END CERTIFICATE-----\n"]
            },
            "httpOptions": {
                "verify": false
            }
        }
    }
}

Edit: Discover cli output

[
        {
                "MSPID": "Org1MSP",
                "Endpoint": "peer0-org1:7051",
                "Identity": "-----BEGIN CERTIFICATE-----\nMIICrzCCAlWgAwIBAgIUIOXH6DldPR4OtWG+wGCtGMqCr44wCgYIKoZIzj0EAwIw\naTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEQMA4GA1UEChMHY2Etb3JnMTEQMA4GA1UECxMHY2Etb3JnMTEQMA4GA1UE\nAxMHY2Etb3JnMTAeFw0yMjAzMTMyMDU0MDBaFw0yMzAzMTMyMDU5MDBaMFsxCzAJ\nBgNVBAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlw\nZXJsZWRnZXIxDTALBgNVBAsTBHBlZXIxDjAMBgNVBAMTBXBlZXIwMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAERrG4wjABl9JDBURMm54cwwMMYQdMTOmTXOA9Y59R\njcDaSYhoBOZCn5b9G+lBjyPsSGONi1kLYi+btEO2IrfCQKOB6DCB5TAOBgNVHQ8B\nAf8EBAMCB4AwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUYuOyec+lAOzQia/Ub6uQ\np+B9jU4wHwYDVR0jBBgwFoAUxuQ0gmluwLBafuud+rREyZFbIbYwLQYDVR0RBCYw\nJIIWcGVlcjAub3JnMS5leGFtcGxlLmNvbYIKcGVlcjAtb3JnMTBWBggqAwQFBgcI\nAQRKeyJhdHRycyI6eyJoZi5BZmZpbGlhdGlvbiI6IiIsImhmLkVucm9sbG1lbnRJ\nRCI6InBlZXIwIiwiaGYuVHlwZSI6InBlZXIifX0wCgYIKoZIzj0EAwIDSAAwRQIh\nAOg4dHWWvhvRYrvDISm1Hhr5RXQEQOsjmWyYF2OHb9ycAiAw6GpITU5Ym29H+UFK\n573Do+OO8h5mJQ5iRnKlXo7kqg==\n-----END CERTIFICATE-----\n"
        },
        {
                "MSPID": "Org2MSP",
                "Endpoint": "peer0-org2:7051",
                "Identity": "-----BEGIN CERTIFICATE-----\nMIICrzCCAlWgAwIBAgIUFbBl1wsOfkD8IlbbbZ41vmCbGpYwCgYIKoZIzj0EAwIw\naTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEQMA4GA1UEChMHY2Etb3JnMjEQMA4GA1UECxMHY2Etb3JnMjEQMA4GA1UE\nAxMHY2Etb3JnMjAeFw0yMjAzMTMyMDU0MDBaFw0yMzAzMTMyMDU5MDBaMFsxCzAJ\nBgNVBAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlw\nZXJsZWRnZXIxDTALBgNVBAsTBHBlZXIxDjAMBgNVBAMTBXBlZXIwMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAEbZOJz8sdxDlb9ZNEaVi2UAUyjJL7MwVXV1N5HpoC\nLJtjtis68p1YUW1J/V41rUF0vQ8VAzxE2qTJKHOSAegjzKOB6DCB5TAOBgNVHQ8B\nAf8EBAMCB4AwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUBj5MxDP1v06A1gas/L7/\n6j+rsJcwHwYDVR0jBBgwFoAUH8XI3OtXwuhywemyT9t4PLfqPtEwLQYDVR0RBCYw\nJIIWcGVlcjAub3JnMi5leGFtcGxlLmNvbYIKcGVlcjAtb3JnMjBWBggqAwQFBgcI\nAQRKeyJhdHRycyI6eyJoZi5BZmZpbGlhdGlvbiI6IiIsImhmLkVucm9sbG1lbnRJ\nRCI6InBlZXIwIiwiaGYuVHlwZSI6InBlZXIifX0wCgYIKoZIzj0EAwIDSAAwRQIh\nAN36LS/0xXO3lyMTK+jtG94DOr8ojL9lsKXtQr5xRlLsAiACxLwt+tFTzmNcdEf+\n6rGzdA5iyc2zll9/g6fz9jRQUw==\n-----END CERTIFICATE-----\n"
        },
        {
                "MSPID": "Org3MSP",
                "Endpoint": "peer0-org3:7051",
                "Identity": "-----BEGIN CERTIFICATE-----\nMIICrjCCAlWgAwIBAgIUQxaZgClDvib8EJso1arU5PhtvIIwCgYIKoZIzj0EAwIw\naTELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEQMA4GA1UEChMHY2Etb3JnMzEQMA4GA1UECxMHY2Etb3JnMzEQMA4GA1UE\nAxMHY2Etb3JnMzAeFw0yMjAzMTMyMDU0MDBaFw0yMzAzMTMyMDU5MDBaMFsxCzAJ\nBgNVBAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlw\nZXJsZWRnZXIxDTALBgNVBAsTBHBlZXIxDjAMBgNVBAMTBXBlZXIwMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAEDtSXYkgkxmaHc5JZCBZXDxZFXkoOaRtfMLe2+4vu\nc6xacbsQZ/O2bqwXPzv6rTQCs9VljvI1DBlfLjKn5r1UgaOB6DCB5TAOBgNVHQ8B\nAf8EBAMCB4AwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUcINyxvwC/eyyhkEXxCRU\neInHMgEwHwYDVR0jBBgwFoAUXbOyeszc/orJIPPjHno7l8zxAzAwLQYDVR0RBCYw\nJIIWcGVlcjAub3JnMy5leGFtcGxlLmNvbYIKcGVlcjAtb3JnMzBWBggqAwQFBgcI\nAQRKeyJhdHRycyI6eyJoZi5BZmZpbGlhdGlvbiI6IiIsImhmLkVucm9sbG1lbnRJ\nRCI6InBlZXIwIiwiaGYuVHlwZSI6InBlZXIifX0wCgYIKoZIzj0EAwIDRwAwRAIg\nHzpfbdMGtVxfOdVS4iPRYJQ9DBAKXe/i5I+nnkb4N/QCIG47V1I8P9m1VKvIcR58\nSiR6Ln7ZK3ErpS8tebuxPruX\n-----END CERTIFICATE-----\n"
        }
]

Solution

Make sure you’re running with Fabric 2.4 and higher.

Implicit collection support was only implemented in Fabric 2.4.

Answered By – yacovm

Answer Checked By – Mary Flores (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.