Hyperledger Fabric 更新分类账失败

Hyperledger Fabric Updating Ledger Fail

我正在尝试通过 Hyperledger Fabric 中的第一个演示 "Writing Your First Application" https://hyperledger-fabric.readthedocs.io/en/release-1.2/write_first_app.html。我成功 运行 查询部分(queryAllCars 和 queryCar 方法)。 我在更新分类帐部分遇到问题。这就是我所做的:

  1. 将值放入 invoke.js 文件中:

    var request = {
    //targets: let default to the peer assigned to the client
    chaincodeId: 'fabcar',
    fcn: 'createCar',
    args: ['CAR10', 'Chevy', 'Volt', 'Red', 'Nick'],
    chainId: 'mychannel',
    txId: tx_id};
    
  2. 运行 节点 invoke.js 并进入终端:

Store path:/home/krystian/hyperledger-test/fabric-samples/fabcar/hfc-key-store

Successfully loaded user1 from persistence

Assigning transaction_id: 0dfca05d6f19187275c6a31febc81429ddca3a284fd590c631961a10f8da5aee

Transaction proposal was good

Successfully sent Proposal and received ProposalResponse: Status - 200, message - ""

Failed to invoke successfully :: Error: There was a problem with the eventhub ::14 UNAVAILABLE: TCP Write failed

at createStatusError (/home/krystian/hyperledger-test/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/client.js:64:15)
at ClientDuplexStream._emitStatusIfDone (/home/krystian/hyperledger-test/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/client.js:270:19)
at ClientDuplexStream._receiveStatus (/home/krystian/hyperledger-test/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/client.js:248:8)
at /home/krystian/hyperledger-test/fabric-samples/fabcar/node_modules/fabric-client/node_modules/grpc/src/client.js:804:12

这是我的package.json

{
"name": "fabcar",
"version": "1.0.0",
"description": "Hyperledger Fabric Car Sample Application",
"main": "fabcar.js",
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
    "fabric-ca-client": "^1.2.1",
    "fabric-client": "^1.2.1",
    "grpc": "^1.15.1"
},
"author": "Anthony O'Dowd",
"license": "Apache-2.0",
"keywords": [
    "Hyperledger",
    "Fabric",
    "Car",
    "Sample",
    "Application"
]

}

这是 invoke.js 崩溃的一部分:

        let event_hub = fabric_client.newEventHub();

    event_hub.setPeerAddr('grpc://localhost:7053');

    // using resolve the promise so that result status may be processed
    // under the then clause rather than having the catch clause process
    // the status
    let txPromise = new Promise((resolve, reject) => {
        let handle = setTimeout(() => {
            event_hub.disconnect();
            resolve({event_status : 'TIMEOUT'}); //we could use reject(new Error('Trnasaction did not complete within 30 seconds'));
        }, 3000);
        **event_hub.connect();
        event_hub.registerTxEvent(transaction_id_string, (tx, code) => {
            // this is the callback for transaction event status
            // first some clean up of event listener
            clearTimeout(handle);
            event_hub.unregisterTxEvent(transaction_id_string);**
            event_hub.disconnect();

我尝试再次删除 fabcar/node_modules 和 运行 npm install。 我也尝试过 运行 sudo node invoke.js。 我完成了构建您的第一个网络的教程,一切正常。

节点版本 v8.9.0

NPM 版本 5.5.1

我正在使用 Linux Mint

当 initLedger 方法和查询没有问题时,更新分类帐哪里会出现问题?

我又遇到了那个错误,我终于解决了。 那是 grpc 版本不匹配。我曾经有使用 grpc@1.14.2 的 Hyperledger Fabric 网络 v1.3.0,我的客户端应用程序在 package.json 文件中设置了 fabric-client 的 v.1.1.0 和 v1.6.6 grpc。

修复后我又遇到了另一个错误:

Failed to invoke successfully :: TypeError: fabric_client.newEventHub is not a function

但该错误已在此处解决: .

因此,如果您遇到相同的问题,则必须在网络和客户端应用程序中使用相同版本的软件包。