简体   繁体   中英

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

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. The network already has one instantiated chaincode named mycc .
  2. Connected to the network from my script using Node.js SDK. I am able to successfully invoke read and write chaincode methods of the mycc chaincode from my script.
  3. Installed new chaincode on all 4 peers using each organization's admin identities. 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. 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.

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. There were no errors
  • Restarting the network from scratch, deleting all fabric docker images and starting anew.

So basically the question is: How can instantiate an already installed chaincode on a channel using Node.js SDK correctly?

My environment:

  • Ubuntu 18.04

  • Hyperledger Fabric v1.4

  • fabric-network 1.4.8

  • fabric-client 1.4.10

  • node 10.22.0

  • npm 6.14.6

  • docker 19.03.12, build 48a66213fe

  • docker-compose 1.26.2, build eefe0d31

  • chaincode is developed using 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 . 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM