"chaincode definition for 'fabcar' exists, but chaincode is not installed" Error when i try to invoke chaincode in HLF2.3 - hyperledger-fabric

I'm following this tutorial — https://kctheservant.medium.com/multi-host-deployment-for-first-network-hyperledger-fabric-v2-273b794ff3d.
I've successfully installed, approved and committed chaincode on both peers.
These are installed chaincodes on host1 and host2 respectively:
Installed chaincodes on peer:
Package ID: fabcar_1:7ed63d49b5b7ff8f8f17cf3106975e1b731b3d1f7c417ef050a24315ef828085, Label: fabcar_1
Package ID: fabcar_1:a8fdf3e70eaa79c8481356484661fe3c763b5fc744ca82c8c564ece77a83cf8b, Label: fabcar_1
Package ID: fabcar_1:cd4f25953c7b04623652da137067c386062bf1b9a6de0e710c72f11e81c7ea0c, Label: fabcar_1
Installed chaincodes on peer:
Package ID: fabcar_1:7ed63d49b5b7ff8f8f17cf3106975e1b731b3d1f7c417ef050a24315ef828085, Label: fabcar_1
Also commit status of peers:
Committed chaincode definition for chaincode 'fabcar' on channel 'mychannel':
Version: 1, Sequence: 2, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
And so when I try to invoke chaincode with
docker exec cli peer chaincode invoke -o orderer3.example.com:9050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer3.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n fabcar --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["initLedger"]}'
I get such error:
Error: endorsement failure during invoke. response: status:500 message:"make sure the chaincode fabcar has been successfully defined on channel mychannel and try again: chaincode definition for 'fabcar' exists, but chaincode is not installed"
CORE_PEER_GOSSIP_USELEADERELECTION is set to true if it'll help.
Nodes are running in docker.
Any help would be greatly appreciated.

I've experience the same issue and it was due to using the wrong --package-id when approving the chain-code.
More info here

Just write docker ps -a. and check the chaincode logs. clean solution

Related

Chaincode definition not agreed to by this org (Org1MSP)

When I try to run the following command to commit the chaincode,
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID testchannel --name property --peerAddresses localhost:7051 --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE_ORG1 --peerAddresses localhost:9051 --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE_ORG2 --version 1.0 --sequence 1 --init-required
I encountered the error as follows even though the org1 approved the chaincode definition,
Error: proposal failed with status: 500 - failed to invoke backing implementation of 'CommitChaincodeDefinition': chaincode definition not agreed to by this org (Org1MSP)
Error Screenshot
I've attached a screenshot of the error.
Both organizations approved the chaincode definition by returning 'true' in this scenario. It still encounters the error "chaincode definition not agreed to by this org (Org1MSP)" after that.
How can I rectify from this?
The checkcommitreadiness uses a contract called product whereas the commit uses a contract called property.

Getting "ENDORSEMENT_POLICY_FAILURE" as Validation Code in Hyperledger Explorer for every transaction / block

I Have two Orgs in My Network. I have Created a channel deployed the chaincode on both Orgs (Org1 and Org2) and received code as VALID.
Chaincode approved by both Orgs, Checked committed readiness and Committed the chaincode. log goes like...
2021-10-04 14:30:52.864 IST [chaincodeCmd] ClientWait -> INFO 001 txid [eff4729bb0fcb0ac21b6b4c4ee78de75d9fc3bc04b67fdd1cc22c9b67044d93a] committed with status (VALID) at localhost:9051
2021-10-04 14:30:52.911 IST [chaincodeCmd] ClientWait -> INFO 002 txid [eff4729bb0fcb0ac21b6b4c4ee78de75d9fc3bc04b67fdd1cc22c9b67044d93a] committed with status (VALID) at localhost:7051
=============== Commit chaincode definition Org 1 ============================== Committed chaincode definition for chaincode 'sample' on channel 'samplechannel': Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
=============== query commited from Org 1====================`` Committed chaincode definition for chaincode 'sample' on channel 'samplechannel': Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
I have gone through similiar issues posted and added
BlockValidation: Type: ImplicitMeta Rule: "ANY Writers" in my configtx.yaml
Transaction gets executed without any error. able to view transaction hash.
But getting ENDORSEMENT_POLICY_FAILURE in explorer.
I have added sceenshots below.
Can any one please help what is wrong / needs to be changed here ?
Thanks in advance.
Image for reference -
ENDORSEMENT_POLICY_FAILURE
Chaincode deployment
The default endorsement policy is MAJORITY. It means your transaction to be validated by a majority of channel members.
To change the endorsement policy, you can specify Channel/Application/Endorsement in configtx.yaml to ANY Endorsement. Fabric will use this config as the default endorsement policy in all chaincode.
Or you can specify the policy for each chaincode by define it when approve & commit chaincode. For example:
peer lifecycle chaincode approveformyorg --channelID mychannel --signature-policy "OR('Org1.member', 'Org2.member')" --name mycc --version 1.0 --package-id mycc_1:3a8c52d70c36313cfebbaf09d8616e7a6318ababa01c7cbe40603c373bcfe173 --sequence 1 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --waitForEvent
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --signature-policy "OR('Org1.member', 'Org2.member')" --name mycc --version 1.0 --sequence 1 --init-required --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --waitForEvent --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
See more in Hyperledger Fabric documentation

How to list chaincode?

