Hyperledger fabric 2.0 : Chaincode commit fails with the error ' chaincode definition not agreed to by this org'

Viewed 1918

I am trying to learn HLF 2.0 chaincode lifecycle, my network configuration as follows

  1. Two orgs with one peer each
  2. RAFT as ordering service(total 3 orderes)

Following the official doc to install the chaincode https://hyperledger-fabric.readthedocs.io/en/release-2.0/deploy_chaincode.html

when I try to commit the chaincode getting the following error

Error: proposal failed with status: 500 - failed to invoke backing implementation of 'CommitChaincodeDefinition': chaincode definition not agreed to by this org (LeftOrgMSP)

however when i check the commitreadyness

{
    "approvals": {
        "LeftOrgMSP": true,
        "RightOrgMSP": false
    }
}

i got the LeftOrgMSP as true

UPDATE

command for approving org

peer lifecycle chaincode approveformyorg -o  orderer1.base.order:7050 --channelID basechannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls \
--cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/base.order/orderers/orderer1.base.order/msp/tlscacerts/tlsca.base.order-cert.pem

command to commit

peer lifecycle chaincode commit -o orderer1.base.order:7050 --channelID basechannel \
 --name fabcar --version 1.0 \
 --sequence 1  --tls true \
 --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/base.order/orderers/orderer1.base.order/msp/tlscacerts/tlsca.base.order-cert.pem \
 --peerAddresses peer1.base.left:7051  \
 --tlsRootCertFiles   /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/base.left/peers/peer1.base.left/tls/ca.crt
1 Answers

The overall process to deploy chaincode is 4 steps:

  1. Package the chaincode
  2. Install it on your org peers - in your case LeftOrg and RightOrg
  3. Approve the chaincode definition for your organization, and
  4. Commit the chaincode definition to your channel.

Install - When you installed the chaincode, did you install it on both orgs? If so, a successful install will return the package identifier (ID), which is a combination of the package label (fabcar_X), combined with a hash of the chaincode package. I am assuming that's what you have stored in $CC_PACKAGE_ID, confirm if the value is accurate.

After a successful install, query the peer for installed chaincodes to see if the result matches. The cmd is:

peer lifecycle chaincode queryinstalled

Approve & Check Commit Readyness - The purpose of Commit Readyness is to help you verify that enough channel members have approved a chaincode definition to meet the endorsement policy (a majority by default) before the definition can be committed to a channel. It looks like you've only approved the chaincode for LeftOrg, you still need to approve it for the RightOrg (Although your log message seems to say otherwise, so there might be more to it). I would execute the approve for RightOrg and then check commit readiness on both orgs to confirm.

Follow that up with commit

And, if the commit was successful, confirm that the definition committed successfully on both orgs with

peer lifecycle chaincode querycommitted

I have a blog on medium on chaincode deployment if you want more information.

Related