Deploying Chaincode to Hyperledger Fabric does not work - hyperledger-fabric

I tried to deploy a custom chaincode to my hyperledger test network. Therefore, I used the tutorial from https://www.youtube.com/watch?v=KFf1qzYP-bA&t=1380s and https://hyperledger-fabric.readthedocs.io/en/release-2.3/deploy_chaincode.html.
Following the tutorials, first I thought the process was successful, but in the end I was running into errors. Here are the steps I did:
peer lifecycle chaincode install newchaincode.tar.gz
And got:
2021-06-20 16:41:18.750 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nLnewchaincode:a52b26224459812b50d72da7fc0644ff2b2c540bd656bbf457a235bca15b3a57\022\013newchaincode" >
2021-06-20 16:41:18.750 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: newchaincode:a52b26224459812b50d72da7fc0644ff2b2c540bd656bbf457a235bca15b3a57
Also checking if the chaincode was installed worked out:
peer lifecycle chaincode queryinstalled
Package ID: newchaincode:a52b26224459812b50d72da7fc0644ff2b2c540bd656bbf457a235bca15b3a57, Label: newchaincode
After that I exported the CC_Package_ID and also set the approve formyorg for both organizations:
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID newchannel --name newchaincode --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
ClientWait -> INFO 001 txid [e2dfcfc6b5218423878132af6f34ebbef25cd793b258581900b21e1fcca98b63] committed with status (VALID) at localhost:7051
Then checking for commitreadiness:
peer lifecycle chaincode checkcommitreadiness --channelID newchannel --name newchaincode --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
{
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
Then I committed my chaincode:
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID newchannel --name newchaincode --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
2021-06-20 16:48:24.990 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [9336b174e344fb5fd977778e7365da0841b3285eff8c0fa13f6d3f03248442e5] committed with status (VALID) at localhost:9051
2021-06-20 16:48:24.993 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [9336b174e344fb5fd977778e7365da0841b3285eff8c0fa13f6d3f03248442e5] committed with status (VALID) at localhost:7051
And finally, checked if I committed correctly:
peer lifecycle chaincode querycommitted --channelID newchannel --name newchaincode --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Committed chaincode definition for chaincode 'newchaincode' on channel 'newchannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
So - I thought the chaincode installation was successful, but when I'm trying to invoke the CC I got this:
Error: endorsement failure during invoke. response: status:500 message:"make sure the chaincode newchaincode has been successfully defined on channel newchannel and try again: chaincode newchaincode not found"
Furthermore, when I'm calling docker ps there is no chaincode running.

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

"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

why is byfn just invoked on two peers (hyperledger fabric)?

I saw in byfn that just two peers are used for the code invocation but we have four peers in the network. Why are just two used?
./byfn.md:+ peer chaincode invoke -o orderer.example.com:7050 --tls true --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 mychannel -n mycc --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":["invoke","a","b","10"]}'
./byfn.md:2019-11-24 08:01:03.051 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
./byfn.md:===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
Because peer0 and peer1 for org1 are actually the same.
They share a gossip protocol and they share the same ledger in the form of a local copy.
Querying and invoking peer0 will get the same output as querying and invoking peer1.
This for org1, but same for org2.
You can for sure invoke all peers and see that you will get the same results.

Instantiation of signed chaincode packages in Hyperledger Fabric

I am trying to apply the packaging method for the chaincode which enables me to enforce signatures from multiple organizations and make sure that chaincode cannot be effectively instantiated if signatures from relevant participants in the channel are not collected.
a) From Org1 context:
# peer chaincode package -n mycc -p github.com/chaincode/chaincode_example02/go/ -v 1 -s -S -i "AND('Org1.admin','Org2.admin')" ccpack.out
2018-12-03 22:49:46.032 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-12-03 22:49:46.032 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
root#bdc554f0a918:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode signpackage ccpack.out signedccpack.out
Wrote signed package to signedccpack.out successfully
root#bdc554f0a918:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install signedccpack.out
2018-12-03 22:50:21.125 UTC [chaincodeCmd] install -> INFO 001 Installed remotely response:<status:200 payload:"OK" >
b) From Org2 context:
root#bdc554f0a918:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode signpackage ccpack.out signedccpack.out
Wrote signed package to signedccpack.out successfully
root#bdc554f0a918:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install signedccpack.out
2018-12-03 22:50:32.414 UTC [chaincodeCmd] install -> INFO 001 Installed remotely response:<status:200 payload:"OK" >
c) From either Org context:
root#bdc554f0a918:/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 channel1 -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
2018-12-03 22:50:42.946 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-12-03 22:50:42.950 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg cannot get package for chaincode (mycc:1.0)
d) The chaincode is present on Org1 Peer 1:
root#af99b3698322:/var/hyperledger/production/chaincodes# ls
mycc.1
e) The chaincode is present on Org2 Peer 1:
root#2fd1355259a8:/var/hyperledger/production/chaincodes# ls
mycc.1
Any recommendations as to the process or the cli syntax structure would be greatly appreciated.

Resources