从客户端发送查询请求时出错:没有可用于查询的同级

时间:2019-07-03 14:05:48

标签: hyperledger-fabric blockchain hyperledger

从客户端发送查询请求时出现以下错误。

FabricError: No peers available to query. Errors: ["Failed to connect before the deadline 
URL:grpcs://localhost:12051","Failed to connect before the deadline 
URL:grpcs://localhost:11051"]. 

以下是我的connection-org3.json连接配置文件的一部分

"organizations": {
        "Org3": {
            "mspid": "Org3MSP",
            "peers": [
                "peer0.org3.bc4scm.de",
                "peer1.org3.bc4scm.de"
            ],
            "certificateAuthorities": [
                "ca.org3.bc4scm.de"
            ]
        }
    },
    "peers": {
        "peer0.org3.bc4scm.de": {
            "url": "grpcs://localhost:11051",
            "tlsCACerts": {
                "path": "crypto-config/peerOrganizations/org3.bc4scm.de/tlsca/tlsca.org3.bc4scm.de-cert.pem"
            },
            "grpcOptions": {
                "ssl-target-name-override": "peer0.org3.bc4scm.de"
            }
        },
        "peer1.org3.bc4scm.de": {
            "url": "grpcs://localhost:12051",
            "tlsCACerts": {
                "path": "crypto-config/peerOrganizations/supplier.bc4scm.de/tlsca/tlsca.org3.bc4scm.de-cert.pem"
            },
            "grpcOptions": {
                "ssl-target-name-override": "peer1.org3.bc4scm.de"
            }
        }
    },
    "certificateAuthorities": {
        "ca.org3.bc4scm.de": {
            "url": "https://localhost:9054",
            "caName": "ca-supplier",
            "tlsCACerts": {
                "path": "crypto-config/peerOrganizations/org3.bc4scm.de/tlsca/tlsca.org3.bc4scm.de-cert.pem"
            },
            "httpOptions": {
                "verify": false
            }
        }
    }

以下是我的docker composer文件的一部分。

peer0.org3.bc4scm.de:
    container_name: peer0.org3.bc4scm.de
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer0.org3.bc4scm.de
      - CORE_PEER_ADDRESS=peer0.org3.bc4scm.de:11051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:11051
      - CORE_PEER_CHAINCODEADDRESS=peer0.org3.bc4scm.de:11052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:11052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.bc4scm.de:12051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org3.bc4scm.de:11051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/org3.bc4scm.de/peers/peer0.org3.bc4scm.de/msp:/etc/hyperledger/fabric/msp
      - ../crypto-config/peerOrganizations/org3.bc4scm.de/peers/peer0.org3.bc4scm.de/tls:/etc/hyperledger/fabric/tls
      - peer0.org3.bc4scm.de:/var/hyperledger/production
    ports:
      - 11051:11051

  peer1.org3.bc4scm.de:
    container_name: peer1.org3.bc4scm.de
    extends:
      file: peer-base.yaml
      service: peer-base
    environment:
      - CORE_PEER_ID=peer1.org3.bc4scm.de
      - CORE_PEER_ADDRESS=peer1.org3.bc4scm.de:12051
      - CORE_PEER_LISTENADDRESS=0.0.0.0:12051
      - CORE_PEER_CHAINCODEADDRESS=peer1.org3.bc4scm.de:12052
      - CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:12052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org3.bc4scm.de:11051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.bc4scm.de:12051
      - CORE_PEER_LOCALMSPID=Org3MSP
    volumes:
      - /var/run/:/host/var/run/
      - ../crypto-config/peerOrganizations/org3.bc4scm.de/peers/peer1.org3.bc4scm.de/msp:/etc/hyperledger/fabric/msp
      - ../crypto-config/peerOrganizations/supplier.bc4scm.de/peers/peer1.org3.bc4scm.de/tls:/etc/hyperledger/fabric/tls
      - peer1.org3.bc4scm.de:/var/hyperledger/production
    ports:
    - 12051:12051

我从Fabcar示例中获得了此代码,并尝试从Org3(而不是Org1)中的客户端进行查询。我创建了一个管理员用户,然后在该组织中成功创建了一个用户。根据我的观察,我从执行以下代码行中得到了错误。

const result = await contract.evaluateTransaction('queryAllProducts','123');

此问题的可能原因是什么?赞赏您对此的见解。

更新:

我检查了peer0.prg3.bs4scm.de中打开的端口

root@e52992a76c3d:/opt/gopath/src/github.com/hyperledger/fabric/peer# netstat -tulpn | grep LISTEN
tcp        0      0 127.0.0.1:9443          0.0.0.0:*               LISTEN      1/peer          
tcp        0      0 127.0.0.11:46353        0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::11051                :::*                    LISTEN      1/peer          
tcp6       0      0 :::6060                 :::*                    LISTEN      1/peer          
tcp6       0      0 :::11052                :::*                    LISTEN      1/peer  

在这里我可以看到端口11051和11052已打开并正在侦听。

此外,还有一个用于安装链码的容器。

cd0b165e5186        dev-peer0.org3.bc4scm.de-scmlogic-1.0-9c7e776aa8a752e530f79d0b456f1bda28aac3f5db0af734be2f315d8d1a4f53   "/bin/sh -c 'cd /usr…"   48 seconds ago       Up 47 seconds                                                     dev-peer0.org3.bc4scm.de-scmlogic-1.0

当我查看该对等方(peer0.org3)的日志时,可以看到不断显示错误信息日志。它抱怨与org1的连接

019-07-06 10:26:52.278 UTC [gossip.discovery] expireDeadMembers -> WARN 164 Exiting
2019-07-06 10:26:56.381 UTC [gossip.comm] func1 -> WARN 165 peer1.org1.bc4scm.de:8051, PKIid:42214b7584f3fabcdb84e5770c62e4cf0f7c00b2a9d0441d772925882d4457a7 isn't responsive: EOF
2019-07-06 10:26:56.381 UTC [gossip.discovery] expireDeadMembers -> WARN 166 Entering [42214b7584f3fabcdb84e5770c62e4cf0f7c00b2a9d0441d772925882d4457a7]
2019-07-06 10:26:56.381 UTC [gossip.discovery] expireDeadMembers -> WARN 167 Closing connection to Endpoint: peer1.org1.bc4scm.de:8051, InternalEndpoint: , PKI-ID: 42214b7584f3fabcdb84e5770c62e4cf0f7c00b2a

3 个答案:

答案 0 :(得分:3)

这可能是由于多种原因造成的:

  1. 您的对等节点不可访问,因此请首先检查这些端口是否打开。

  2. 您应确认链码是否已安装在这些对等节点上。

  3. 如果不是这种情况,则必须检查chaincode的docker容器以及这些对等方中的日志,为此,您可以使用:

docker exec -it [container-name] bash

请告诉我您是否在那找到了什么而无法解决。

答案 1 :(得分:3)

您可以检查是否可以使用浏览器(Firefox)访问对等项。 request on firefox - localhost:11051,如果您可以看到响应表示您的对等方是可访问的,或者如果不是,则表明您的端口未针对同一端口打开,则转到docker文件并为该端口打开该端口,然后使用docker compose向上对等,对您要访问的每个对等对象都执行相同操作。

您甚至可以使用以下命令查看对等方的日志-

docker logs --follow peer0.org3.bc4scm.de

更新:---

您可以为两个同伴检查 CORE_PEER_GOSSIP_BOOTSTRAP和CORE_PEER_GOSSIP_EXTERNALENDPOINT

**CORE_PEER_GOSSIP_BOOTSTRAP=<a list of peer endpoints within the peer's org>
CORE_PEER_GOSSIP_EXTERNALENDPOINT=<the peer endpoint, as known outside the org>**


for peer0.org3.bc4scm.de

CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org3.bc4scm.de:12051
CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org3.bc4scm.de:11051

for peer1.org3.bc4scm.de : 

CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org3.bc4scm.de:11051
CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org3.bc4scm.de:12051
  • 相应地检查端口,您的同伴和您的docker文件。

答案 2 :(得分:0)

我遇到了同样的问题,并且意识到问题是我将“ asLocalhost”属性设置为false,并试图访问http://localhost/上的对等体。下面是正确设置属性的工作行。 (我从使用fabcar的示例中提取,否则就很棒)。

await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });