Failed to invoke chaincode name:"lscc" , error: container exited with 1: chaincode registration failed (Fabric 1.4.1)

Failed to invoke chaincode name:"lscc" , error: container exited with 1: chaincode registration failed (Fabric 1.4.1)

我正在尝试创建一个由 nodejs-sdk 引导的单一组织、单一 CA、单一对等网络。我用了this sample作为参考。

当我尝试 instantiate() 链代码时,我在 docker logs ax-peer

访问的对等节点中收到此错误
2019-06-02 13:21:51.395 UTC [ledgermgmt] CreateLedger -> INFO 028 Created ledger [default] with genesis block
2019-06-02 13:21:51.401 UTC [gossip.gossip] JoinChan -> INFO 029 Joining gossip network of channel default with 1 organizations
2019-06-02 13:21:51.401 UTC [gossip.gossip] learnAnchorPeers -> INFO 02a No configured anchor peers of AxOrgMSP for channel default to learn about
2019-06-02 13:21:51.529 UTC [gossip.state] NewGossipStateProvider -> INFO 02b Updating metadata information, current ledger sequence is at = 0, next expected block is = 1
2019-06-02 13:21:51.531 UTC [sccapi] deploySysCC -> INFO 02c system chaincode lscc/default(github.com/hyperledger/fabric/core/scc/lscc) deployed
2019-06-02 13:21:51.532 UTC [cscc] Init -> INFO 02d Init CSCC
2019-06-02 13:21:51.532 UTC [sccapi] deploySysCC -> INFO 02e system chaincode cscc/default(github.com/hyperledger/fabric/core/scc/cscc) deployed
2019-06-02 13:21:51.532 UTC [qscc] Init -> INFO 02f Init QSCC
2019-06-02 13:21:51.532 UTC [sccapi] deploySysCC -> INFO 030 system chaincode qscc/default(github.com/hyperledger/fabric/core/scc/qscc) deployed
2019-06-02 13:21:51.532 UTC [sccapi] deploySysCC -> INFO 031 system chaincode (+lifecycle,github.com/hyperledger/fabric/core/chaincode/lifecycle) disabled
2019-06-02 13:21:51.533 UTC [endorser] callChaincode -> INFO 032 [][4f292791] Exit chaincode: name:"cscc"  (656ms)
2019-06-02 13:21:51.533 UTC [comm.grpc.server] 1 -> INFO 033 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.21.0.1:50128 grpc.code=OK grpc.call_duration=657.290863ms
2019-06-02 13:21:51.541 UTC [endorser] callChaincode -> INFO 034 [][3ae34d18] Entry chaincode: name:"lscc" 
2019-06-02 13:21:51.542 UTC [endorser] callChaincode -> INFO 035 [][3ae34d18] Exit chaincode: name:"lscc"  (0ms)
2019-06-02 13:21:51.542 UTC [comm.grpc.server] 1 -> INFO 036 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.21.0.1:50128 grpc.code=OK grpc.call_duration=940.979µs
2019-06-02 13:21:51.550 UTC [endorser] callChaincode -> INFO 037 [default][17bf8e2d] Entry chaincode: name:"lscc" 
2019-06-02 13:21:51.550 UTC [endorser] callChaincode -> INFO 038 [default][17bf8e2d] Exit chaincode: name:"lscc"  (1ms)
2019-06-02 13:21:51.550 UTC [comm.grpc.server] 1 -> INFO 039 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.21.0.1:50128 grpc.code=OK grpc.call_duration=1.690033ms
2019-06-02 13:21:51.709 UTC [endorser] callChaincode -> INFO 03a [][bc977c1f] Entry chaincode: name:"lscc" 
2019-06-02 13:21:51.710 UTC [lscc] executeInstall -> INFO 03b Installed Chaincode [ax-chaincode] Version [v2] to peer
2019-06-02 13:21:51.710 UTC [endorser] callChaincode -> INFO 03c [][bc977c1f] Exit chaincode: name:"lscc"  (1ms)
2019-06-02 13:21:51.710 UTC [comm.grpc.server] 1 -> INFO 03d unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.21.0.1:50128 grpc.code=OK grpc.call_duration=1.329134ms
2019-06-02 13:21:51.738 UTC [endorser] callChaincode -> INFO 03e [default][c3bbc09e] Entry chaincode: name:"lscc" 
2019-06-02 13:21:57.532 UTC [gossip.election] beLeader -> INFO 03f 7da5b667471b7350114ff369dd11eda7255c2c9de61dc64915fa01b0ca730def : Becoming a leader
2019-06-02 13:21:57.532 UTC [gossip.service] func1 -> INFO 040 Elected as a leader, starting delivery service for channel default
2019-06-02 13:22:10.692 UTC [endorser] callChaincode -> INFO 041 [default][c3bbc09e] Exit chaincode: name:"lscc"  (18954ms)
2019-06-02 13:22:10.692 UTC [endorser] SimulateProposal -> ERRO 042 [default][c3bbc09e] failed to invoke chaincode name:"lscc" , error: container exited with 1
github.com/hyperledger/fabric/core/chaincode.(*RuntimeLauncher).Launch.func1
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/runtime_launcher.go:63
runtime.goexit
    /opt/go/src/runtime/asm_amd64.s:1333
