我正在运行byfn
教程的修改版,其中包含5个订购者,1个组织,2个同级和1个具有docker-compose的ca服务。我在本地使用node v10.18.1
上的macOs Catalina
运行节点应用程序。hyperledger fabric version 1.4
也正在使用。
[我尝试用connection.json
命令提供的容器替换与[c0]到grpcUrl的路径有关的localhost
到IP的路径,也没有成功替换到docker inspect
的路径,也使用telnet来grep暴露的端口并运行0.0.0.0
,以检查所有容器是否都在正确的端口上运行。
在我的代码中,我可以成功注册管理员和其他用户,但是当我尝试连接到网关以调用链码时,它会失败。
我一直在我的API日志中收到错误:
docker ps
为什么会出现此错误?
我的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"
文件是:
connection.json
这些是我的package.json文件中的依赖项(请记住,我已经尝试过手动安装最新的grpc模块,但没有成功):
{
"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
}
}
}
}
这是我失败的代码:
"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"
}
[通过在docker-compose文件中查找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;
}
};
标志,确保为同级启用TLS通信。如果未设置为true,则将连接配置文件中的对等URL从CORE_PEER_TLS_ENABLED=true
修改为grpcs://localhost:7051