简体   繁体   English

在通道上实例化节点链码时出错

[英]Error when instantiating a node chaincode on a channel

I'm trying to instantiate an already installed node chaincode on a channel, but it fails with error: failed to invoke chaincode name:"lscc" , error: container exited with 0我正在尝试在通道上实例化已安装的节点链代码,但失败并显示错误: failed to invoke chaincode name:"lscc" , error: container exited with 0

What I did up to this point:到目前为止我做了什么:

  1. Successfully started a network with 2 organizations with 2 peers for each organization and a raft consensus using ./byfn up -c some-channel -s couchdb -o etcdraft -l node script from Building your first network (v1.4) tutorial.使用./byfn up -c some-channel -s couchdb -o etcdraft -l node script 中的./byfn up -c some-channel -s couchdb -o etcdraft -l node script 从构建你的第一个网络 (v1.4) 教程成功启动了一个包含 2 个组织的网络,每个组织有 2 个对等./byfn up -c some-channel -s couchdb -o etcdraft -l node The network already has one instantiated chaincode named mycc .网络已经有一个名为mycc实例化链mycc
  2. Connected to the network from my script using Node.js SDK.使用 Node.js SDK 从我的脚本连接到网络。 I am able to successfully invoke read and write chaincode methods of the mycc chaincode from my script.我能够从我的脚本中成功调用mycc链码的读写链码方法。
  3. Installed new chaincode on all 4 peers using each organization's admin identities.使用每个组织的管理员身份在所有 4 个对等节点上安装新的链码。 I am able to confirm that the chaincode is indeed installed by querying installed chaincodes on a peer.我能够通过查询对等方上已安装的链码来确认链码确实已安装。 Also peer container logs also confirm that the chaincode is installed successfully.此外,对等容器日志也确认链码已成功安装。
  4. Tried to instantiate the installed chaincode and encountered the above-mentioned error.尝试实例化已安装的链码并遇到上述错误。

Here is how I'm trying to instantiate my chaincode:这是我尝试实例化链码的方式:

 // Load the network configuration const ccpPath = path.resolve(__dirname, ccpName); let ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8')); // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), walletName); const wallet = new FileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. const identity = await wallet.exists(identityName); if (!identity) { console.log(`An identity for the user ${identityName} 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: identityName, discovery: { enabled: true, asLocalhost: true } }); // Get the network (channel) our contract is deployed to. const network = await gateway.getNetwork(channelName); const client = gateway.getClient(); const channel = network.getChannel(channelName); let channelPeers = channel.getPeers().map(peer => peer._peer); // console.log(channelPeers); const endorsementPolicy = { identities: [ { role: { name: 'member', mspId: 'Org1MSP' }}, { role: { name: 'member', mspId: 'Org2MSP' }} ], policy: { '1-of': [{ 'signed-by': 0 }, { 'signed-by': 1 }] } }; console.log(channelPeers[0]._name); const instantiateChaincodeRequest = { targets: channelPeers, chaincodeType: 'node', chaincodeId: 'deal', chaincodeVersion: '1.0.0', txId: client.newTransactionID(true), 'endorsement-policy': endorsementPolicy }; const instantiateResponse = await channel.sendInstantiateProposal(instantiateChaincodeRequest, 300000); console.log(instantiateResponse[0]);

This script resolves to this error:此脚本可解决此错误:

{ Error: chaincode registration failed: container exited with 0
  at self._endorserClient.processProposal (/home/projects/testing/vs-code-hlf-sc/node_modules/fabric-client/lib/Peer.js:144:36)
  at Object.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:1212:9)
  at InterceptingListener._callNext (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:568:42)
  at InterceptingListener.onReceiveStatus (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:618:8)
  at callback (/home/projects/testing/vs-code-hlf-sc/node_modules/grpc/src/client_interceptors.js:847:24)
status: 500,
payload: <Buffer >,
peer:
 { url: 'grpcs://localhost:9051',
   name: 'peer0.org2.example.com:9051',
   options: [Object] },
