TRANSIENT_FAILURE 当使用在 fabric-go-sdk 中使用“WithSDK”配置的网关发送事务时发生

TRANSIENT_FAILURE occurs when a transaction is sent using Gateway that is configured using `WithSDK` in fabric-go-sdk

我正在构建一个客户端服务器以使用 fabric-go-sdk 连接 Hyperledger Fabric 网络。要使用自定义日志记录系统,我使用 fabsdk.New() 获得一个 FabricSDK 对象,然后使用 gateway.WithSDK 函数将其注入到 Gateway 对象。检查下面的代码:

    ccpPath := getPath("connection-profile.json", staticPath)
    sdk, err := fabsdk.New(config.FromFile(ccpPath),
        fabsdk.WithLoggerPkg(&FabSDKLoggerProvider{}), // using my custom logging system
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to create a new fabsdk")
    }

    gw, err := gateway.Connect(
        gateway.WithSDK(sdk),
        gateway.WithIdentity(wallet, "admin"),
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
    }

当我 运行 测试时,我得到一个错误:

Failed to submit: error registering for TxStatus event: could not create client conn: could not connect to peer0.test.bpl:7051: dialing connection on target [peer0.test.bpl:7051]: connection is in TRANSIENT_FAILURE

我运行的测试是使用Gateway对象及其Submit方法发送t运行saction的测试。

当我定义一个没有 FabricSDKGateway 对象时,它工作正常。也就是说,如果我使用下面的代码,测试会顺利通过。但是,在这种情况下,我无法使用我的自定义日志记录系统。 (我只想禁用 Fabric SDK 的日志系统。)

    ccpPath := getPath("connection-profile.json", staticPath)
    gw, err := gateway.Connect(
        gateway.WithConfig(config.FromFile(ccpPath)),
        gateway.WithIdentity(wallet, "admin"),
    )
    if err != nil {
        return nil, errors.Wrap(err, "failed to connect the network via a fabric gateway")
    }

根据我的调查,fabsdk.New()gateway.Connect(gateway.WithConfig()) 初始化的 FabricSDK 对象之间的区别在于 gateway.Connect(gateway.WithConfig()) 创建的 FabricSDK 对象具有选项 fabsdk.WithMSPPkg(gw.mspfactory) 但另一个没有。我尝试为我的 fabsdk.New() 代码提供相同的选项,但我找不到如何操作。

那么,我的问题是:

谢谢。

我在编写一些示例 CLI 以获取链代码元数据时遇到了完全相同的两个问题

How can I deal with "TRANSIENT_FAILURE" error

在我的例子中,dialing connection on target [peer0.org1.example.com:7051]: connection is in TRANSIENT_FAILURE 错误是因为我使用的是 Fabric 测试网络 docker 环境,但我没有设置 DISCOVERY_AS_LOCALHOST 环境变量。 DISCOVERY_AS_LOCALHOST 确定服务发现期间找到的 IP 地址是否从 docker 网络转换为本地主机,这在 Connection Options 应用程序开发文档中有描述。

How can I disable the Fabric SDK's default logging system?

我仍然想查看错误消息,但我能够使用 logging.SetLevel("", logging.ERROR)

更改日志记录级别以删除不需要的信息消息

ccmetadata sample is on GitHub if that's any help