首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在信道上实例化节点链码时出错

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

Stack Overflow用户
提问于 2020-09-08 12:26:29
回答 2查看 481关注 0票数 0

我试图在通道上实例化一个已经安装的节点链码,但是它失败了,错误:failed to invoke chaincode name:"lscc" , error: container exited with 0

到目前为止我所做的:

  1. 成功地创建了一个由2个组织组成的网络,每个组织有2个对等点,并且使用./byfn up -c some-channel -s couchdb -o etcdraft -l node脚本构建了第一个网络(v1.4)教程中的raft共识。网络已经有一个名为mycc.
  2. Connected的实例化链码从我的脚本Node.js SDK到网络。我能够在所有4个对等点上,使用每个组织的管理身份,从我的script.
  3. Installed新链码中成功地调用、读取和写入mycc链代码的链码方法。我可以通过查询对等端上已安装的链码来确认该链码确实已安装。此外,对等容器日志还确认链码已安装为successfully.
  4. Tried,以实例化已安装的链码,并遇到上述错误。

这里是我如何尝试实例化我的链码:

代码语言:javascript
运行
复制
// 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]);

此脚本解决此错误:

代码语言:javascript
运行
复制
{ 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 }

这里有相关的对等容器日志:

代码语言:javascript
运行
复制
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

日志显示链码已成功安装,然后日志显示lscc链码出现错误。所以我假设这个错误与链码的构建阶段有关。但是,当我使用VS代码扩展部署它时,同样的链码工作得很好。

到目前为止我尝试过的:

identities

  • Inspecting

  • 提供/不提供代理策略,并以多种方式调整实例化请求对象(

  • ),使用接收实例化请求时生成的ccenv容器的不同

  • 日志进行大约30秒。从零开始没有errors

  • Restarting网络,删除所有的织物对接图像并重新启动.

所以基本上问题是:如何能够正确地使用Node.js SDK在通道上实例化已经安装的链码?

我的环境:

  • Ubuntu 18.04

  • 超分类账织物v1.4

  • fabric-network 1.4.8

  • fabric-client 1.4.10

  • 节点10.22.0

  • npm 6.14.6

  • 码头19.03.12,构建48a66213fe

  • docker-compose 1.26.2,构建eefe0d31

使用fabric-contract-api开发的

  • 链码
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-09 08:57:07

所以,作为将来的参考,我终于想出了答案。由于某种原因,我的一个自定义链码类在从Init()扩展Chaincode类之后没有继承fabric-shimfabric-shim方法。我在链码类中显式地声明了方法,并成功地实例化了这些方法。

Hyperledger Fabric v1.4运行时发射器需要这些方法。

票数 1
EN

Stack Overflow用户

发布于 2020-09-08 22:56:25

我的建议是,对于两个不同的链码,你必须使用两个不同的通道。您可以在每个对等点中安装任意数量的链码,但是当您试图实例化链码时,问题就会开始,因为这个过程直接涉及到网络和通道。尽管它们改变了>= 2版本中的实例化进程。

为记录:

为了经营一家企业,一些组织必须达成共识,因此他们必须创建一个只有允许的组织属性才能访问的渠道。

在一个通道中,每个有效的组织对等方都持有一个业务事务记录的物理副本,这被称为分类账,其中分类账是相同的,这意味着属于同一通道的每个分类账都必须保存相同的记录。

分类账包括两个不同的,虽然相关的部分-一个世界状态和一个区块链。“世界状态”--一个保存一组分类账状态当前值的数据库。区块链-一个事务日志,它记录导致当前世界状态的所有更改。

链码是用于读取分类帐记录或将新记录写入分类帐或更新现有记录的业务逻辑。

链码由多个智能契约组成。

因此,对于每个通道,您需要一个相同的链码。如果您有两个通道,那么按照惯例,您有两个不同的链码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63793936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档