0

我正在用 Go 开发一个中间件,它使用 fabric-sdk-go 集成了一个超级账本结构网络。中间件在 Docker 容器上运行,它设置为使用相同的结构容器网络(我已经检查过容器是否相互连接),但是当我尝试连接到通道时,会引发以下错误:

未能创建新通道客户端:事件服务创建失败:无法获取 chConfig 缓存引用:QueryBlockConfig 失败:queryChaincode 失败:背书者 [peer0.slaughterhouse.kingbeefcattle.com:7051] 的事务处理:背书客户端状态代码:(2)CONNECTION_FAILED . 说明:拨号连接超时 [peer0.slaughterhouse.kingbeefcattle.com:7051]

有我的 config.yaml:

name: "kingbeefcattlenetowrk"
#
# Schema version of the content. Used by the SDK to apply the corresponding parsing rules.
#
version: 1.0.0

#
# The client section used by GO SDK.
#
client:

  # Which organization does this application instance belong to? The value must be the name of an org
  # defined under "organizations"
  organization: slaughterhouse

  logging:
    level: info

  # Root of the MSP directories with keys and certs.
  cryptoconfig:
    path: /crypto-config

  # Some SDKs support pluggable KV stores, the properties under "credentialStore"
  # are implementation specific
  credentialStore:
    path: /tmp/kingbeefcattlestore

    # [Optional]. Specific to the CryptoSuite implementation used by GO SDK. Software-based implementations
    # requiring a key store. PKCS#11 based implementations does not.
    cryptoStore:
      path: /tmp/kingbeefcattlemsp

  # BCCSP config for the client. Used by GO SDK.
  BCCSP:
    security:
     enabled: true
     default:
      provider: "SW"
     hashAlgorithm: "SHA2"
     softVerify: true
     level: 256

  tlsCerts:
    # [Optional]. Use system certificate pool when connecting to peers, orderers (for negotiating TLS) Default: false
    systemCertPool: false

    # [Optional]. Client key and cert for TLS handshake with peers and orderers
    # client:
    #   keyfile:
    #   certfile:

#
# [Optional]. But most apps would have this section so that channel objects can be constructed
# based on the content below. If an app is creating channels, then it likely will not need this
# section.
#
channels:
  # name of the channel
  kingbeefcattlechannel:
    # Required. list of orderers designated by the application to use for transactions on this
    # channel. This list can be a result of access control ("org1" can only access "ordererA"), or
    # operational decisions to share loads from applications among the orderers.  The values must
    # be "names" of orgs defined under "organizations/peers"
    # deprecated: not recommended, to override any orderer configuration items, entity matchers should be used.
    # orderers:
    #  - orderer.example.com

    # Required. list of peers from participating orgs
    peers:
      peer0.slaughterhouse.kingbeefcattle.com:
        # [Optional]. will this peer be sent transaction proposals for endorsement? The peer must
        # have the chaincode installed. The app can also use this property to decide which peers
        # to send the chaincode install request. Default: true
        endorsingPeer: true

        # [Optional]. will this peer be sent query proposals? The peer must have the chaincode
        # installed. The app can also use this property to decide which peers to send the
        # chaincode install request. Default: true
        chaincodeQuery: true

        # [Optional]. will this peer be sent query proposals that do not require chaincodes, like
        # queryBlock(), queryTransaction(), etc. Default: true
        ledgerQuery: true

        # [Optional]. will this peer be the target of the SDK's listener registration? All peers can
        # produce events but the app typically only needs to connect to one to listen to events.
        # Default: true
        eventSource: true

      peer1.slaughterhouse.kingbeefcattle.com:

    policies:
      #[Optional] options for retrieving channel configuration blocks
      queryChannelConfig:
        #[Optional] min number of success responses (from targets/peers)
        minResponses: 1
        #[Optional] channel config will be retrieved for these number of random targets
        maxTargets: 1
        #[Optional] retry options for query config block
        retryOpts:
          #[Optional] number of retry attempts
          attempts: 5
          #[Optional] the back off interval for the first retry attempt
          initialBackoff: 500ms
          #[Optional] the maximum back off interval for any retry attempt
          maxBackoff: 5s
          #[Optional] he factor by which the initial back off period is exponentially incremented
          backoffFactor: 2.0


#
# list of participating organizations in this network
#
organizations:
  slaughterhouse:
    mspid: SlaughterhouseMSP
    cryptoPath: peerOrganizations/slaughterhouse.kingbeefcattle.com/users/{userName}@slaughterhouse.kingbeefcattle.com/msp
    peers:
      - peer0.slaughterhouse.kingbeefcattle.com
      # - peer1.slaughterhouse.kingbeefcattle.com

