1

On instantiating the chaincode without specifying the endorsement policy, invocation of functions in chaincode work fine and stored data can be seen on couchdb database. But on explicitly specifying endorsement policy as "AND ('mohaMSP.peer','ecMSP.peer')" during instantiation of chaincode, the invocation of chaincode functions don't show any error, but do not update the couchdb state database. So I checked the logs on peer0.moha.nid.com and it showed the following error:

2019-01-29 09:46:00.851 UTC [valimpl] preprocessProtoBlock -> WARN cac6 Channel [nid-channel]: Block [7] Transaction index [0] TxId [bfed301afcaae5ad2ee8885c3cdbd39521827b25cabe92d6cf03f931da4ea391] marked as invalid by committer. Reason code [ENDORSEMENT_POLICY_FAILURE]

I have installed the chaincode on peer0.ec.nid.com and peer0.moha.nid.com (i.e. in both organizations) and verified the installation as well. There are three peers joined to the nid-channel - peer0.moha.nid.com, peer1.moha.nid.com, peer0.ec.nid.com as shown by peer channel list command.

here is docker-compose.yaml file to start the network

here is docker-compose-base.yaml file

here is peer-base.yaml file

I am running fabric 1.2.1 containers and have tagged them as latest.

Chaincode instantiation command:

peer chaincode instantiate -o orderer.nid.com:7050 -n car_reg -v 1 -C nid-channel -c '{"Args":[]}' -P "AND ('ecMSP.peer','mohaMSP.peer')"
Bukks
  • 408
  • 7
  • 16
  • which command are you using for invoking? – Harshit Jan 30 '19 at 05:20
  • peer chaincode invoke -o orderer.nid.com:7050 -C nid-channel -n car_reg -c '{"Args":["createCar","1","bmw","gtx","blue","me"]}' – Bukks Jan 30 '19 at 07:00
  • 1
    while using 'AND' try using command - peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:7051 -c '{"Args":["invoke","...."]}' – Harshit Jan 30 '19 at 07:08
  • yes you have to, if you specify 'AND' policy you have to give the endorsing peers in the command. Check BYFN we have specified --peeradd there too during invoke – Harshit Jan 30 '19 at 07:21
  • 1
    @Harshit Yes I had overlooked it. Now it's working. Thanks – Bukks Jan 30 '19 at 07:23

3 Answers3

2

I was missing the --peerAddresses arguments during invocation of chaincode function. Now it's solved. Thanks to @Harshit 's comment

peer chaincode invoke -o orderer.nid.com:7050 -C nid-channel -n car_reg --peerAddresses peer0.moha.nid.com:7051 --peerAddresses peer0.ec.nid.com:7051 -c '{"Args":["createCar","1","bmw","tx","blue","me"]}'
Bukks
  • 408
  • 7
  • 16
0
  1. If you did not specify endorsement policy during instantiation, the endorsement policy defaults to “any member of the organizations in the channel”. i.e) "OR ('mohaMSP.member','ecMSP.member')"

  2. When you specify endorsement policy "AND ('mohaMSP.peer','ecMSP.peer')" explicitly, it requests one signature from each Org (mohaMSP, ecMSP) peers. So check whether both Org has endorsing peers..

For more info, setting-chaincode-level-endorsement-policies

Muthu Thavamani
  • 1,325
  • 9
  • 19
  • Yes both orgs have chaincode installed on one of their peers. I think I have made some error on yaml files but even on inspecting them many times, I can't find the error – Bukks Jan 29 '19 at 11:30
0

Try this:

-P "AND ('ecMSP.member','mohaMSP.member')"

Maybe your peers has not the "peer" role.

Check this documentation: Endorsement policy Identity Classification

Alexander Yammine
  • 548
  • 1
  • 5
  • 14