fabric提交链码时报错:Error: transaction invalidated with status (ENDORSEMENT_POLICY_FAILURE)
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name oilcc --version 1.0 --sequence 1 --init-required --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 --peerAddresses peer0.department1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/department1.example.com/peers/peer0.department1.example.com/tls/ca.crt
报错说得很明白,department2节点没有进行背书。
先查询一下链码定义是否已经被所有组织批准: peer lifecycle chaincode queryapproved --channelID mychannel --name oilcc --sequence 1 --output json
两个组织都为true,说明问题应该不是出在背书策略上。
返回去查看commit命令,发现该命令只写了一个department1组织,但该网络中一共有两个组织,必须所有的组织都进行提交才能将链码正常运行在fabric通道中。结合报错的大意:department1提交成功,但department2缺少相应背书策略。
补上另一个组织department2:
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name oilcc --version 1.0 --sequence 1 --init-required --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 --peerAddresses peer0.department1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/department1.example.com/peers/peer0.department1.example.com/tls/ca.crt --peerAddresses peer0.department2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/department2.example.com/peers/peer0.department2.example.com/tls/ca.crt
提交成功: