How to list chaincode? - hyperledger-fabric

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.

Related

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

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

Hyperledger fabric 1.4 Error on Instantiate chaincode

Setting up Built Your First Network (BYFN), after creating and joining Channel, chaincode is installed on both organization peers using following cli command -
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
Chaincode Installation is successful.
While I tried to Instantiate chaincode from the CLI using following command given by HLF document.
The following error occurred while Instantiate the chaincode in Hyperledger fabric v 1.4.
root#8804d95b7083:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -o orderer.example.com:7050 --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 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
Error: must supply value for chaincode name parameter
Usage:
peer chaincode instantiate [flags]
Flags:
-C, --channelID string The channel on which this command should be executed
--collections-config string The fully qualified path to the collection JSON file including the file name
Is there any alternative way to resolve this error other than re-setup the Network?
There is a conflict with the CLI command there. You used go cli command for installing the chaincode and NodeJS cli command for instantiating the chaincode.

Endorsement policy in Hyperledger Fabric

I am using Hyperledger Fabric version 1.2. I have created a channel with 1 orderer and 10 peer nodes, all belonging to the same organisation. I want to instantiate the chaincode with the endorsement policy such that all the peers of ORG1 are the endorsing peer, not just 1. What is the valid expression for the same?
Currently using the following policy:
docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n chainname -v 1.0 -c '{"Args":[""]}' -P "AND('Org1MSP.member')"
Fabric documentation contains examples of including peers from different organisations.
This can be achived while invoking the chaincode. You have to pass the peer addresses of all the peer nodes who you want to act as endorsing peers
peer chaincode invoke -o orderer0.abc.com:7050 -C abcchannel -n fabcar --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer1.org1.example.com:7051 -c '{"Args":["initLedger"]}'
Unfortunately! there no valid command for that, you can follow two steps if you want to achieve this:
Write your own custom endorsement logic by a plugin. This method is little cumbersome and you can follow this link if you want to do that. Pluggable endorsement and validation logic
Or, you can have an alternate solution by creating 10 Orgs with 1 peer each and define the endorsement policy through the command that you want as:
-P "OutOf(10, 'Org1.peer', 'Org2.peer', ...., 'Org10.peer')"
But, having all the peers as an endorsing peer is never a good idea as if a peer goes down, you will have to face serious problems as no transaction will be committed

Modify existing endorsement policy (Hyperledger Fabric)

I had 2 organization in Hyperledger Fabric blockchain network initially. Recently I added one more organization on a different host using swarm. When I try to invoke chaincode from 1st or 2nd organization then it's working fine and I can see the updated transaction from org3. But when I invoke a transaction from org3, I am getting the following error.
"[2019-02-06 06:44:21.895] [ERROR] invoke - The transaction was
invalid, code = ENDORSEMENT_POLICY_FAILURE"
Initially, chaincode was initiated using the following policy.
-P "OR ('Org1MSP.peer','Org2MSP.peer')"
So I think I will have to update existing endorsement policy to include org3.
Could anyone help to modify existing endorsement policy or to resolve the issue?
The way to upgrade the chaincode is as followed:
Increment the version of ccRequest containing ccPackage
Re-Install the ccRequest on all orgs in the channel.
Ex: peer chaincode install -n mycc -v 2.0 -p github.com/chaincode/chaincode_example02/go/
Create new ccPolicy with correct rules containing required orgs as endorsers.
Upgrade the chaincode by running upgradeCC command
Ex: peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
Test with a query on chaincode with peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
For more details refer docs or ask on rockerchat
Yes, you can do that using peer chaincode upgrade command.
peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile
$ORDERER_CA -C mychannel -n mycc -v 1.2 -c
'{"Args":["init","a","100","b","200","c","300"]}' -P "AND
('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
refer : peer chaincode upgrade

ENDORSEMENT_POLICY_FAILURE when chaincode is invoked using node.js SDK

Steps followed:
1. Started a Hyperledger Fabric network with 1 organization,1 Peer,1
couch db and 1 CA
2. Created channel
docker exec command -e"CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
3. Joined peer to the channel using docker exec command
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin#org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block
4. Installed chaincode
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -v 1.0 -c '{"Args":[""]}' -P "AND ('Org1MSP.member','Org2MSP.member')"
5. Started the client
6. Used node SDK to enroll and register a user
7. Ran invoke.js [from fabcar example] to initledger with 10 cars
8. The invoke query throws ENDORSEMENT_POLICY_FAILURE error.Please note that endorsement policy is set as "AND" Image
Your endorsement policy requires a peer from Org1 and a peer from Org2 to endorse the transaction. Given you are only running a single peer from Org1, there is no way to satisfy this endorsement policy.
Try setting the endorsement policy to
-P "AND ('Org1MSP.member')"
or adding a peer from Org2 to the channel and install the chaincode.

Resources