chaincode registration failed
2019-06-02 13:22:10.693 UTC [comm.grpc.server] 1 -> INFO 043 unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=172.21.0.1:50128 grpc.code=OK grpc.call_duration=18.955253529s

排序者没有注册其他日志。我的代码如下


const createClientInstance = async () => {
  let myClient = new client();
  const ordererConfig = {
    hostname: 'orderer0',
    url: 'grpc://localhost:7050',
    pem: readCryptoFile('ordererOrg.pem')
  };
  const orderer = myClient.newOrderer(ordererConfig.url, {
    pem: ordererConfig.pem,
    'ssl-target-name-override': ordererConfig.hostname
  });

  let peerConfig = {
    hostname: 'ax-peer',
    url: 'grpc://localhost:7051',
    eventHubUrl: 'grpc://localhost:7053',
    pem: readCryptoFile('axOrg.pem')
  };
  const defaultPeer = myClient.newPeer(peerConfig.url, {
    pem: peerConfig.pem,
    'ssl-target-name-override': peerConfig.hostname
  });
  myClient.setStateStore(await client.newDefaultKeyValueStore({
    path: './ax-peer'
  }))

  let user = await myClient.getUserContext('admin', true);
  if (user && user.isEnrolled()) {
    console.log('Existing admin user used');

  } else {
    let url = 'http://localhost:7054'
    const ca = new CAClient(url, {
      verify: false
    });

    let enrollmentID = 'admin';
    let enrollmentSecret = 'adminpw';
    const enrollment = await ca.enroll({
      enrollmentID: 'admin',
      enrollmentSecret: 'adminpw'
    });
    user = new User(enrollmentID, myClient);
    await user.setEnrollment(enrollment.key, enrollment.certificate, 'AxOrgMSP');
  };
  await myClient.setUserContext(user);

  let adminUser = await myClient.createUser({
    username: `Admin@ax-peer`,
    mspid: 'AxOrgMSP',
    cryptoContent: {
      privateKeyPEM: readCryptoFile('Admin@ax-org-key.pem'),
      signedCertPEM: readCryptoFile('Admin@ax-org-cert.pem')
    }
  });
  let channelRes = await myClient.queryChannels(defaultPeer);

  // Create a new channel. Does not make you join it though
  let txId = myClient.newTransactionID();
  let envelope_bytes = fs.readFileSync('./channel.tx');
  var channelConfig = myClient.extractChannelConfig(envelope_bytes);
  let signature = myClient.signChannelConfig(channelConfig);
  const request = {
      name: 'default',
      orderer: orderer,
      config: channelConfig,
      signatures: [signature],
      txId: txId
    };

    await myClient.createChannel(request);
    let channel = myClient.newChannel('default');
    channel.addOrderer(orderer);
    channel.addPeer(defaultPeer);
    const genesisBlock = await channel.getGenesisBlock({ txId: myClient.newTransactionID() });
    let res = await channel.joinChannel({
        targets: [defaultPeer],
        txId: myClient.newTransactionID(),
        block: genesisBlock
      }, 120000);

    const installReq = {
      targets: [ defaultPeer ],
      chaincodePath: ccPath,
      chaincodeId:'ax-chaincode',
      chaincodeVersion: 'v2',
      chaincodeType: 'node'
    };
    let installRes = await myClient.installChaincode(installReq, 120000);

    let instantiateResponse = await channel.sendInstantiateProposal({
      targets: [ defaultPeer ],
      chaincodeId: 'ax-chaincode',
      chaincodeVersion: 'v2',
      chaincodeType: 'node',
      txId: myClient.newTransactionID()
    });

    // This fails
    console.log(instantiateResponse);
};

由于语言是 node 我必须提供链代码的绝对路径。我的文件夹结构是

- chaincode
  - src
    - ax-chaincode
      - package.json
      - index.js (fabric-contract-api used)
- server
  - index.js (where I am calling the above code)

如果我 运行 client.queryInstalledChaincodes(defaultPeer) 那么它 returns 这个日志所以我猜链码正在安装。

{ chaincodes: 
   [ { name: 'ax-chaincode',
       version: 'v2',
       path: '/home/varun/Algorythmix/Core-Projects/ax-boilerplate/chaincode/src/ax-chaincode',
       input: '',
       escc: '',
       vscc: '',
       id: [Object] } ] }

我该如何解决这个问题?我想坚持使用 nodejs 而不是将我的链代码更改为 golang。该示例还提取证书并将其存储在根文件夹中,因此无需执行 docker exec -it bash.

即可访问

因此,根据 Gari 的建议,我在 peer-base.yaml 文件中添加了命令。该代码仍然无效,但在 docker logs ax-peer 中弹出了一个更具描述性的错误,表示 fabric-chaincode-node 未找到。经检查,除了安装 fabric-contract-api,我还必须在链代码文件夹中安装 fabric-shim。这是在最新的 Fabric 中作为一项要求添加的 per this document

由于 fabric-contract-api 扩展了 fabric-shim 所以我没有包含它,现在我已经安装了链码。

编辑- 2020

nodejs SDK的文档已经转移。 fabric-contract-api 的发行说明和新的依赖项可以在 at this link 中找到,其中指出 fabric-shim 现在是 fabric-shim-api