Reputation: 4228
I am running a modified version of the byfn
tutorial, with 5 orderers, 1 org, 2 peers and 1 ca service with docker-compose. Locally I am running a node application, using node v10.18.1
on macOs Catalina
.
The hyperledger fabric version 1.4
is also being used.
I have tried replacing the path in the connection.json
file relating to the grpcUrl's from localhost
to the IP for the containers provided with docker inspect
command and also to 0.0.0.0
without any success, have also used telnet to grep the exposed ports and have run docker ps
to check that all containers are running with the correct ports.
In my code I can successfully register the admin and other users, but it fails when I try to connect to the gateway to invoke the chaincode.
I am constantly getting the error in my API logs:
2020-01-15T15:42:37.920Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:37.922Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:40.929Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.929Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.930Z - error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051
level:warn time:2020-01-15T15:42:40.932Z message: "x-request-id_ac5294fd-9587-4432-87d9-ada4e73a1142 creating user product Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051"
Why am I getting this error?
My connection.json
file is:
{
"name": "first-network-org1",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": [
"ca.org1.example.com"
]
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"hostnameOverride": "peer0.org1.example.com"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com",
"hostnameOverride": "peer1.org1.example.com"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca-org1",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
}
}
}
These are the dependencies in my package.json file (bare in mind I have tried manually installing the latest grpc module without any success):
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"fabric-ca-client": "^1.4.4",
"fabric-client": "^1.4.4",
"fabric-network": "^1.4.4",
"helmet": "^3.15.1",
"http-status": "^1.3.1",
"joi": "^14.3.1",
"lodash": "^4.17.11",
"nconf": "^0.10.0",
"request-promise": "^4.2.4",
"swagger-stats": "^0.95.7",
"uuid": "^3.3.2",
"winston": "^3.2.1",
"xss": "^1.0.3"
}
Here is my failing code:
const initGateway = async (params) => {
try {
const {
wallet,
identity,
discovery, // object with { enabled: true, asLocalhost: true }
channelName,
contractName
} = params;
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity, discovery });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
logger.info({ message: `NETWORK ${network}` });
// Get the contract from the network.
const contract = network.getContract(contractName);
return { gateway, contract };
} catch (err) {
throw err;
}
};
const createProduct = async (dataObj) => {
try {
const {
userIdentity,
seller,
value,
description,
issueDateTime,
productId
} = dataObj;
// Create a new file system based wallet for managing identities
const wallet = new FileSystemWallet(walletFilePath);
const params = {
wallet,
identity: userIdentity,
discovery: { enabled: true, asLocalhost: true },
channelName: 'mychannel',
contractName: 'mychaincode'
};
// Get the contract from the network.
const { gateway, contract } = await initGateway(params);
await contract.submitTransaction('setForSale', seller, productId, issueDateTime, value, description);
// Disconnect from the gateway.
await gateway.disconnect();
} catch (err) {
throw err;
}
};
Upvotes: 2
Views: 3160
Reputation: 4228
Answering my own question here.
I had noticed that the grpcOptions
in the connection file had wrong values. Namely the ssl-target-name-override
and hostnameOverride
were pointing to non-existent docker container names. Setting them to the correct peer container names fixed this error. #facepalm
Upvotes: 1
Reputation: 43
Make sure you enabled TLS communications for peers by looking up to CORE_PEER_TLS_ENABLED=true
flag in your docker-compose file. If it is not set to true, then modify peer urls in connection profiles from grpcs://localhost:7051
to grpc://localhost:7051
Upvotes: 3