#
# List of orderers to send transaction and channel create/update requests to. For the time
# being only one orderer is needed. If more than one is defined, which one get used by the
# SDK is implementation specific. Consult each SDK's documentation for its handling of orderers.
#
orderers:
  orderer.kingbeefcattle.com:
    url: orderer.kingbeefcattle.com:7050
    # url: grpc://172.22.0.4:7050
    # these are standard properties defined by the gRPC library
    # they will be passed in as-is to gRPC client constructor
    grpcOptions:
      # ssl-target-name-override: orderer.kingbeefcattle.com
      # These parameters should be set in coordination with the keepalive policy on the server,
      # as incompatible settings can result in closing of connection.
      # When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
      keep-alive-time: 0s
      keep-alive-timeout: 20s
      keep-alive-permit: false
      fail-fast: false
      # allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
      allow-insecure: false

    tlsCACerts:
      # Certificate location absolute path
      path: /crypto-config/ordererOrganizations/kingbeefcattle.com/tlsca/tlsca.kingbeefcattle.com-cert.pem
#
# List of peers to send various requests to, including endorsement, query
# and event listener registration.
#
peers:
  peer0.slaughterhouse.kingbeefcattle.com:
    #this URL is used to send endorsement and query requests
    url: peer0.slaughterhouse.kingbeefcattle.com:7051
    # eventUrl is only needed when using eventhub (default is delivery service)
    eventUrl: peer0.slaughterhouse.kingbeefcattle.com:7053
    # url: grpc://172.22.0.2:7051
    # # eventUrl is only needed when using eventhub (default is delivery service)
    # eventUrl: grpc://172.22.0.2:7053

    grpcOptions:
      # ssl-target-name-override: peer0.slaughterhouse.kingbeefcattle.com
      # These parameters should be set in coordination with the keepalive policy on the server,
      # as incompatible settings can result in closing of connection.
      # When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled
      keep-alive-time: 0s
      keep-alive-timeout: 20s
      keep-alive-permit: false
      fail-fast: false
      # allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs
      allow-insecure: false

    tlsCACerts:
      # Certificate location absolute path
      # path: /crypto-config/peerOrganizations/slaughterhouse.kingbeefcattle.com/peers/peer0.slaughterhouse.kingbeefcattle.com/tls/ca.crt
      path: /crypto-config/peerOrganizations/slaughterhouse.kingbeefcattle.com/tlsca/tlsca.slaughterhouse.kingbeefcattle.com-cert.pem

有人可以帮忙吗?

4

3 回答 3

2

我找到了问题的原因,这是因为我已经使用它向主机公开的值配置了对等端口(在同一个网络上)。

为了解决这个问题,我更改为端口 7051 和 7053(事件),所以一些请求开始工作,但现在我有以下间歇性发生的错误:

Endorser [peer1.slaughterhouse.kingbeefcattle.com:7051] 的交易处理:Endorser 客户端状态代码:(2) CONNECTION_FAILED。说明:拨号连接超时 [peer1.slaughterhouse.kingbeefcattle.com:7051]

注意:这不是我在 config.yaml 中设置的对等主机,实际上这个对等主机来自另一个组织......

这可能与 CORE_PEER_GOSSIP_USELEADERELECTION = true 设置有关吗?

于 2018-09-15T18:06:12.063 回答
1

当对等点发现通过引用 localhost 映射的 url 而不是peer0.org1.example.com. 因此,将 config.yaml 文件更改为类似

orderers:
  orderer.example.com:
    url: localhost:7050
    grpcOptions:
      ssl-target-name-override: orderer.example.com
      keep-alive-time: 0s
      keep-alive-timeout: 20s
      keep-alive-permit: false
      fail-fast: false

      allow-insecure: false

    tlsCACerts:

      path: ${GOPATH}/src/github.com/ProjectName/fixtures/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem

peers:
  peer0.org1.example.com:

    url: localhost:7051
    eventUrl: localhost:7053

    grpcOptions:
      ssl-target-name-override: peer0.org1.example.com
      keep-alive-time: 0s
      keep-alive-timeout: 20s
      keep-alive-permit: false
      fail-fast: false

      allow-insecure: false

    tlsCACerts:
      # Certificate location absolute path
      path: ${GOPATH}/src/github.com/ProjectFolder/fixtures/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem
于 2019-01-09T11:59:55.717 回答
0

为了解决这个问题,我在主机文件中添加了以下条目,例如 sudo vi /etc/hosts 文件:

127.0.0.1    orderer.example.com
127.0.0.1    peer0.org1.example.com
127.0.0.1    ca.example.com
于 2018-10-02T05:00:53.410 回答