无法在具有Hyperledger Fabric网络的节点应用程序中调用事务?

时间:2019-02-12 09:51:28

标签: hyperledger-fabric hyperledger

问题:

我自己建立了一个Hyperledger架构网络。然后我在那里安装并实例化了一个网络,我成功地在cli容器上进行了交易。然后,我尝试使用节点js SDK进行事务。在那里,我创建一个connection.js文件。使用它,我可以发出管理员和用户身份。但是,当我尝试调用事务时,会出现错误错误:需要PEM编码的证书。

这是我的connection.js文件的外观。

{
"name": "mynetwork",
"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": {
"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",
"peer1.org1.example.com"
],
"certificateAuthorities": ["ca.org1.example.com"],
"adminPrivateKey": {
"path": "../crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/27eb88cf4af9d4e38a3a154b55f71f46576f118a48a5cf3dd15eb20e412629c_sk"
},
"signedCert": {
"path": "../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",
"peer1.org2.example.com"
],
"certificateAuthorities": ["ca.org2.example.com"],
"adminPrivateKey": {
"path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/105cec4dc08b10f82b52816c499e613a81d09756bb40824f4cd27c08189028c_sk"
},
"signedCert": {
"path": "../crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem"
}
}
},
"orderers": {
"orderer.example.com": {
"url": "grpcs://localhost:7050",
"grpcOptions": {
"ssl-target-name-override": "orderer.example.com",
"grpc-max-send-message-length": 15
},
" tlsCACerts": {
"path": "../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
}
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"eventUrl": "grpcs://localhost:8053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem"
}
},
"peer0.org2.example.com": {
"url": "grpcs://localhost:9051",
"eventUrl": "grpcs://localhost:9053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org2.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
}
},
"peer1.org2.example.com": {
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com",
"grpc.keepalive_time_ms": 600000
},
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"httpOptions": {
"verify": false
},
"caName": "ca.org1.example.com",
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem"
}
},
"ca.org2.example.com": {
"url": "https://localhost:7054",
"httpOptions": {
"verify": false
},
"caName": "ca.org2.example.com",
"tlsCACerts": {
"path": "../crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem"
}
}
}
}

这就是我的invoke.js文件的样子。

/*
* SPDX-License-Identifier: Apache-2.0
*/

"use strict";

const { FileSystemWallet, Gateway } = require("fabric-network");
const fs = require("fs");
const path = require("path");

const ccpPath = path.resolve(__dirname, ".", "connection.json");
const ccpJSON = fs.readFileSync(ccpPath, "utf8");
const ccp = JSON.parse(ccpJSON);

async function main() {
try {
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(), "wallet");
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);

// Check to see if we've already enrolled the user.
const userExists = await wallet.exists("TharinduSA");
if (!userExists) {
console.log(
'An identity for the user "user1" 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: "TharinduSA",
discovery: { enabled: false }
});

console.log(gateway);

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork("mychannel");
// console.log(network);

// Get the contract from the network.
const contract = network.getContract("fabcar");
// console.log(contract);
``
// Submit the specified transaction.
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR10', 'Dave')
await contract.submitTransaction(
"createCar",
"CAR12",
"Honda",
"Accord",
"Black",
"Tom"
);
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();

我逐行注释掉并检查错误发生的地方。然后,我发现这行失败了。 const network = await gateway.getNetwork("mychannel"),当我寻找订购者的日志时,它将留在终端机上。

2019-02-10 13:17:53.903 UTC [common.deliver] Handle -> WARN 00c Error reading from 172.19.0.9:50024: rpc error: code = Canceled desc = context canceled
2019-02-10 13:17:53.904 UTC [comm.grpc.server] 1 -> INFO 00d streaming call completed {"grpc.start_time": "2019-02-10T13:17:53.655Z", "grpc.service": "orderer.AtomicBroadcast", "grpc.method": "Deliver", "grpc.peer_address": "172.19.0.9:50024", "error": "rpc error: code = Canceled desc = context canceled", "grpc.code": "Canceled", "grpc.call_duration": "249.1296ms"}
2019-02-10 13:19:36.344 UTC [common.deliver] Handle -> WARN 00e Error reading from 172.19.0.9:50034: rpc error: code = Canceled desc = context canceled
2019-02-10 13:19:36.345 UTC [comm.grpc.server] 1 -> INFO 00f streaming call completed {"grpc.start_time": "2019-02-10T13:19:36.313Z", "grpc.service": "orderer.AtomicBroadcast", "grpc.method": "Deliver", "grpc.peer_address": "172.19.0.9:50034", "error": "rpc error: code = Canceled desc = context canceled", "grpc.code": "Canceled", "grpc.call_duration": "31.1696ms"}
2019-02-10 13:19:36.345 UTC [orderer.common.broadcast] Handle -> WARN 010 Error reading from 172.19.0.9:50036: rpc error: code = Canceled desc = context canceled
2019-02-10 13:19:36.345 UTC [comm.grpc.server] 1 -> INFO 011 streaming call completed {"grpc.start_time": "2019-02-10T13:19:36.329Z", "grpc.service": "orderer.AtomicBroadcast", "grpc.method": "Broadcast", "grpc.peer_address": "172.19.0.9:50036", "error": "rpc error: code = Canceled desc = context canceled", "grpc.code": "Canceled", "grpc.call_duration": "15.8332ms"}
2019-02-10 13:25:09.482 UTC [orderer.common.broadcast] Handle -> WARN 012 Error reading from 172.19.0.9:50350: rpc error: code = Canceled desc = context canceled
2019-02-10 13:25:09.482 UTC [comm.grpc.server] 1 -> INFO 013 streaming call completed {"grpc.start_time": "2019-02-10T13:23:29.301Z", "grpc.service": "orderer.AtomicBroadcast", "grpc.method": "Broadcast", "grpc.peer_address": "172.19.0.9:50350", "error": "rpc error: code = Canceled desc = context canceled", "grpc.code": "Canceled", "grpc.call_duration": "1m40.1810731s"}
2019-02-11 03:49:50.311 UTC [orderer.common.broadcast] Handle -> WARN 014 Error reading from 172.19.0.9:54714: rpc error: code = Canceled desc = context canceled
2019-02-11 03:49:50.311 UTC [comm.grpc.server] 1 -> INFO 015 streaming call completed {"grpc.start_time": "2019-02-11T03:49:50.191Z", "grpc.service": "orderer.AtomicBroadcast", "grpc.method": "Broadcast", "grpc.peer_address": "172.19.0.9:54714", "error": "rpc error: code = Canceled desc = context canceled", "grpc.code": "Canceled", "grpc.call_duration": "120.1639ms"}

在同级上的日志就像。

 2019-02-11 03:53:06.171 UTC [peer.gossip.mcs] Verify -> ERRO 1956 Failed getting validated identity from peer identity

有人可以帮助我找出我做错了什么吗?这使我脱离开发工作三到五天,我真的真的需要针对这个问题的解决方案。谢谢!

1 个答案:

答案 0 :(得分:0)

由于启用了TLS,因此在尝试连接到订购者和对等方时需要通过pem编码的证书。您可以通过查看here

来了解您的想法