CamoxFromGeopolis
CamoxFromGeopolis

Reputation: 83

HyperLedger 2.3.1 Failed to Connect on Committer

I am trying to execute a smart contract on the Hyperledger fabric test-network (Fabcar javascript smart contract) and I get the follwing error when I try to invoke the chaincode using the invoke.js file present in the fabcar javascript example:

error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer0.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true 2021-05-05T23:44:02.951Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer0.example.com:7050 url:grpcs://localhost:7050 timeout:3000 2021-05-05T23:44:02.952Z - error: [DiscoveryService]: _buildOrderer[mychannel] - Unable to connect to the discovered orderer orderer0.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer0.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true 2021-05-05T23:44:05.957Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org01.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true 2021-05-05T23:44:05.957Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org01.example.com:7051 url:grpcs://localhost:7051 timeout:3000 2021-05-05T23:44:05.958Z - error: [DiscoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org01.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org01.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true

One thing to note is that I have changed port forwardings and peer/org names in the default test-network. My connection profile is as follows (removed certificates for clarity):

{
"name": "test-network-org1",
"version": "1.0.0",
"client": {
    "organization": "Org1",
    "connection": {
        "timeout": {
            "peer": {
                "endorser": "300"
            }
        }
    }
},
"channels": {
    "mychannel": {
        "orderers": [
            "orderer0.example.com"
        ],
        "peers": [
            "peer0.org01.example.com"
        ]
    }
},
"organizations": {
    "Org1": {
        "mspid": "Org1MSP",
        "peers": [
            "peer0.org01.example.com"
        ],
        "certificateAuthorities": [
            "ca.org1.example.com"
        ]
    }
},
"peers": {
    "peer0.org01.example.com": {
        "url": "grpcs://localhost:6041",
        "tlsCACerts": {
            "pem": "-----BEGIN CERTIFICATE-----**********-----END CERTIFICATE-----\n"
        },
        "grpcOptions": {
            "ssl-target-name-override": "peer0.org01.example.com",
            "hostnameOverride": "peer0.org01.example.com"
        }
    }
},
"orderers": {
    "orderer0.example.com": {
        "url": "grpcs://localhost:6040",
        "tlsCACerts": {
            "pem": "-----BEGIN CERTIFICATE-----**********-----END CERTIFICATE-----\n"
        },
        "grpcOptions": {
            "ssl-target-name-override": "orderer0.example.com"
        }
    }
},
"certificateAuthorities": {
    "ca.org1.example.com": {
        "url": "https://localhost:6054",
        "caName": "ca-org1",
        "tlsCACerts": {
            "pem": ["-----BEGIN CERTIFICATE-----******-----END CERTIFICATE-----\n"]
        },
        "httpOptions": {
            "verify": false
        }
    }
}

}

One thing that puzzles me (which I believe is the root cause of the error) is the grpcs url for the orderer. In the connection profile I have clearly specified it to be grpcs://localhost:6041, however as can be seen in the error, the error states the url as grpcs://localhost:7050. I have gone over the various files in the test-network and have not been able to figure out why the grpcs url is not read from the connection profile.

This problem is only limited to the query.js and invoke.js files in the fabcar example (I am able to successfully execute enrollAdmin.js and registerUser.js on the network).

Following is the invoke.js file I execute which leads to aforementioned error:

   'use strict';

const { Gateway, Wallets } = require('fabric-network');
const fs = require('fs');
const path = require('path');

async function main() {
    try {
        // load the network configuration
        const ccpPath = path.resolve(__dirname, '..', '..', 'test-network', 'organizations', 'peerOrganizations', 'org1.example.com', 'connection-org1.json');
        let ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));

        // Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = await Wallets.newFileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        // Check to see if we've already enrolled the user.
        const identity = await wallet.get('appUser3');
        if (!identity) {
            console.log('An identity for the user "appUser3" does not exist in the wallet');
            console.log('Run the registerUser.js application before retrying');
            return;
        }

        // Create a new gateway for connecting to our peer node.
        const gateway = new Gateway();
        await gateway.connect(ccp, { wallet, identity: 'appUser3', discovery: { enabled: true, asLocalhost: true } });

        // 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('fabcar');

        // Submit the specified transaction.
        // createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
        // changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR12', 'Dave')
        await contract.submitTransaction('createCar', 'CAR312', 'Skoda', 'Kadiq', 'White', 'JOHNSON');
        console.log('Transaction has been submitted');

        // Disconnect from the gateway.
        await gateway.disconnect();

    } catch (error) {
        console.error(`Failed to submit transaction: ${error}`);
        process.exit(1);
    }
}

main();

Any help would be appreciated. Thank You

Upvotes: 0

Views: 870

Answers (1)

bestbeforetoday
bestbeforetoday

Reputation: 1649

I think the key piece of information is this part of the error message:

Unable to connect to the discovered orderer orderer0.example.com:7050

This is a node that has been located by the client using service discovery, not defined in your connection profile.

What I suspect has happened is that, even though you have changed the port mappings between your local machine and the Docker network, the orderer is still listening on port 7050 within your Docker network.

The discovery.asLocalhost connection option is there to support the scenario where the blockchain network is running within a Docker network on the client's local machine, so it causes any discovered hostnames to be treated as localhost, but it leaves the discovered port numbers unchanged. So, when using the discovery.asLocalhost option, the port numbers that nodes are listening on within the Docker network must be mapped to the same port numbers on the local machine.

If you want to change the port numbers then you need to change them on the actual nodes themselves, not just in your Docker network mappings.

Upvotes: 5

Related Questions