在超级账本结构中初始化来自节点sdk的网络通道时出错

时间:2019-03-18 10:44:17

标签: hyperledger-fabric hyperledger blockchain hyperledger-fabric-sdk-js

背景: 我已经修改了第一个网络文件(到每个网络中有2个组织和1个对等体的网络),并在上面安装了自己的链码。另外,我制作了一个connection.yaml文件来与网络交互。

问题: 但是,当我尝试获取网络通道并从nodeSDK建立网关时,遇到此错误:

  

错误:[网络]:_initializeInternalChannel:无法初始化   渠道。尝试联系2个对等方。最后一个错误是错误:2   未知:流已删除

     

无法评估交易:错误:无法初始化渠道。   尝试联系2个对等方。上一个错误是错误:2未知:流   删除

下面您可以在我的客户端上找到代码。执行gateway.getNetwork('mychannel')时可能会出现错误。

let connectionProfile = yaml.safeLoad(fs.readFileSync('./connection.yaml', 'utf8'));
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(connectionProfile, { wallet, identity: 'user1', discovery: { enabled: false } });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');
// Get the contract from the network.

const contract = network.getContract('bankpeerContract');
var result = await contract.evaluateTransaction('queryAllStamps');

这是我的connection.yaml文件:

---
name: mychannel.firstnetwork.connectionprofile
x-type: "hlfv1"
description: "BankPeerContract methods will be used through this profile"
version: "1.0"

channels:
  mychannel:
    orderers:
      - orderer.example.com
    peers:
      peer0.org1.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true
      peer0.org2.example.com:
        endorsingPeer: true
        chaincodeQuery: true
        ledgerQuery: true
        eventSource: true

organizations:
  Org1:
    mspid: Org1MSP
    peers:
      - peer0.org1.example.com
    certificateAuthorities:
      - certificate-authority-org1
    adminPrivateKey:
      path: ../first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/63145b12cd86abb07b6b5797c5e9506faa8f799e81d3c71d11a6a60840e3b6ae_sk
    signedCert:
      path: ../first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem

  Org2:
    mspid: Org2MSP
    peers:
      - peer0.org2.example.com
    certificateAuthorities:
      - certificate-authority-org2
    adminPrivateKey:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/4d9b19fdcce70620b45760f5d62c7c877200ab38553b7a8b85245b04ca0e8bdd_sk
    signedCert:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem

orderers:
  orderer.example.com:
    url: grpc://localhost:7050
    grpcOptions:
      ssl-target-name-override: orderer.example.com
    tlsCACerts:
      path: ../first-network/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

peers:
  peer0.org1.example.com:
    url: grpc://localhost:7051
    grpcOptions:
      ssl-target-name-override: peer0.org1.example.com
      request-timeout: 120001
    tlsCACerts:
      path: ../first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem

  peer0.org2.example.com:
    url: grpc://localhost:9051
    grpcOptions:
      ssl-target-name-override: peer0.org2.example.com
      request-timeout: 120001
    tlsCACerts:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem

certificateAuthorities:
  ca-org1:
    url: http://localhost:7054
    httpOptions:
      verify: false
    tlsCACerts:
      path: ../first-network/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem
    registrar:
      - enrollId: admin
        enrollSecret: adminpw
    caName: certificate-authority-org1
  ca-org2:
    url: http://localhost:8054
    httpOptions:
      verify: false
    tlsCACerts:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem
    registrar:
      - enrollId: admin
        enrollSecret: adminpw
    caName: certificate-authority-org2

我一直无法弄清楚connection.yaml文件是否存在问题或网络中是否存在问题。

1 个答案:

答案 0 :(得分:1)

BYFN / EFYN在所有交换矩阵节点(对等,订购者,证书颁发机构)上启用TLS,以保护通信。您的连接配置文件具有“ grpc://”和“ http://” URL-应将其更改为“ grpcs://”和“ https://”。看来TLS CA证书是正确的。