From 41dca99e5a40ad4762ef2d822fa9457c0decf384 Mon Sep 17 00:00:00 2001 From: NIKHIL E GUPTA Date: Tue, 9 Apr 2019 16:55:56 -0400 Subject: [PATCH] [FAB-15127] Update high throughput sample Update high throughput sample scripts for chaincode lifecycle Change-Id: I8e7f9d98bb62d75a779e2767b0e165a36a700d43 Signed-off-by: NIKHIL E GUPTA --- high-throughput/README.md | 12 +-- .../scripts/approve-commit-chaincode.sh | 43 +++++++++++ high-throughput/scripts/channel-setup.sh | 7 +- high-throughput/scripts/install-chaincode.sh | 21 +++-- .../scripts/instantiate-chaincode.sh | 9 --- high-throughput/scripts/query-status.sh | 76 +++++++++++++++++++ high-throughput/scripts/setclienv.sh | 2 + high-throughput/scripts/update-invoke.sh | 2 - high-throughput/scripts/upgrade-chaincode.sh | 9 --- 9 files changed, 144 insertions(+), 37 deletions(-) create mode 100755 high-throughput/scripts/approve-commit-chaincode.sh delete mode 100755 high-throughput/scripts/instantiate-chaincode.sh create mode 100755 high-throughput/scripts/query-status.sh delete mode 100755 high-throughput/scripts/upgrade-chaincode.sh diff --git a/high-throughput/README.md b/high-throughput/README.md index 8ce49eb67b..ee84a83a74 100644 --- a/high-throughput/README.md +++ b/high-throughput/README.md @@ -120,15 +120,15 @@ and run some invocations are provided below. 4. Open a new terminal window and enter the CLI container using `docker exec -it cli bash`, all operations on the network will happen within this container from now on. -### Install and instantiate the chaincode +### Install and define the chaincode 1. Once you're in the CLI container run `cd scripts` to enter the `scripts` folder 2. Set-up the environment variables by running `source setclienv.sh` 3. Set-up your channels and anchor peers by running `./channel-setup.sh` -4. Install your chaincode by running `./install-chaincode.sh 1.0`. The only argument is a number representing the chaincode version, every time - you want to install and upgrade to a new chaincode version simply increment this value by 1 when running the command, e.g. `./install-chaincode.sh 2.0` -5. Instantiate your chaincode by running `./instantiate-chaincode.sh 1.0`. The version argument serves the same purpose as in `./install-chaincode.sh 1.0` - and should match the version of the chaincode you just installed. In the future, when upgrading the chaincode to a newer version, - `./upgrade-chaincode.sh 2.0` should be used instead of `./instantiate-chaincode.sh 1.0`. +4. Package and install your chaincode by running `./install-chaincode.sh 1`. The only argument is a number representing the chaincode version, every time + you want to install and upgrade to a new chaincode version simply increment this value by 1 when running the command, e.g. `./install-chaincode.sh 2` +5. Define your chaincode on the channel by running `./approve-commit-chaincode.sh 1`. The version argument serves the same purpose as in `./install-chaincode.sh 1` + and should match the version of the chaincode you just installed. This script also invokes the chaincode `Init` function to start the chaincode container. + You can also upgrade the chaincode to a newer version by running `./approve-commit-chaincode.sh 2`. 6. Your chaincode is now installed and ready to receive invocations ### Invoke the chaincode diff --git a/high-throughput/scripts/approve-commit-chaincode.sh b/high-throughput/scripts/approve-commit-chaincode.sh new file mode 100755 index 0000000000..081235826f --- /dev/null +++ b/high-throughput/scripts/approve-commit-chaincode.sh @@ -0,0 +1,43 @@ +# +# Copyright IBM Corp All Rights Reserved +# +# SPDX-License-Identifier: Apache-2.0 +# + + +echo "========== Query chaincode package ID ==========" +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +export CORE_PEER_LOCALMSPID="Org1MSP" +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +peer lifecycle chaincode queryinstalled >&log.txt +export PACKAGE_ID=`sed -n '/Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt` + +echo "========== Approve definition for Org1 ==========" +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +export CORE_PEER_LOCALMSPID="Org1MSP" +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +peer lifecycle chaincode install ${CC_NAME}.tar.gz + +peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --package-id ${PACKAGE_ID} --sequence $1 + +echo "========== Approve definition for Org2 ==========" +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 +export CORE_PEER_LOCALMSPID="Org2MSP" +export 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 +peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --package-id ${PACKAGE_ID} --sequence $1 + +. query-status.sh + +queryStatus $1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": true" +queryStatus $1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": true" + + +echo "========== Commit the definition the $CHANNEL_NAME ==========" +peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --sequence $1 --waitForEvent --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt + + +echo "========== Invoke the Init function ==========" +peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CC_NAME --isInit -c '{"Args":["Init"]}' diff --git a/high-throughput/scripts/channel-setup.sh b/high-throughput/scripts/channel-setup.sh index 2843ffe82a..376f468501 100755 --- a/high-throughput/scripts/channel-setup.sh +++ b/high-throughput/scripts/channel-setup.sh @@ -22,7 +22,7 @@ peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ../channel-a # peer1.org1 channel join echo "========== Joining peer1.org1.example.com to channel mychannel ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp -export CORE_PEER_ADDRESS=peer1.org1.example.com:7051 +export CORE_PEER_ADDRESS=peer1.org1.example.com:8051 export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt peer channel join -b ${CHANNEL_NAME}.block @@ -30,7 +30,7 @@ peer channel join -b ${CHANNEL_NAME}.block # peer0.org2 channel join echo "========== Joining peer0.org2.example.com to channel mychannel ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -export CORE_PEER_ADDRESS=peer0.org2.example.com:7051 +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt peer channel join -b ${CHANNEL_NAME}.block @@ -39,8 +39,7 @@ peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ../channel-a # peer1.org2 channel join echo "========== Joining peer1.org2.example.com to channel mychannel ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -export CORE_PEER_ADDRESS=peer1.org2.example.com:7051 +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt peer channel join -b ${CHANNEL_NAME}.block - diff --git a/high-throughput/scripts/install-chaincode.sh b/high-throughput/scripts/install-chaincode.sh index 8bd230b0b6..15f344d008 100755 --- a/high-throughput/scripts/install-chaincode.sh +++ b/high-throughput/scripts/install-chaincode.sh @@ -4,30 +4,37 @@ # SPDX-License-Identifier: Apache-2.0 # +echo "========== Package a chaincode on peer0.org1 ==========" +export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp +export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 +export CORE_PEER_LOCALMSPID="Org1MSP" +export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt +peer lifecycle chaincode package ${CC_NAME}.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/ --lang golang --label ${CC_NAME}_$1 + echo "========== Installing chaincode on peer0.org1 ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -peer chaincode install -n $CC_NAME -v $1 -p github.com/hyperledger/fabric-samples/chaincode +peer lifecycle chaincode install ${CC_NAME}.tar.gz echo "========== Installing chaincode on peer1.org1 ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp -export CORE_PEER_ADDRESS=peer1.org1.example.com:7051 +export CORE_PEER_ADDRESS=peer1.org1.example.com:8051 export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt -peer chaincode install -n $CC_NAME -v $1 -p github.com/hyperledger/fabric-samples/chaincode +peer lifecycle chaincode install ${CC_NAME}.tar.gz echo "========== Installing chaincode on peer0.org2 ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -export CORE_PEER_ADDRESS=peer0.org2.example.com:7051 +export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 export CORE_PEER_LOCALMSPID="Org2MSP" export 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 -peer chaincode install -n $CC_NAME -v $1 -p github.com/hyperledger/fabric-samples/chaincode +peer lifecycle chaincode install ${CC_NAME}.tar.gz echo "========== Installing chaincode on peer1.org2 ==========" export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -export CORE_PEER_ADDRESS=peer1.org2.example.com:7051 +export CORE_PEER_ADDRESS=peer1.org2.example.com:10051 export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt -peer chaincode install -n $CC_NAME -v $1 -p github.com/hyperledger/fabric-samples/chaincode +peer lifecycle chaincode install ${CC_NAME}.tar.gz diff --git a/high-throughput/scripts/instantiate-chaincode.sh b/high-throughput/scripts/instantiate-chaincode.sh deleted file mode 100755 index 25fe046c33..0000000000 --- a/high-throughput/scripts/instantiate-chaincode.sh +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright IBM Corp All Rights Reserved -# -# SPDX-License-Identifier: Apache-2.0 -# - -echo "========== Instantiating chaincode v$1 ==========" -peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CC_NAME -c '{"Args": []}' -v $1 -P "OR ('Org1MSP.member','Org2MSP.member')" - diff --git a/high-throughput/scripts/query-status.sh b/high-throughput/scripts/query-status.sh new file mode 100755 index 0000000000..d5592a81ef --- /dev/null +++ b/high-throughput/scripts/query-status.sh @@ -0,0 +1,76 @@ +# +# Copyright IBM Corp All Rights Reserved +# +# SPDX-License-Identifier: Apache-2.0 +# + +setGlobals() { + PEER=$1 + ORG=$2 + if [ $ORG -eq 1 ]; then + CORE_PEER_LOCALMSPID="Org1MSP" + CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt + CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp + if [ $PEER -eq 0 ]; then + CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + else + CORE_PEER_ADDRESS=peer1.org1.example.com:8051 + fi + elif [ $ORG -eq 2 ]; then + CORE_PEER_LOCALMSPID="Org2MSP" + 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 + CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp + if [ $PEER -eq 0 ]; then + CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + else + CORE_PEER_ADDRESS=peer1.org2.example.com:10051 + fi + + else + echo "================== ERROR !!! ORG Unknown ==================" + fi + + if [ "$VERBOSE" == "true" ]; then + env | grep CORE + fi +} + +queryStatus() { + VERSION=$1 + PEER=$2 + ORG=$3 + shift 3 + setGlobals $PEER $ORG + echo "===================== Querying approval status on peer${PEER}.org${ORG} ===================== " + local rc=1 + local starttime=$(date +%s) + + # continue to poll + # we either get a successful response, or reach TIMEOUT + while + test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0 + do + sleep $DELAY + echo "Attempting to Query approval status on peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs" + set -x + peer lifecycle chaincode queryapprovalstatus --channelID $CHANNEL_NAME --name $CC_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --version ${VERSION} --init-required --sequence ${VERSION} >&log.txt + res=$? + set +x + test $res -eq 0 || continue + let rc=0 + for var in "$@" + do + grep "$var" log.txt &>/dev/null || let rc=1 + done + done + echo + cat log.txt + if test $rc -eq 0; then + echo "===================== Query approval status successful on peer${PEER}.org${ORG} ===================== " + else + echo "!!!!!!!!!!!!!!! Query approval status result on peer${PEER}.org${ORG} is INVALID !!!!!!!!!!!!!!!!" + echo "================== ERROR !!! FAILED to execute End-2-End Scenario ==================" + echo + exit 1 + fi +} diff --git a/high-throughput/scripts/setclienv.sh b/high-throughput/scripts/setclienv.sh index 8e95350059..6193f753f1 100644 --- a/high-throughput/scripts/setclienv.sh +++ b/high-throughput/scripts/setclienv.sh @@ -6,3 +6,5 @@ export CHANNEL_NAME=mychannel export CC_NAME=bigdatacc +export TIMEOUT=10 +export DELAY=3 diff --git a/high-throughput/scripts/update-invoke.sh b/high-throughput/scripts/update-invoke.sh index d49b2ccc43..14ec2dbe83 100755 --- a/high-throughput/scripts/update-invoke.sh +++ b/high-throughput/scripts/update-invoke.sh @@ -3,6 +3,4 @@ # # SPDX-License-Identifier: Apache-2.0 # - peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CC_NAME -c '{"Args":["update","'$1'","'$2'","'$3'"]}' - diff --git a/high-throughput/scripts/upgrade-chaincode.sh b/high-throughput/scripts/upgrade-chaincode.sh deleted file mode 100755 index add1b8c73c..0000000000 --- a/high-throughput/scripts/upgrade-chaincode.sh +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright IBM Corp All Rights Reserved -# -# SPDX-License-Identifier: Apache-2.0 -# - -echo "========== Upgrade chaincode to version $1 ==========" -peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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 $CC_NAME -c '{"Args": []}' -v $1 -P "OR ('Org1MSP.member','Org2MSP.member')" -