Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error initializing the network channel from node sdk in hyperledger fabric

Background: I have modified the first-network files (to a network with 2 Orgs and 1 peer in each of them) and installed my own chaincode on it. Additionally I have made a connection.yaml file to interact with the network.

Problem: But when I try to get the network channel & establish the gateway from nodeSDK, I encounter this error:

error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: 2 UNKNOWN: Stream removed

Failed to evaluate transaction: Error: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: 2 UNKNOWN: Stream removed

Below you can find the code on my client side. The error probably arises when gateway.getNetwork('mychannel') is executed.

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');

This is my connection.yaml file:

---
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/[email protected]/msp/keystore/63145b12cd86abb07b6b5797c5e9506faa8f799e81d3c71d11a6a60840e3b6ae_sk
    signedCert:
      path: ../first-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]

  Org2:
    mspid: Org2MSP
    peers:
      - peer0.org2.example.com
    certificateAuthorities:
      - certificate-authority-org2
    adminPrivateKey:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/4d9b19fdcce70620b45760f5d62c7c877200ab38553b7a8b85245b04ca0e8bdd_sk
    signedCert:
      path: ../first-network/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]

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

I have been unable to figure out whether there is some problem with connection.yaml file or there is something wrong within the network.

like image 925
dawood Avatar asked Mar 05 '23 08:03

dawood


1 Answers

BYFN/EFYN enable TLS on all of the Fabric nodes (peers, orderers, certificate authorities) to secure communications. Your connection profile has "grpc://" and "http://" URLs - these should be changed to "grpcs://" and "https://". It looks like the TLS CA certificates are correct.

like image 106
Simon Stone Avatar answered May 16 '23 07:05

Simon Stone