I'm able to follow https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html
$ peer chaincode invoke ... -c '{"function":"InitLedger","Args":[]}'
2021-08-23 17:52:59.534 PST [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
I leanred peer chaincode list can list chaincodes, but the following commands don't give expected result.
$ peer chaincode list -C mychannel --installed
Get installed chaincodes on peer:
$ peer chaincode list -C mychannel --instantiated
Get instantiated chaincodes on channel mychannel:
Given I've successfully deployed the basic chaincode, how do I see it through peer chaincode list?
I think issue, will be with the path that is getting set. Make sure to export the following peer path where chaincode is installed :-
FABRIC_LOGGING_SPEC
CORE_PEER_MSPCONFIGPATH
CORE_PEER_LISTENADDRESS
CORE_PEER_LOCALMSPDIR
If tls is enabled, export the following path along with the paths above
CORE_PEER_TLS_ENABLED
CORE_PEER_TLS_KEY_FILE
CORE_PEER_TLS_CERT_FILE
CORE_PEER_TLS_ROOTCERT_FILE
And then try the commands
peer chaincode list --installed
peer chaincode list --instantiated -C mychannel
If you want to just view the installed chaincode below is the command for the HLF2.2x
peer lifecycle chaincode queryinstalled --peerAddresses localhost:7051
--tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE
If you want to view the commited chaincode list below is the command
peer lifecycle chaincode querycommitted --channelID channelName
in HLF2.2x chaincode lifecycle is introduced. So if you want to execute chaincode you need to approve and commit after installed on peer.

What is the meaning of “peer chaincode install -p" in Hyperledger Fabric?

I passed "first-network", no problem.
In CLI:/opt/gopath/src/github.com/hyperledger/fabric/peer:, execute these commands:
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND('Org1MSP.peer','Org2MSP.peer')"
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}' --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
There are no problem. But when I execute these commands in the subdirectory of the peer /opt/gopath/src/github.com/hyperledger/fabric/peer/scripts:, install、instantiate and query success, but invoke error:
Error: endorsement failure during invoke. response: status:500 message:"cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory".
This happens when CLI connects to peer0.ogr1, but I find this file at peer0.ogr1:
enter image description here
I replaced the peer node through the CLI, and the same problem occurred under the same path.
The problem may arise from the path specified by chaincode install -p. The official document says that this is a path relative to $GOPATH/src, so I feel that this path should have nothing to do with the current directory.
After searching, I found two similar problems, but the reasons are completely different and cannot be used for reference. Therefore, I can only raise new problems and hope to find solutions.
two similar problems:
Install a different version of chaincode (Hyperledger fabic)
Hyperledger Fabric - How to limit Org2 to install/instantiate/upgrade the chaincode to the channel?
version: Fabric1.4.4, Ubuntu18.04
structure: one order, four peers, each distributed on five machines, there is no problem with normal transactions

Error trying to instantiate composer runtime. Error: No valid responses from any peers. for Multi organization hyperledger fabric 1.1

I am trying to setup hyperledger fabric + composer setup with multi organizations locally. The steps I followed to setup hyperledger network is below.
Generate crypto materials and channel
cryptogen generate --config=./crypto-config.yaml configtxgen -profile
OrdererGenesis -outputBlock ./channel-artifacts/genesis.block
configtxgen -profile Channel -CreateChannelTx
./channel-artifacts/channel.tx -channelID ehrchannel
configtxgen -profile Channel -outputAnchorPeersUpdate ./channel-artifacts/Hospital1MSPanchors.tx -channelID ehrchannel -asOrg Hospital1MSP
configtxgen -profile Channel -outputAnchorPeersUpdate ./channel-artifacts/Hospital2MSPanchors.tx -channelID ehrchannel -asOrg Hospital2MSP
Start docker containors for two organisations
Execute Below commands on cli containor
peer channel create -o orderer.ehr.com:7050 -c ehrchannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/ehr.com/orderers/orderer.ehr.com/msp/tlscacerts/tlsca.ehr.com-cert.pem
Having all peers join the channel with setting appropriate env veriables
- peer channel join -b ehrchannel.block
Updating anchor peers for two organisations by setting env variables
peer channel update -o orderer.ehr.com:7050 -c ehrchannel -f ./channel-artifacts/Hospital1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/ehr.com/orderers/orderer.ehr.com/msp/tlscacerts/tlsca.ehr.com-cert.pem
After that I have followed Hyperledger composer document to configure composer.
But on step 17 on the doc, I am getting an error
composer network start -c PeerAdmin#ehr-network-hos1 -a marbles-network.bna -o endorsementPolicyFile=/tmp/composer/endorsement-policy.json -A admin1 -C admin2/admin-pub.pem -A admin2 -C admin2/admin-pub.pem
Starting business network from archive: marbles-network.bna
Business network definition:
Identifier: marbles-network#0.1.14
Description: Marble Trading Network
Processing these Network Admins:
userName: admin1
userName: admin2
✖ Starting business network definition. This may take a minute...
Error: Error trying to instantiate composer runtime. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: cannot get package for chaincode (marbles-network:0.18.2))
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: cannot get package for chaincode (marbles-network:0.18.2))
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: cannot get package for chaincode (marbles-network:0.18.2))
Response from attempted peer comms was an error: Error: 2 UNKNOWN: chaincode error (status: 500, message: cannot get package for chaincode (marbles-network:0.18.2))
Command failed
What are the potential issues? Thank you so much in advance.
What versions of Composer and Fabric are you using ? If you are using Composer v0.18.2 you need to have the GA version of Fabric v1.1.
The releases document for Composer details the compatible versions of Composer and Fabric. https://github.com/hyperledger/composer/releases
Also you might have a typo in your command ... -A admin1 -C admin2/admin-pub.pem -A admin2 -C admin2/admin-pub.pem are you specifying the wrong folder for admin1 ?
Check fabric node logs to find clue:
docker logs [orderer/peer/...]

Resources