4

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/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

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

dawood
  • 43
  • 1
  • 4
  • Do you have the docker containers up and running for both the peers? If so, then check if the peers have joined the channel. – Dheeraj Kumar Mar 18 '19 at 11:20
  • @DheerajKumar yes, the containers are up and running. And both peers have already joined the channel. – dawood Mar 18 '19 at 11:39
  • see https://github.com/hyperledger/fabric-samples/blob/master/commercial-paper/organization/magnetocorp/gateway/networkConnection.yaml as a comparison. Noticed your `name` entry isn't in double quotes (the example is) - not sure if its mandated. – Paul O'Mahony Mar 18 '19 at 11:54
  • Mentioned the name in double quotes. Didn't make any difference. – dawood Mar 18 '19 at 12:00

1 Answers1

7

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.

Simon Stone
  • 495
  • 2
  • 4
  • As you said, I changed them to "grpcs://" and "https://" in connection profile. Now it's giving me this error: `error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: 2 UNKNOWN: access denied: channel [myc1] creator org [Org1MSP] Failed to evaluate transaction: Error: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: 2 UNKNOWN: access denied: channel [myc1] creator org [Org1MSP]` – dawood Mar 20 '19 at 12:33
  • 1
    I'm accepting this as the answer although it solved half of my issue. I certainly needed my connection profile to have "grpcs://" and "https://". However, the next thing that I missed was to add/register a user who is part of any of the organizations of the first- network. Initially, I had a different user registered at the client side (node SDK) and as a result I was receiving the error that I have mentioned in my comment above. Having registered a user (who's part of the first-network) and changing my connection profile, I successfully resolved all the errors. – dawood Apr 04 '19 at 13:33
  • Hi, i am facing the same issue. I have registered user1 in both ca and in client but I am still getting the same error. could you please be more specific how did you fix this issue? – user1456110 Dec 03 '20 at 05:30