isProposalResponse: true }

Here are relevant peer container logs:以下是相关的对等容器日志:

2020-09-08 08:27:09.274 UTC [endorser] callChaincode -> INFO 0c7 [][7fdf845f] Entry chaincode: name:"lscc" 
2020-09-08 08:27:09.277 UTC [lscc] executeInstall -> INFO 0c8 Installed Chaincode [deal] Version [1.0.0] to peer
2020-09-08 08:27:09.277 UTC [endorser] callChaincode -> INFO 0c9 [][7fdf845f] Exit chaincode: name:"lscc"  (3ms)
2020-09-08 08:27:09.277 UTC [comm.grpc.server] 1 -> INFO 0ca unary call completed grpc.service=protos.Endorser grpc.method=ProcessProposal grpc.peer_address=192.168.48.1:59702 grpc.code=OK grpc.call_duration=3.376691ms
2020-09-08 08:45:34.201 UTC [endorser] callChaincode -> INFO 0dd [some-channel][d3a00bc9] Entry chaincode: name:"lscc" 
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0de 
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0df > deal@1.0.0 start /usr/local/src
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e0 > node deal-contract.js "--peer.address" "peer0.org2.example.com:9052"
2020-09-08 08:46:16.593 UTC [peer.chaincode.dev-peer0.org2.example.com-deal-1.0.0] func2 -> INFO 0e1 
2020-09-08 08:46:17.141 UTC [dockercontroller] func2 -> INFO 0e2 Container dev-peer0.org2.example.com-deal-1.0.0 has closed its IO channel
2020-09-08 08:46:17.314 UTC [endorser] callChaincode -> INFO 0e3 [some-channel][d3a00bc9] Exit chaincode: name:"lscc"  (43113ms)
2020-09-08 08:46:17.314 UTC [endorser] SimulateProposal -> ERRO 0e4 [some-channel][d3a00bc9] failed to invoke chaincode name:"lscc" , error: container exited with 0
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:1357
chaincode registration failed

The logs say that the chaincode was installed successfully and then the logs show an error with lscc chaincode.日志说链码安装成功,然后日志显示lscc链码错误。 So I assume the error has something to do with building stage of the chaincode.所以我认为错误与链码的构建阶段有关。 But the very same chaincode works perfectly when I deploy it with VS Code IBM Blockchain Extension.但是当我使用 VS Code IBM Blockchain Extension 部署它时,完全相同的链代码可以完美地工作。

What I've tried so far:到目前为止我尝试过的:

  • Providing / not providing endorsement policy and tweaking instantiare request object in numerous ways以多种方式提供/不提供背书政策和调整实例请求对象
  • Using different identities使用不同的身份
  • Inspecting logs of the ccenv container that is spawn for ~30 seconds when instantiation request is received.检查收到实例化请求时生成约 30 秒的ccenv容器的日志。 There were no errors没有错误
  • Restarting the network from scratch, deleting all fabric docker images and starting anew.从头开始重新启动网络,删除所有结构 docker 映像并重新开始。

So basically the question is: How can instantiate an already installed chaincode on a channel using Node.js SDK correctly?所以基本上问题是:如何使用 Node.js SDK 正确实例化通道上已安装的链码?

My environment:我的环境:

  • Ubuntu 18.04 Ubuntu 18.04

  • Hyperledger Fabric v1.4 Hyperledger Fabric v1.4

  • fabric-network 1.4.8 fabric-network 1.4.8

  • fabric-client 1.4.10 fabric-client 1.4.10

  • node 10.22.0节点 10.22.0

  • npm 6.14.6 npm 6.14.6

  • docker 19.03.12, build 48a66213fe码头工人 19.03.12,构建 48a66213fe

  • docker-compose 1.26.2, build eefe0d31 docker-compose 1.26.2,构建eefe0d31

  • chaincode is developed using fabric-contract-api链码是使用fabric-contract-api

