Instantiate test contract fails with Contract name is not known - hyperledger-fabric

I am trying to adapt the commercial paper tutorial to a custom contract. As soon as I change the contract name, I cannot instantiate it.
In commercial-paper/organization/magnetocorp/contract/lib, I updated paper.js to replace:
static getClass() {
return 'org.papernet.commercialpaper';
}
... with
static getClass() {
return 'org.papernet.commercialpapertest';
}
Similarly, in commercial-paper/organization/magnetocorp/contract/lib, I updated papercontract.js to replace:
constructor() {
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper');
}
... with:
constructor() {
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpapertest');
}
I then changed the instantiate command from:
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpaper:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
... to:
docker exec cliMagnetoCorp peer chaincode instantiate -n papercontract -v 0 -l node -c '{"Args":["org.papernet.commercialpapertest:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"
On deleting the couchdb databases, stopping then removing all containers, and rerunning the example from scratch, these changes causes instantiate to fail with Contract name is not known:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg transaction returned with failure: Error: Contract name is not known: org.papernet.commercialpapertest
Here is the docker log:
> papercontract#0.0.3 start /usr/local/src
> fabric-chaincode-node start "--peer.address" "peer0.org1.example.com:7052"
2019-09-08T16:11:08.911Z info [shim:contracts-spi/bootstrap.js]
No metadata file supplied in contract, introspection will generate all the data
2019-09-08T16:11:08.914Z info [shim:contracts-spi/chaincodefromcontract.js]
Using serializers {"transaction":"jsonSerializer","serializers":{}}
2019-09-08T16:11:08.942Z info [shim:lib/chaincode.js]
Registering with peer peer0.org1.example.com:7052 as chaincode "papercontract:0"
Command succeeded
2019-09-08T16:11:08.971Z info [shim:lib/handler.js] Successfully registered with peer node. State transferred to "established"
2019-09-08T16:11:08.972Z info [shim:lib/handler.js] Successfully established communication with peer node. State transferred to "ready"
2019-09-08T16:11:08.977Z error [shim:contracts-spi/chaincodefromcontract.js [mychannel-971a76f9] Error: Contract name is not known: org.papernet.commercialpapertest
2019-09-08T16:11:08.977Z error [shim:lib/handler.js] [mychannel-971a76f9] Calling chaincode Init() returned error response [Error: Contract name is not known: org.papernet.commercialpapertest]. Sending ERROR message back to peer
Listing installed contracts shows that the contract is installed:
Get installed chaincodes on peer:
Name: papercontract, Version: 0, Path: /opt/gopath/src/github.com/contract, Id: a766e52585dbf1c0c9b725a72e66bd0e3f50f83da8641c9a4b4d6aebd6b85777
Listing instantiated contracts show that it is not instantiated:
Get instantiated chaincodes on channel mychannel:
It seems as if the original contract name is set somewhere else also? If so, I cannot locate it with a "Find in Files" search from VS Code.
Help gratefully received.

It seems you didn't change the contract name in package.json papercontract as the contract installed on peer with details name: papercontract, Version: 0

Related

Hyperledger Fabric: CouchDB doesn't show the worldstate of a channel

The HLF Version I use is 2.2
I set up my own network consisting of 3 Orgs, 1 Orderer and 2 Channels. The network is set up and I can call Chaincode Functions responding with 200. So far, so good. The problem is I don't see the worldstate in CouchDB. I think it's related due to the fact the chaincode is not instantiated properly or at all
When I call:
peer chaincode list --instantiated -C examplechannel
It doesn't return anything. But if I try to set the flag --isInit on the first Invoke.
peer chaincode invoke -o localhost:7050 -C examplechannel -n example --peerAddresses localhost:9051 --isInit -c '{"function":"instantiate","Args":[]}'
The response is:
chaincode 'example' does not require initialization but called as init
When I try to instantiate the Chaincode by:
peer chaincode instantiate -o localhost:7050 -C examplechannel -n example -v 1 -c '{"function":"instantiate","Args":[]}'
I get the response:
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg Channel 'examplechannel' has been migrated to the new lifecycle, LSCC is now read-only
Any suggestions?
There is difference in the chaincode installation from Fabric version 2.0 when compare to previous version. Please refer below documentation for more details regarding new chaincode lifecycle
https://hyperledger-fabric.readthedocs.io/en/release-2.2/deploy_chaincode.html

Error while invoking javascript chaincode

Error: endorsement failure during invoke. response: status:500 message:"make sure the chaincode basic2 has been successfully defined on channel mychannel and try again: chaincode definition for 'basic2' exists, but chaincode is not installed"
It gives me this error whenever I try to invoke chaincode but when I try to install chaincode again it shows that chain code is successfully installed. what should be the meaning of this error?
It also does not create a docker container.
So i try to instantiated with command
COMMAND: peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -l node -n basic2 -v 1 -c '{"Args":["init"]}' -P 'OR ("Org1MSP.member")'
But then i got new error:
Error: error getting broadcast client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
I check the logs of Orderer then it shows :
Can anyone tell me what is problem and how should i resolve it?
Try enabling the tls using the '--tls' flag. Also, you can refer to this similar question here
Make sure you're following the steps properly. Also, if you're sure about the steps, sometimes it works if you retry without making any changes, just repeat the step where you're facing the error without making any changes, it should work on the 3rd try atmost if everything goes well.

Hyperledger Fabric: Peer Node Rollback

I am following Hyperledger V 1.4 documsation to roll back the channel mychannel to block number 150 using this following command:
peer node rollback -c mychannel -b 150
If I run this inside CLI container it's showing:
Validating the rollback parameters: ledgerID [mychannel], block number
[0]
Error: ledgerID [mychannel] does not exist.
If i run inside peer0 it is giving an error
Error: as another peer node command is executing, wait for that
command to complete its execution or terminate it before retrying:
lock is already acquired on file
/var/hyperledger/production/ledgersData/fileLock
I have tried different possible ways by stop and pausing the nodes but failed, can anyone please guide the right way to perform this task.
Thanks in Advance
peer node rollback -c mychannel -b 150
Note: The above-said command should be executed from the peer node, not from the CLI
Error: as another peer node command is executing, wait for that command to complete its execution or terminate it before retrying: lock is already acquired on file /var/hyperledger/production/ledgersData/fileLock
Please make sure that peer is offline when you are performing tasks such as
peer node reset
peer node rollback
Please note that rollback doest mean it delete the blocks permanently, after the rollback operation performed peer will receive blocks from the orderer or other peers
I have found the solution as follow:
First network was up and running, I have added following command in docker compose file for required peer lets say peer0.org1.example.com,
command: peer node rollback -c mychannel -b 1 && peer node start
After saving the changes run following command
docker-compose -f docker-compose-cli.yaml up -d peer0.org1.example.com
Now remove rollback part from above command, I can see logs show that it has been rollback successfully.
docker logs peer0.org1.example.com

Not able to install Commercial paper chaincode which is shown in documentation

docker exec cliMagnetoCorp peer chaincode install -n papercontract -v 0 -p /opt/gopath/src/github.com/contract -l node .
above line is mentioned in the fabric documentation https://hyperledger-fabric.readthedocs.io/en/release-1.4/tutorial/commercial_paper.html
when i run this then its giving below error
Error: Error endorsing chaincode: rpc error: code = Unknown desc =
chaincode error (status: 500, message: Error installing chaincode code
papercontract:0(chaincode
/var/hyperledger/production/chaincodes/papercontract.0 exists))
my question is how does /opt/gopath/src/github.com/contract come from in your documentation. its never mentioned anywhere.
Moreover,
./../../../../organization/magnetocorp:/opt/gopath/src/github.com/
its written in docker-composer.yml. how /opt path is related and connected here ?

Error - chaincode exists

I'm getting this error when trying to start running my chaincode:
Command: composer network start -c adminCardLessor -n block-aviation-network -V 0.0.1 -A admin -C ./credentials/lessor/admin-pub.pem -f delete_me.card
Error: Error trying to start business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: chaincode exists block-aviation-network)
I successfully installed my chaincode on each of my peers but can seem to start it due to the above error...
Does anyone have any experience with this error or how to resolve it?
Because the chaincode already exists on the network, you can only upgrade it, because I am assuming the network is not starting because you made some changes. Look toward questions such as How to upgrade a chaincode after modification? and then try starting the network. This should solve your problem.

Resources