Process I've installed, queried, invoked fabcar chaincode via CLI. Everything was successful.
enrolAdmin.js and registerUser.js successfully worked.
BUT when I ran query.js I've got the following error
Error
error: [Remote.js]: Error: Failed to connect before the deadline URL:grpc://192.168.56.171:7051
error: [Remote.js]: Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051
error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051
Failed to evaluate transaction: Error: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpc://192.168.56.171:8051
FYI - I've tested the same with both TLS disabled and enabled. Still fails
Environment I've extended Hyperledger Fabric first-network e2e to work in multiple hosts with the help of docker swarm.
Connection profile ( without TLS) as follows
{
"name": "first-network",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"orderers": [
"orderer.example.com",
],
"peers": {
"peer0.org1.example.com": {},
"peer1.org1.example.com": {},
"peer0.org2.example.com": {},
"peer1.org2.example.com": {}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": [
"ca.org1.example.com"
]
},
"Org2": {
"mspid": "Org2MSP",
"peers": [
"peer0.org2.example.com",
"peer1.org2.example.com"
],
"certificateAuthorities": [
"ca.org2.example.com"
]
}
},
"orderers": {
"orderer.example.com": {
"url": "grpc://192.168.56.170:7050"
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpc://192.168.56.171:7051"
},
"peer1.org1.example.com": {
"url": "grpc://192.168.56.171:8051"
},
"peer0.org2.example.com": {
"url": "grpc://192.168.56.172:7051"
},
"peer1.org2.example.com": {
"url": "grpc://192.168.56.172:8051"
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "http://192.168.56.171:7054",
"caName": "ca.org1.example.com"
},
"ca.org2.example.com": {
"url": "http://192.168.56.172:7054",
"caName": "ca.org2.example.com"
}
}
}
Snippet of docker-compose file structure as follows,
networks:
hyperledger:
external:
name: hyperledger
peer0.org1.example.com:
container_name: peer0.org1.example.com
-----------------------
-----------------------
-----------------------
ports:
- 7051:7051
networks:
hyperledger:
aliases:
- peer0.org1.example.com
Expected Result - Connect to Hyperledger docker swarm containers via NodeJS
I recommend use domain. modify /etc/hosts
192.168.100.100 peer0.org1.example.com
192.168.100.100 peer1.org1.example.com
192.168.100.100 orderer.example.com
192.168.100.100 orderer.example.com
192.168.100.100 orderer3.example.com
192.168.100.100 orderer4.example.com
192.168.100.100 orderer5.example.com
modify connection-org1.json
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://peer0.org1.example.com:7051",
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://peer0.org1.example.com:7051",
modify code
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: false } });
I have found the solution for the issue. Make sure telnet works to the desired container from outside the network. By running
telnet 192.168.128.171 7051
If Telnet doesn't work --> The issue must because that ports are not published/exposed properly. 1st check the following,
Make sure CORE_PEER_LISTENADDRESS is set to listen to desired port in docker-compose files. As follows, For peer0.org1.eaxmple.com --> 7051,
CORE_PEER_LISTENADDRESS=0.0.0.0:7051
If Telnet works --> Check the connection profile. If TLS is enabled, make sure the tls certificates/PEM files are passed properly and connection is set to GRPCS (not GRPC)
Connection Profile
"certificateAuthorities": [
"ca.org1.example.com"
],
"adminPrivateKey": {
"path": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_sk"
},
"signedCert": {
"path": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
}
"peer0.org1.example.com": {
"url": "grpcs://192.168.128.171:7051",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"request-timeout": 120001
},
"tlsCACerts": {
"path": "crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
}
},
Have a look at the following link for further reference https://fabric-sdk-node.github.io/tutorial-network-config.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.