So, for future reference, I figured it out at last.所以,为了将来参考,我终于想通了。 For some reason one of my custom chaincode classes did not inherit Init() and Invoke() methods after extending Chaincode class from fabric-shim .由于某种原因,我的一个自定义链码类在从fabric-shim扩展Chaincode类后没有继承Init()Invoke()方法。 I redeclared the methods explicitly in my chaincode class and it got instantiated successfully.我在我的链代码类中明确地重新声明了这些方法,并且它成功地实例化了。

Those methods are required by Hyperledger Fabric v1.4 Runtime Launcher. Hyperledger Fabric v1.4 Runtime Launcher 需要这些方法。

My suggestion is that you have to use two different channels for two different chaincodes.我的建议是你必须为两个不同的链码使用两个不同的通道。 You can install as much chaincode as you want in every peer but the problems will begin when you try to instantiate chaincode as this process is directly involved with network and channel.您可以在每个对等点中安装任意数量的链代码,但是当您尝试实例化链代码时,问题就会开始,因为此过程直接涉及网络和通道。 Though they change the instantiate process from version >= 2.尽管他们从版本> = 2 更改了实例化过程。

For the records:对于记录:

For running a business, some organizations have to come into a consensus and so they have to create a channel where only permissioned organizational properties have access.为了经营业务,一些组织必须达成共识,因此他们必须创建一个只有获得许可的组织属性才能访问的渠道。

Here within a channel every valid organizational peer hold a physical copy of business transactional records which is known as ledger where the ledger is identical which means every ledger that belongs to same channel must hold the same records.在一个通道中,每个有效的组织节点都持有商业交易记录的物理副本,称为账本,其中账本是相同的,这意味着属于同一通道的每个账本都必须持有相同的记录。

A ledger consists of two distinct, though related, parts – a world state and a blockchain.分类帐由两个不同但相关的部分组成——世界状态和区块链。 The world state – a database that holds current values of a set of ledger states.世界状态 - 一个数据库,其中包含一组分类帐状态的当前值。 The blockchain – a transaction log that records all the changes that have resulted in the current the world state.区块链 – 记录导致当前世界状态的所有更改的事务日志。

A chaincode is the business logic that is used to read the records of ledger or to write new records into the ledger or to update existing records.链码是用于读取账本记录或将新记录写入账本或更新现有记录的业务逻辑。

A chaincode is consist with multiple smart contracts.一个链码由多个智能合约组成。

So The convention is for each channel, you need an identical chaincode.所以约定是针对每个通道的,你需要一个相同的链码。 If you have 2 channel, than it's the convention that you have two different chaincodes.如果您有 2 个通道,那么通常会有两个不同的链码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在结构1.3的节点中实例化fabcar链码时出错 - Error in instantiating fabcar chaincode in node, fabric 1.3 调用Chaincode时出错,Node SDK,方法:channel.sendTransactionProposal() - Error Invoking Chaincode, Node SDK, Method: channel.sendTransactionProposal() 在Hyperledger Fabric 1.1中实例化node.js链码时找不到package.json - package.json not found when instantiating node.js chaincode in Hyperledger Fabric 1.1 在同一网络上实例化第二个链码时出错 - Error while instantiating 2nd chaincode on same network 使用Hyperledger Fabric Node JS创建频道时出错 - Error when Creating Channel Using Hyperledger Fabric Node JS 将背书或链码查询角色动态分配给 Fabric 节点 SDK 中的通道对等方 - Dynamically assign endorsing or chaincode query role to channel peers in the Fabric Node SDK 尝试使用Node.js SDK调用链码时出错 - Error trying to invoke chaincode using Node.js SDK 节点链码在代理后面实例化 - node chaincode instantiate behind proxy 使用Node.js SDK调用链码时出错[TypeError:无法读取未定义的属性&#39;getConnectivityState&#39; - Error invoking chaincode using Node.js SDK [TypeError: Cannot read property 'getConnectivityState' of undefined] 使用节点SDK在Hyperledger Fabric上升级Chaincode - Upgrade Chaincode on hyperledger fabric using node sdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM