peer chaincode instantiate -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 -l node -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'OR ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
while try to run my first network my program got hang here everytime
Related
I got problems during my invoke.
1.) I rund following command:
peer lifecycle chaincode querycommitted \
--channelID mychannel \
--name basic \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
--> till here everything worked well.
Than I wanted to invoke the chaincode:
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
-C mychannel \
-n basic \
--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 \
-c '{"function":"InitLedger","Args":[]}'
Afterwards I got the Error:
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: failed to execute transaction 93.....: could not launch chaincode basic_1.0:465......: chaincode registration failed: container exited with 1"
I tried the whole process serveral times, to make sure, that I do not have any mistakes before.
I also checked the dockers by docker ps , all are normal.
So I have no glue, what the source for the error could be.I will be happy about every help! Thank you!!!
Initially after committing the chaincode, init must be performed first. To execute init, you just need to specify --isInit in the invoke parameter option. See the documentation below.
fabric/peer/chaincode
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
-C mychannel \
-n basic \
--isInit \
--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 \
-c '{"function":"InitLedger","Args":[]}'
Am trying to add an org to existing channle and following the steps from https://hyperledger-fabric.readthedocs.io/en/release-1.4/channel_update_tutorial.html,
but at the final step for channel update
" peer channel update -f org3_update_in_envelope.pb -c $CHANNEL_NAME -o orderer.example.com:7050 --tls --cafile $ORDERER_CA"
It is failing with
"Error: Invalid channel create transaction : mismatched channel ID $CHANNEL_NAME != mychannel
"
does anyoe have idea about it.
I even check the CHANNEL_NAME vairable value and tried replacing $CHANNEL_NAME directly with mychannel as
" peer channel update -f org3_update_in_envelope.pb -c mychannel -o orderer.example.com:7050 --tls --cafile $ORDERER_CA"
But same error
Found the reason,
The step to create envelope for "org3_update.json" and adding header fields to form "org3_update_in_envelope.json" has the issue
echo '{"payload":{"header":{"channel_header":{"channel_id":"$CHANNEL_NAME", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
here the "channel_id":"$CHANNEL_NAME" is not taken as environment variable and is actually consider as value , that's why "org3_update_in_envelope.json" file gets header "$CHANNEL_NAME" entry and not the actually channel name as mychannel
To fix it, add a single quotes around the variable like this:
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL_NAME'", "type":2}},"data":{"config_update":'$(cat org3_update.json)'}}}' | jq . > org3_update_in_envelope.json
reference this change.
root#27e4f0c27a0e:/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 myChannel -n marbles -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')"
2018-10-01 05:46:15.704 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-10-01 05:46:15.704 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
root#27e4f0c27a0e:/opt/gopath/src/github.com/hyperledger/fabric/peer#
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 myChannel -n marbles -c '{"Args":["initMarble","marble1","blue","35","tom"]}'
Error: endorsement failure during invoke. chaincode result:
Add sleep 20 into the starting of your chaincodeInvoke function on scripts/utils.sh line no 297
I am experimenting with changing the fabric chaincode endorsement policy from OR to AND. When the endorsement policy is OR, everything works fine and the balances are updated. After I have switched the endorsement policy to AND and recreate all containers, the balances are not updated anymore. In the peer0 org1 container, I see the following warnings and errors. Similar errors are found in peer0 org2 container too.
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]
The only thing I have changed is the policy part of the peer chaincode instantiate command: -P "AND ('Org1MSP.member','Org2MSP.member')"
Are there other configurations or commands need to be changed? Thank You!
cd to the first-network directory and execute the following commands:
../../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
Get into the cli container and execute the following commands:
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.
That makes sense, because the peer CLI (peer chaincode *, peer channel *, etc. etc.) binary can only collect an endorsement from a single peer.
When you define CORE_PEER_ADDRESS it basically tells the peer CLI, which peer it should contact.
An endorsment policy that has an AND, obviously needs more than 1 peer, so that's why the transactions fail...
I am new to hyperledger and is going through the example here . I am tried to play around the chaincode but is now stuck at the part where I am suppose to upgrade the chaincode
I have tried to execute the peer chaincode upgrade within the docker peer node:
peer chaincode upgrade -n tuna-app -p github.com/tuna-app
but end up with the error
Error getting (testchainid) orderer endpoint: Error endorsing GetConfigBlock: rpc error: code = Unknown desc = chaincode error (status: 500, message: "GetConfigBlock" request failed authorization check for channel [testchainid]: [Failed to get policy manager for channel [testchainid]])
You need to specify the channel name for which you'd like to upgrade the chaincode, also need to specify args and new version. Moreover you have to specify the ordering service endpoints so peer cli will be able to submit the upgrade transaction:
peer chaincode upgrade -n tuna-app -v 2.0 \
-c '{"Args":[""]}' \
-p github.com/tuna-app -C mychannel \
-o orderer:7051
You can find more here.
Here you have some basic script in bash:
#!/bin/bash
PRV_VERSION='v2';
VERSION='v3';
CONTAINER_IDS=$(docker ps -a | grep "mycc-$PRV_VERSION" | awk '{print $1}')
docker rm -f $CONTAINER_IDS
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" peer0.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" peer1.org1.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" peer0.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" peer1.org2.example.com \
peer chaincode install \
-n mycc \
-v $VERSION \
-p /etc/hyperledger/chaincode \
-l node;
sleep 10;
ORDERER_CA=/etc/hyperledger/organizations/users/Admin#example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org1.example.com/msp" \
peer0.org1.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
ORDERER_CA=/etc/hyperledger/organizations/users/Admin#example.com/msp/tlscacerts/tlsca.example.com-cert.pem
docker exec -e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/users/Admin#org2.example.com/msp" \
peer0.org2.example.com \
peer chaincode upgrade \
-o orderer.example.com:7050 --tls --cafile $ORDERER_CA \
-C mychannel \
-n mycc \
-v $VERSION \
-c '{"Args":[""]}' \
-p /etc/hyperledger/chaincode
You need of course share some certs to your peer0.org1 and of course the chaincode itself (in js or go), here you have some docker-compose.yml part:
peer0.org1.example.com:
container_name: peer0.org1.example.com
extends:
file: base.yaml
service: peer-base
environment:
- CORE_PEER_ID=peer0.org1.example.com
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
ports:
- 7051:7051
- 7053:7053
volumes:
- ./channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/:/etc/hyperledger/crypto/peer
- ./channel/crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/peer/users
- ./channel/crypto-config/ordererOrganizations/example.com/users:/etc/hyperledger/organizations/users
- ./src/github.com/example_cc/node:/etc/hyperledger/chaincode
Then you can check the logs by:
docker logs dev-peer0.org1.example.com-mycc-v3 -f
I need to say, that upgrading chaincode in development take the same amount of time as just recreate whole blockchain (without pulling new images - this should be removed from ./runApp.sh script).