在将认可策略从OR切换到AND之后,构建您的第一个网络示例不会更新余额

时间:2018-02-15 20:23:13

标签: hyperledger-fabric hyperledger

我正在尝试将面料链码代言政策从OR更改为AND。当认可政策是OR时,一切正常并且余额会更新。在我将认可策略切换到AND并重新创建所有容器后,余额不再更新。在peer0 org1容器中,我看到以下警告和错误。在peer0 org2容器中也发现了类似的错误。

2018-02-15 20:08:11.778 UTC [vscc] Invoke -> WARN 8d4 Endorsement policy failure for transaction txid=2742f25b173374674c6f9796fe11d8ad37bc52fe332ffa420fa04a272b67d927, err: Failed to authenticate policy
2018-02-15 20:08:11.779 UTC [txvalidator] VSCCValidateTxForCC -> ERRO 8de VSCC check failed for transaction txid=2742f25b173374674c6f9796fe11d8ad37bc52fe332ffa420fa04a272b67d927, error VSCC error: policy evaluation failed, err Failed to authenticate policy
2018-02-15 20:08:11.779 UTC [txvalidator] validateTx -> ERRO 8e2 VSCCValidateTx for transaction txId = 2742f25b173374674c6f9796fe11d8ad37bc52fe332ffa420fa04a272b67d927 returned error VSCC error: policy evaluation failed, err Failed to authenticate policy
2018-02-15 20:08:11.780 UTC [valimpl] preprocessProtoBlock -> WARN 8ea Block [4] Transaction index [0] marked as invalid by committer. Reason code [10]

我唯一改变的是peer chaincode instantiate命令的策略部分:-P" AND(' Org1MSP.member',' Org2MSP.member') "

是否需要更改其他配置或命令?谢谢!

cd到第一个网络目录并执行以下命令:

../../bin/cryptogen generate --config=./crypto-config.yaml
export FABRIC_CFG_PATH=$PWD
../../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
export CHANNEL_NAME=mychannel  && ../../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
../../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
../../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml up -d

进入cli容器并执行以下命令:

docker exec -it cli bash
export CHANNEL_NAME=mychannel
echo $CHANNEL_NAME
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --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
peer channel join -b mychannel.block
CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CHANNEL_NAME=mychannel peer channel join -b mychannel.block
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --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
CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CHANNEL_NAME=mychannel peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --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
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CHANNEL_NAME=mychannel peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
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.member','Org2MSP.member')"
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'  #this shows 100 as expected
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","b"]}'  #this shows 200 as expected
peer chaincode invoke -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 -c '{"Args":["invoke","a","b","10"]}'
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'  #this still shows 100 and is not changed.
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","b"]}'  #this still shows 200 and is not changed.

1 个答案:

答案 0 :(得分:1)

这是有道理的,因为对等CLI(对等链代码*,对等通道*等等)二进制文件只能收集来自单个对等方的认可。

当您定义CORE_PEER_ADDRESS时,它基本上告诉对等CLI,它应该联系哪个对等体。

具有AND的认可政策,显然需要超过1个同行,这就是交易失败的原因......