通过go gateway sdk调用chaincode时发现错误

discovery error when invoking chaincode through go gateway sdk

我在尝试通过带有网关 sdk 的 go 应用程序调用链代码时遇到了这个问题。 Chaincode 已成功安装在对等节点上并通过 cli 运行,但在尝试使用应用程序调用 chaincode 时出现以下错误:

[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" > 

我可以使用 cli 创建并使用应用程序进行查询,但无法提交任何交易。

与此合约一起安装的示例 fabcar 链代码可以在启用发现的 nodejs 应用程序中正常工作。这可能与我们链码的私有数据有关?

我可以确认这在本地使用测试网络时工作正常,但是我正在尝试 运行 在 kubernetes 部署的网络上 运行 将链代码作为外部服务。

从有关此问题的其他帖子看来,可能是锚点设置不正确。我已将更新的锚点推送到频道。如果不是,fabcar 应用程序是否也无法运行?

转到应用程序代码:

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)
}

编辑:连接配置文件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
            }
        }
    }
}

编辑:发现 cli 输出

[
        {
                "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"
        }
]

确保您使用的是 运行 Fabric 2.4 及更高版本。

隐式集合支持仅在 Fabric 2.4 中 implemented