From b690d8f30f0e47f9512bc2620e95a413f54f6039 Mon Sep 17 00:00:00 2001 From: Will Lahti Date: Thu, 7 Jan 2021 13:22:03 -0500 Subject: [PATCH] Stop using deprecated outputAnchorPeersUpdate in test-network (#394) * Stop using deprecated outputAnchorPeersUpdate in test-network FAB-18381 Signed-off-by: Will Lahti * Improve consistency of test-network output Signed-off-by: Will Lahti --- test-network/addOrg3/addOrg3.sh | 104 +++++----------- .../addOrg3/fabric-ca/registerEnroll.sh | 41 +++---- .../docker/docker-compose-test-net.yaml | 22 ++++ test-network/network.sh | 42 +++---- .../organizations/fabric-ca/registerEnroll.sh | 52 ++++---- test-network/scripts/configUpdate.sh | 61 +++++++++ test-network/scripts/createChannel.sh | 84 +++---------- test-network/scripts/deployCC.sh | 2 +- test-network/scripts/envVar.sh | 33 +++-- .../scripts/org3-scripts/envVarCLI.sh | 54 -------- .../scripts/org3-scripts/joinChannel.sh | 70 +++++++++++ .../scripts/org3-scripts/step1org3.sh | 116 ------------------ .../scripts/org3-scripts/step2org3.sh | 68 ---------- .../org3-scripts/updateChannelConfig.sh | 52 ++++++++ test-network/scripts/setAnchorPeer.sh | 58 +++++++++ .../{scriptUtils.sh => scripts/utils.sh} | 0 16 files changed, 392 insertions(+), 467 deletions(-) create mode 100755 test-network/scripts/configUpdate.sh delete mode 100644 test-network/scripts/org3-scripts/envVarCLI.sh create mode 100755 test-network/scripts/org3-scripts/joinChannel.sh delete mode 100755 test-network/scripts/org3-scripts/step1org3.sh delete mode 100755 test-network/scripts/org3-scripts/step2org3.sh create mode 100755 test-network/scripts/org3-scripts/updateChannelConfig.sh create mode 100755 test-network/scripts/setAnchorPeer.sh rename test-network/{scriptUtils.sh => scripts/utils.sh} (100%) diff --git a/test-network/addOrg3/addOrg3.sh b/test-network/addOrg3/addOrg3.sh index 4d50a193..b56b92d1 100755 --- a/test-network/addOrg3/addOrg3.sh +++ b/test-network/addOrg3/addOrg3.sh @@ -15,6 +15,8 @@ export PATH=${PWD}/../../bin:${PWD}:$PATH export FABRIC_CFG_PATH=${PWD} export VERBOSE=false +. ../scripts/utils.sh + # Print the usage message function printHelp () { echo "Usage: " @@ -52,38 +54,28 @@ function printHelp () { # Create Organziation crypto material using cryptogen or CAs function generateOrg3() { - # Create crypto material using cryptogen if [ "$CRYPTO" == "cryptogen" ]; then which cryptogen if [ "$?" -ne 0 ]; then - echo "cryptogen tool not found. exiting" - exit 1 + fatalln "cryptogen tool not found. exiting" fi - echo - echo "##########################################################" - echo "##### Generate certificates using cryptogen tool #########" - echo "##########################################################" - echo + infoln "Generating certificates using cryptogen tool" - echo "##########################################################" - echo "############ Create Org3 Identities ######################" - echo "##########################################################" + infoln "Creating Org3 Identities" set -x cryptogen generate --config=org3-crypto.yaml --output="../organizations" res=$? { set +x; } 2>/dev/null if [ $res -ne 0 ]; then - echo "Failed to generate certificates..." - exit 1 + fatalln "Failed to generate certificates..." fi fi - # Create crypto material using Fabric CAs + # Create crypto material using Fabric CA if [ "$CRYPTO" == "Certificate Authorities" ]; then - fabric-ca-client version > /dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "ERROR! fabric-ca-client binary not found.." @@ -93,10 +85,7 @@ function generateOrg3() { exit 1 fi - echo - echo "##########################################################" - echo "##### Generate certificates using Fabric CA's ############" - echo "##########################################################" + infoln "Generating certificates using Fabric CA" IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA_ORG3 up -d 2>&1 @@ -104,16 +93,12 @@ function generateOrg3() { sleep 10 - echo "##########################################################" - echo "############ Create Org3 Identities ######################" - echo "##########################################################" - + infoln "Creating Org3 Identities" createOrg3 fi - echo - echo "Generate CCP files for Org3" + infoln "Generating CCP files for Org3" ./ccp-generate.sh } @@ -121,22 +106,17 @@ function generateOrg3() { function generateOrg3Definition() { which configtxgen if [ "$?" -ne 0 ]; then - echo "configtxgen tool not found. exiting" - exit 1 + fatalln "configtxgen tool not found. exiting" + fi + infoln "Generating Org3 organization definition" + export FABRIC_CFG_PATH=$PWD + set -x + configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json + res=$? + { set +x; } 2>/dev/null + if [ $res -ne 0 ]; then + fatalln "Failed to generate Org3 organization definition..." fi - echo "##########################################################" - echo "####### Generating Org3 organization definition #########" - echo "##########################################################" - export FABRIC_CFG_PATH=$PWD - set -x - configtxgen -printOrg Org3MSP > ../organizations/peerOrganizations/org3.example.com/org3.json - res=$? - { set +x; } 2>/dev/null - if [ $res -ne 0 ]; then - echo "Failed to generate Org3 config material..." - exit 1 - fi - echo } function Org3Up () { @@ -147,20 +127,15 @@ function Org3Up () { IMAGE_TAG=$IMAGETAG docker-compose -f $COMPOSE_FILE_ORG3 up -d 2>&1 fi if [ $? -ne 0 ]; then - echo "ERROR !!!! Unable to start Org3 network" - exit 1 + fatalln "ERROR !!!! Unable to start Org3 network" fi } # Generate the needed certificates, the genesis block and start the network. function addOrg3 () { - # If the test network is not up, abort if [ ! -d ../organizations/ordererOrganizations ]; then - echo - echo "ERROR: Please, run ./network.sh up createChannel first." - echo - exit 1 + fatalln "ERROR: Please, run ./network.sh up createChannel first." fi # generate artifacts if they don't exist @@ -169,39 +144,26 @@ function addOrg3 () { generateOrg3Definition fi - CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /fabric-tools/) {print $1}') - if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then - echo "Bringing up network" - Org3Up - fi + infoln "Bringing up Org3 peer" + Org3Up # Use the CLI container to create the configuration transaction needed to add # Org3 to the network - echo - echo "###############################################################" - echo "####### Generate and submit config tx to add Org3 #############" - echo "###############################################################" - docker exec Org3cli ./scripts/org3-scripts/step1org3.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE + infoln "Generating and submitting config tx to add Org3" + docker exec cli ./scripts/org3-scripts/updateChannelConfig.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE if [ $? -ne 0 ]; then - echo "ERROR !!!! Unable to create config tx" - exit 1 + fatalln "ERROR !!!! Unable to create config tx" fi - echo - echo "###############################################################" - echo "############### Have Org3 peers join network ##################" - echo "###############################################################" - docker exec Org3cli ./scripts/org3-scripts/step2org3.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE + infoln "Joining Org3 peers to network" + docker exec cli ./scripts/org3-scripts/joinChannel.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE if [ $? -ne 0 ]; then - echo "ERROR !!!! Unable to have Org3 peers join network" - exit 1 + fatalln "ERROR !!!! Unable to join Org3 peers to network" fi - } # Tear down running network function networkDown () { - cd .. ./network.sh down } @@ -286,9 +248,7 @@ while [[ $# -ge 1 ]] ; do shift ;; * ) - echo - echo "Unknown flag: $key" - echo + errorln "Unknown flag: $key" printHelp exit 1 ;; @@ -299,7 +259,7 @@ done # Determine whether starting, stopping, restarting or generating for announce if [ "$MODE" == "up" ]; then - echo "Add Org3 to channel '${CHANNEL_NAME}' with '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}'" + infoln "Adding org3 to channel '${CHANNEL_NAME}' with '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${DATABASE}'" echo elif [ "$MODE" == "down" ]; then EXPMODE="Stopping network" diff --git a/test-network/addOrg3/fabric-ca/registerEnroll.sh b/test-network/addOrg3/fabric-ca/registerEnroll.sh index a0dc729e..65b4122c 100644 --- a/test-network/addOrg3/fabric-ca/registerEnroll.sh +++ b/test-network/addOrg3/fabric-ca/registerEnroll.sh @@ -1,10 +1,14 @@ +#!/bin/bash +# +# Copyright IBM Corp All Rights Reserved +# +# SPDX-License-Identifier: Apache-2.0 +# +. ../../scripts/utils.sh function createOrg3 { - - echo - echo "Enroll the CA admin" - echo + infoln "Enrolling the CA admin" mkdir -p ../organizations/peerOrganizations/org3.example.com/ export FABRIC_CA_CLIENT_HOME=${PWD}/../organizations/peerOrganizations/org3.example.com/ @@ -30,23 +34,17 @@ function createOrg3 { Certificate: cacerts/localhost-11054-ca-org3.pem OrganizationalUnitIdentifier: orderer' > ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml - echo - echo "Register peer0" - echo + infoln "Registering peer0" set -x fabric-ca-client register --caname ca-org3 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null - echo - echo "Register user" - echo + infoln "Registering user" set -x fabric-ca-client register --caname ca-org3 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null - echo - echo "Register the org admin" - echo + infoln "Registering the org admin" set -x fabric-ca-client register --caname ca-org3 --id.name org3admin --id.secret org3adminpw --id.type admin --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null @@ -54,18 +52,14 @@ function createOrg3 { mkdir -p ../organizations/peerOrganizations/org3.example.com/peers mkdir -p ../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com - echo - echo "## Generate the peer0 msp" - echo + infoln "Generating the peer0 msp" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp --csr.hosts peer0.org3.example.com --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/msp/config.yaml - echo - echo "## Generate the peer0-tls certificates" - echo + infoln "Generating the peer0-tls certificates" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls --enrollment.profile tls --csr.hosts peer0.org3.example.com --csr.hosts localhost --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null @@ -87,9 +81,7 @@ function createOrg3 { mkdir -p ../organizations/peerOrganizations/org3.example.com/users mkdir -p ../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com - echo - echo "## Generate the user msp" - echo + infoln "Generating the user msp" set -x fabric-ca-client enroll -u https://user1:user1pw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/User1@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null @@ -98,13 +90,10 @@ function createOrg3 { mkdir -p ../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com - echo - echo "## Generate the org admin msp" - echo + infoln "Generating the org admin msp" set -x fabric-ca-client enroll -u https://org3admin:org3adminpw@localhost:11054 --caname ca-org3 -M ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp --tls.certfiles ${PWD}/fabric-ca/org3/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/../organizations/peerOrganizations/org3.example.com/msp/config.yaml ${PWD}/../organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp/config.yaml - } diff --git a/test-network/docker/docker-compose-test-net.yaml b/test-network/docker/docker-compose-test-net.yaml index f0b48514..71acf7fa 100644 --- a/test-network/docker/docker-compose-test-net.yaml +++ b/test-network/docker/docker-compose-test-net.yaml @@ -123,3 +123,25 @@ services: - 9051:9051 networks: - test + + cli: + container_name: cli + image: hyperledger/fabric-tools:$IMAGE_TAG + tty: true + stdin_open: true + environment: + - GOPATH=/opt/gopath + - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock + - FABRIC_LOGGING_SPEC=INFO + #- FABRIC_LOGGING_SPEC=DEBUG + working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer + command: /bin/bash + volumes: + - /var/run/:/host/var/run/ + - ../organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations + - ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ + depends_on: + - peer0.org1.example.com + - peer0.org2.example.com + networks: + - test diff --git a/test-network/network.sh b/test-network/network.sh index f9c99af7..0768cd66 100755 --- a/test-network/network.sh +++ b/test-network/network.sh @@ -16,7 +16,7 @@ export PATH=${PWD}/../bin:$PATH export FABRIC_CFG_PATH=${PWD}/configtx export VERBOSE=false -source scriptUtils.sh +. scripts/utils.sh # Obtain CONTAINER_IDS and remove them # TODO Might want to make this optional - could clear other containers @@ -131,7 +131,6 @@ function checkPrereqs() { # Create Organization crypto material using cryptogen or CAs function createOrgs() { - if [ -d "organizations/peerOrganizations" ]; then rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations fi @@ -142,9 +141,9 @@ function createOrgs() { if [ "$?" -ne 0 ]; then fatalln "cryptogen tool not found. exiting" fi - infoln "Generate certificates using cryptogen tool" + infoln "Generating certificates using cryptogen tool" - infoln "Create Org1 Identities" + infoln "Creating Org1 Identities" set -x cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output="organizations" @@ -154,7 +153,7 @@ function createOrgs() { fatalln "Failed to generate certificates..." fi - infoln "Create Org2 Identities" + infoln "Creating Org2 Identities" set -x cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output="organizations" @@ -164,7 +163,7 @@ function createOrgs() { fatalln "Failed to generate certificates..." fi - infoln "Create Orderer Org Identities" + infoln "Creating Orderer Org Identities" set -x cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output="organizations" @@ -176,10 +175,9 @@ function createOrgs() { fi - # Create crypto material using Fabric CAs + # Create crypto material using Fabric CA if [ "$CRYPTO" == "Certificate Authorities" ]; then - - infoln "Generate certificates using Fabric CA's" + infoln "Generating certificates using Fabric CA" IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA up -d 2>&1 @@ -194,21 +192,21 @@ function createOrgs() { fi done - infoln "Create Org1 Identities" + infoln "Creating Org1 Identities" createOrg1 - infoln "Create Org2 Identities" + infoln "Creating Org2 Identities" createOrg2 - infoln "Create Orderer Org Identities" + infoln "Creating Orderer Org Identities" createOrderer fi - infoln "Generate CCP files for Org1 and Org2" + infoln "Generating CCP files for Org1 and Org2" ./organizations/ccp-generate.sh } @@ -240,7 +238,6 @@ function createOrgs() { # Generate orderer system channel genesis block. function createConsortium() { - which configtxgen if [ "$?" -ne 0 ]; then fatalln "configtxgen tool not found." @@ -267,7 +264,6 @@ function createConsortium() { # Bring up the peer and orderer nodes using docker compose. function networkUp() { - checkPrereqs # generate artifacts if they don't exist if [ ! -d "organizations/peerOrganizations" ]; then @@ -289,10 +285,10 @@ function networkUp() { fi } -## call the script to join create the channel and join the peers of org1 and org2 +# call the script to create the channel, join the peers of org1 and org2, +# and then update the anchor peers for each organization function createChannel() { - -## Bring up the network if it is not already up. + # Bring up the network if it is not already up. if [ ! -d "organizations/peerOrganizations" ]; then infoln "Bringing up network" @@ -303,24 +299,17 @@ function createChannel() { # more to create the channel creation transaction and the anchor peer updates. # configtx.yaml is mounted in the cli container, which allows us to use it to # create the channel artifacts - scripts/createChannel.sh $CHANNEL_NAME $CLI_DELAY $MAX_RETRY $VERBOSE - if [ $? -ne 0 ]; then - fatalln "Create channel failed" - fi - + scripts/createChannel.sh $CHANNEL_NAME $CLI_DELAY $MAX_RETRY $VERBOSE } ## Call the script to deploy a chaincode to the channel function deployCC() { - scripts/deployCC.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE if [ $? -ne 0 ]; then fatalln "Deploying chaincode failed" fi - - exit 0 } @@ -345,7 +334,6 @@ function networkDown() { docker run --rm -v $(pwd):/data busybox sh -c 'cd /data && rm -rf addOrg3/fabric-ca/org3/msp addOrg3/fabric-ca/org3/tls-cert.pem addOrg3/fabric-ca/org3/ca-cert.pem addOrg3/fabric-ca/org3/IssuerPublicKey addOrg3/fabric-ca/org3/IssuerRevocationPublicKey addOrg3/fabric-ca/org3/fabric-ca-server.db' # remove channel and script artifacts docker run --rm -v $(pwd):/data busybox sh -c 'cd /data && rm -rf channel-artifacts log.txt *.tar.gz' - fi } diff --git a/test-network/organizations/fabric-ca/registerEnroll.sh b/test-network/organizations/fabric-ca/registerEnroll.sh index 6c01061d..c064d024 100755 --- a/test-network/organizations/fabric-ca/registerEnroll.sh +++ b/test-network/organizations/fabric-ca/registerEnroll.sh @@ -1,10 +1,9 @@ #!/bin/bash -source scriptUtils.sh +source scripts/utils.sh function createOrg1() { - - infoln "Enroll the CA admin" + infoln "Enrolling the CA admin" mkdir -p organizations/peerOrganizations/org1.example.com/ export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.example.com/ @@ -30,17 +29,17 @@ function createOrg1() { Certificate: cacerts/localhost-7054-ca-org1.pem OrganizationalUnitIdentifier: orderer' >${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml - infoln "Register peer0" + infoln "Registering peer0" set -x fabric-ca-client register --caname ca-org1 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null - infoln "Register user" + infoln "Registering user" set -x fabric-ca-client register --caname ca-org1 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null - infoln "Register the org admin" + infoln "Registering the org admin" set -x fabric-ca-client register --caname ca-org1 --id.name org1admin --id.secret org1adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null @@ -48,14 +47,14 @@ function createOrg1() { mkdir -p organizations/peerOrganizations/org1.example.com/peers mkdir -p organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com - infoln "Generate the peer0 msp" + infoln "Generating the peer0 msp" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp --csr.hosts peer0.org1.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/config.yaml - infoln "Generate the peer0-tls certificates" + infoln "Generating the peer0-tls certificates" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls --enrollment.profile tls --csr.hosts peer0.org1.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null @@ -76,7 +75,7 @@ function createOrg1() { mkdir -p organizations/peerOrganizations/org1.example.com/users mkdir -p organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com - infoln "Generate the user msp" + infoln "Generating the user msp" set -x fabric-ca-client enroll -u https://user1:user1pw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null @@ -85,18 +84,16 @@ function createOrg1() { mkdir -p organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com - infoln "Generate the org admin msp" + infoln "Generating the org admin msp" set -x fabric-ca-client enroll -u https://org1admin:org1adminpw@localhost:7054 --caname ca-org1 -M ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org1/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/config.yaml - } function createOrg2() { - - infoln "Enroll the CA admin" + infoln "Enrolling the CA admin" mkdir -p organizations/peerOrganizations/org2.example.com/ export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org2.example.com/ @@ -122,17 +119,17 @@ function createOrg2() { Certificate: cacerts/localhost-8054-ca-org2.pem OrganizationalUnitIdentifier: orderer' >${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml - infoln "Register peer0" + infoln "Registering peer0" set -x fabric-ca-client register --caname ca-org2 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null - infoln "Register user" + infoln "Registering user" set -x fabric-ca-client register --caname ca-org2 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null - infoln "Register the org admin" + infoln "Registering the org admin" set -x fabric-ca-client register --caname ca-org2 --id.name org2admin --id.secret org2adminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null @@ -140,14 +137,14 @@ function createOrg2() { mkdir -p organizations/peerOrganizations/org2.example.com/peers mkdir -p organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com - infoln "Generate the peer0 msp" + infoln "Generating the peer0 msp" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp --csr.hosts peer0.org2.example.com --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/config.yaml - infoln "Generate the peer0-tls certificates" + infoln "Generating the peer0-tls certificates" set -x fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls --enrollment.profile tls --csr.hosts peer0.org2.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null @@ -168,7 +165,7 @@ function createOrg2() { mkdir -p organizations/peerOrganizations/org2.example.com/users mkdir -p organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com - infoln "Generate the user msp" + infoln "Generating the user msp" set -x fabric-ca-client enroll -u https://user1:user1pw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null @@ -177,18 +174,16 @@ function createOrg2() { mkdir -p organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com - infoln "Generate the org admin msp" + infoln "Generating the org admin msp" set -x fabric-ca-client enroll -u https://org2admin:org2adminpw@localhost:8054 --caname ca-org2 -M ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/org2/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/peerOrganizations/org2.example.com/msp/config.yaml ${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/config.yaml - } function createOrderer() { - - infoln "Enroll the CA admin" + infoln "Enrolling the CA admin" mkdir -p organizations/ordererOrganizations/example.com export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/ordererOrganizations/example.com @@ -214,12 +209,12 @@ function createOrderer() { Certificate: cacerts/localhost-9054-ca-orderer.pem OrganizationalUnitIdentifier: orderer' >${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml - infoln "Register orderer" + infoln "Registering orderer" set -x fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem { set +x; } 2>/dev/null - infoln "Register the orderer admin" + infoln "Registering the orderer admin" set -x fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem { set +x; } 2>/dev/null @@ -229,14 +224,14 @@ function createOrderer() { mkdir -p organizations/ordererOrganizations/example.com/orderers/orderer.example.com - infoln "Generate the orderer msp" + infoln "Generating the orderer msp" set -x fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/config.yaml - infoln "Generate the orderer-tls certificates" + infoln "Generating the orderer-tls certificates" set -x fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls --enrollment.profile tls --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem { set +x; } 2>/dev/null @@ -254,11 +249,10 @@ function createOrderer() { mkdir -p organizations/ordererOrganizations/example.com/users mkdir -p organizations/ordererOrganizations/example.com/users/Admin@example.com - infoln "Generate the admin msp" + infoln "Generating the admin msp" set -x fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@localhost:9054 --caname ca-orderer -M ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp --tls.certfiles ${PWD}/organizations/fabric-ca/ordererOrg/tls-cert.pem { set +x; } 2>/dev/null cp ${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml ${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp/config.yaml - } diff --git a/test-network/scripts/configUpdate.sh b/test-network/scripts/configUpdate.sh new file mode 100755 index 00000000..f5d941f4 --- /dev/null +++ b/test-network/scripts/configUpdate.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# import utils +. scripts/envVar.sh + +# fetchChannelConfig +# Writes the current channel config for a given channel to a JSON file +# NOTE: this must be run in a CLI container since it requires configtxlator +fetchChannelConfig() { + ORG=$1 + CHANNEL=$2 + OUTPUT=$3 + + setGlobals $ORG + + infoln "Fetching the most recent configuration block for the channel" + set -x + peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA + { set +x; } 2>/dev/null + + infoln "Decoding config block to JSON and isolating config to ${OUTPUT}" + set -x + configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}" + { set +x; } 2>/dev/null +} + +# createConfigUpdate +# Takes an original and modified config, and produces the config update tx +# which transitions between the two +# NOTE: this must be run in a CLI container since it requires configtxlator +createConfigUpdate() { + CHANNEL=$1 + ORIGINAL=$2 + MODIFIED=$3 + OUTPUT=$4 + + set -x + configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb + configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb + configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json + echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json + configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}" + { set +x; } 2>/dev/null +} + +# signConfigtxAsPeerOrg +# Set the peerOrg admin of an org and sign the config update +signConfigtxAsPeerOrg() { + ORG=$1 + CONFIGTXFILE=$2 + setGlobals $ORG + set -x + peer channel signconfigtx -f "${CONFIGTXFILE}" + { set +x; } 2>/dev/null +} diff --git a/test-network/scripts/createChannel.sh b/test-network/scripts/createChannel.sh index 28d23e02..567155cb 100755 --- a/test-network/scripts/createChannel.sh +++ b/test-network/scripts/createChannel.sh @@ -1,6 +1,8 @@ #!/bin/bash -source scriptUtils.sh +# imports +. scripts/envVar.sh +. scripts/utils.sh CHANNEL_NAME="$1" DELAY="$2" @@ -11,38 +13,16 @@ VERBOSE="$4" : ${MAX_RETRY:="5"} : ${VERBOSE:="false"} -# import utils -. scripts/envVar.sh - if [ ! -d "channel-artifacts" ]; then mkdir channel-artifacts fi createChannelTx() { - set -x configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID $CHANNEL_NAME res=$? { set +x; } 2>/dev/null - if [ $res -ne 0 ]; then - fatalln "Failed to generate channel configuration transaction..." - fi - -} - -createAnchorPeerTx() { - - for orgmsp in Org1MSP Org2MSP; do - - infoln "Generating anchor peer update transaction for ${orgmsp}" - set -x - configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp} - res=$? - { set +x; } 2>/dev/null - if [ $res -ne 0 ]; then - fatalln "Failed to generate anchor peer update transaction for ${orgmsp}..." - fi - done + verifyResult $res "Failed to generate channel configuration transaction..." } createChannel() { @@ -53,7 +33,7 @@ createChannel() { while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do sleep $DELAY set -x - peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock ./channel-artifacts/${CHANNEL_NAME}.block --tls --cafile $ORDERER_CA >&log.txt + peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock $BLOCKFILE --tls --cafile $ORDERER_CA >&log.txt res=$? { set +x; } 2>/dev/null let rc=$res @@ -61,11 +41,11 @@ createChannel() { done cat log.txt verifyResult $res "Channel creation failed" - successln "Channel '$CHANNEL_NAME' created" } -# queryCommitted ORG +# joinChannel ORG joinChannel() { + FABRIC_CFG_PATH=$PWD/../config/ ORG=$1 setGlobals $ORG local rc=1 @@ -74,7 +54,7 @@ joinChannel() { while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do sleep $DELAY set -x - peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt + peer channel join -b $BLOCKFILE >&log.txt res=$? { set +x; } 2>/dev/null let rc=$res @@ -84,31 +64,9 @@ joinChannel() { verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' " } -updateAnchorPeers() { +setAnchorPeer() { ORG=$1 - setGlobals $ORG - local rc=1 - local COUNTER=1 - ## Sometimes Join takes time, hence retry - while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do - sleep $DELAY - set -x - peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt - res=$? - { set +x; } 2>/dev/null - let rc=$res - COUNTER=$(expr $COUNTER + 1) - done - cat log.txt - verifyResult $res "Anchor peer update failed" - successln "Anchor peers updated for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME'" - sleep $DELAY -} - -verifyResult() { - if [ $1 -ne 0 ]; then - fatalln "$2" - fi + docker exec cli ./scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME } FABRIC_CFG_PATH=${PWD}/configtx @@ -117,28 +75,24 @@ FABRIC_CFG_PATH=${PWD}/configtx infoln "Generating channel create transaction '${CHANNEL_NAME}.tx'" createChannelTx -## Create anchorpeertx -infoln "Generating anchor peer update transactions" -createAnchorPeerTx - FABRIC_CFG_PATH=$PWD/../config/ +BLOCKFILE="./channel-artifacts/${CHANNEL_NAME}.block" ## Create channel infoln "Creating channel ${CHANNEL_NAME}" createChannel +successln "Channel '$CHANNEL_NAME' created" ## Join all the peers to the channel -infoln "Join Org1 peers to the channel..." +infoln "Joining org1 peer to the channel..." joinChannel 1 -infoln "Join Org2 peers to the channel..." +infoln "Joining org2 peer to the channel..." joinChannel 2 ## Set the anchor peers for each org in the channel -infoln "Updating anchor peers for org1..." -updateAnchorPeers 1 -infoln "Updating anchor peers for org2..." -updateAnchorPeers 2 +infoln "Setting anchor peer for org1..." +setAnchorPeer 1 +infoln "Setting anchor peer for org2..." +setAnchorPeer 2 -successln "Channel successfully joined" - -exit 0 +successln "Channel '$CHANNEL_NAME' joined" diff --git a/test-network/scripts/deployCC.sh b/test-network/scripts/deployCC.sh index c65973c6..fb5f95b6 100755 --- a/test-network/scripts/deployCC.sh +++ b/test-network/scripts/deployCC.sh @@ -1,6 +1,6 @@ #!/bin/bash -source scriptUtils.sh +source scripts/utils.sh CHANNEL_NAME=${1:-"mychannel"} CC_NAME=${2} diff --git a/test-network/scripts/envVar.sh b/test-network/scripts/envVar.sh index 8ef2bd25..4ac40c07 100755 --- a/test-network/scripts/envVar.sh +++ b/test-network/scripts/envVar.sh @@ -1,3 +1,4 @@ +#!/bin/bash # # Copyright IBM Corp All Rights Reserved # @@ -6,7 +7,8 @@ # This is a collection of bash functions used by different scripts -source scriptUtils.sh +# imports +. scripts/utils.sh export CORE_PEER_TLS_ENABLED=true export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem @@ -14,13 +16,6 @@ export PEER0_ORG1_CA=${PWD}/organizations/peerOrganizations/org1.example.com/pee export PEER0_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt export PEER0_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt -# Set OrdererOrg.Admin globals -setOrdererGlobals() { - export CORE_PEER_LOCALMSPID="OrdererMSP" - export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem - export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp -} - # Set environment variables for the peer org setGlobals() { local USING_ORG="" @@ -55,11 +50,31 @@ setGlobals() { fi } +# Set environment variables for use in the CLI container +setGlobalsCLI() { + setGlobals $1 + + local USING_ORG="" + if [ -z "$OVERRIDE_ORG" ]; then + USING_ORG=$1 + else + USING_ORG="${OVERRIDE_ORG}" + fi + if [ $USING_ORG -eq 1 ]; then + export CORE_PEER_ADDRESS=peer0.org1.example.com:7051 + elif [ $USING_ORG -eq 2 ]; then + export CORE_PEER_ADDRESS=peer0.org2.example.com:9051 + elif [ $USING_ORG -eq 3 ]; then + export CORE_PEER_ADDRESS=peer0.org3.example.com:11051 + else + errorln "ORG Unknown" + fi +} + # parsePeerConnectionParameters $@ # Helper function that sets the peer connection parameters for a chaincode # operation parsePeerConnectionParameters() { - PEER_CONN_PARMS="" PEERS="" while [ "$#" -gt 0 ]; do diff --git a/test-network/scripts/org3-scripts/envVarCLI.sh b/test-network/scripts/org3-scripts/envVarCLI.sh deleted file mode 100644 index 5607196e..00000000 --- a/test-network/scripts/org3-scripts/envVarCLI.sh +++ /dev/null @@ -1,54 +0,0 @@ -# -# Copyright IBM Corp All Rights Reserved -# -# SPDX-License-Identifier: Apache-2.0 -# - -# This is a collection of bash functions used by different scripts - -ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -PEER0_ORG3_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt - -# Set OrdererOrg.Admin globals -setOrdererGlobals() { - CORE_PEER_LOCALMSPID="OrdererMSP" - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp -} - -# Set environment variables for the peer org -setGlobals() { - ORG=$1 - if [ $ORG -eq 1 ]; then - CORE_PEER_LOCALMSPID="Org1MSP" - CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - elif [ $ORG -eq 2 ]; then - CORE_PEER_LOCALMSPID="Org2MSP" - CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp - CORE_PEER_ADDRESS=peer0.org2.example.com:9051 - elif [ $ORG -eq 3 ]; then - CORE_PEER_LOCALMSPID="Org3MSP" - CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp - CORE_PEER_ADDRESS=peer0.org3.example.com:11051 - else - echo "================== ERROR !!! ORG Unknown ==================" - fi - - if [ "$VERBOSE" == "true" ]; then - env | grep CORE - fi -} - -verifyResult() { - if [ $1 -ne 0 ]; then - echo $'\e[1;31m'!!!!!!!!!!!!!!! $2 !!!!!!!!!!!!!!!!$'\e[0m' - echo - exit 1 - fi -} diff --git a/test-network/scripts/org3-scripts/joinChannel.sh b/test-network/scripts/org3-scripts/joinChannel.sh new file mode 100755 index 00000000..97153ccb --- /dev/null +++ b/test-network/scripts/org3-scripts/joinChannel.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# This script is designed to be run in the cli container as the +# second step of the EYFN tutorial. It joins the org3 peers to the +# channel previously setup in the BYFN tutorial and install the +# chaincode as version 2.0 on peer0.org3. +# + +CHANNEL_NAME="$1" +DELAY="$2" +TIMEOUT="$3" +VERBOSE="$4" +: ${CHANNEL_NAME:="mychannel"} +: ${DELAY:="3"} +: ${TIMEOUT:="10"} +: ${VERBOSE:="false"} +COUNTER=1 +MAX_RETRY=5 + +# import environment variables +. scripts/envVar.sh + +# joinChannel ORG +joinChannel() { + ORG=$1 + local rc=1 + local COUNTER=1 + ## Sometimes Join takes time, hence retry + while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do + sleep $DELAY + set -x + peer channel join -b $BLOCKFILE >&log.txt + res=$? + { set +x; } 2>/dev/null + let rc=$res + COUNTER=$(expr $COUNTER + 1) + done + cat log.txt + verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' " +} + +setAnchorPeer() { + ORG=$1 + scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME +} + +setGlobalsCLI 3 +BLOCKFILE="${CHANNEL_NAME}.block" + +echo "Fetching channel config block from orderer..." +set -x +peer channel fetch 0 $BLOCKFILE -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt +res=$? +{ set +x; } 2>/dev/null +cat log.txt +verifyResult $res "Fetching config block from orderer has failed" + +infoln "Joining org3 peer to the channel..." +joinChannel 3 + +infoln "Setting anchor peer for org3..." +setAnchorPeer 3 + +successln "Channel '$CHANNEL_NAME' joined" +successln "Org3 peer successfully added to network" diff --git a/test-network/scripts/org3-scripts/step1org3.sh b/test-network/scripts/org3-scripts/step1org3.sh deleted file mode 100755 index 6d2300ba..00000000 --- a/test-network/scripts/org3-scripts/step1org3.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash -# -# Copyright IBM Corp. All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -# - -# This script is designed to be run in the org3cli container as the -# first step of the EYFN tutorial. It creates and submits a -# configuration transaction to add org3 to the test network -# - -CHANNEL_NAME="$1" -DELAY="$2" -TIMEOUT="$3" -VERBOSE="$4" -: ${CHANNEL_NAME:="mychannel"} -: ${DELAY:="3"} -: ${TIMEOUT:="10"} -: ${VERBOSE:="false"} -COUNTER=1 -MAX_RETRY=5 - - -# import environment variables -. scripts/org3-scripts/envVarCLI.sh - - -# fetchChannelConfig -# Writes the current channel config for a given channel to a JSON file -fetchChannelConfig() { - ORG=$1 - CHANNEL=$2 - OUTPUT=$3 - - setOrdererGlobals - - setGlobals $ORG - - echo "Fetching the most recent configuration block for the channel" - set -x - peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA - { set +x; } 2>/dev/null - - echo "Decoding config block to JSON and isolating config to ${OUTPUT}" - set -x - configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}" - { set +x; } 2>/dev/null -} - -# createConfigUpdate -# Takes an original and modified config, and produces the config update tx -# which transitions between the two -createConfigUpdate() { - CHANNEL=$1 - ORIGINAL=$2 - MODIFIED=$3 - OUTPUT=$4 - - set -x - configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb - configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb - configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb - configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json - echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json - configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}" - { set +x; } 2>/dev/null -} - -# signConfigtxAsPeerOrg -# Set the peerOrg admin of an org and signing the config update -signConfigtxAsPeerOrg() { - PEERORG=$1 - TX=$2 - setGlobals $PEERORG - set -x - peer channel signconfigtx -f "${TX}" - { set +x; } 2>/dev/null -} - -echo -echo "========= Creating config transaction to add org3 to network =========== " -echo - -# Fetch the config for the channel, writing it to config.json -fetchChannelConfig 1 ${CHANNEL_NAME} config.json - -# Modify the configuration to append the new org -set -x -jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json -{ set +x; } 2>/dev/null - -# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb -createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb - -echo -echo "========= Config transaction to add org3 to network created ===== " -echo - -echo "Signing config transaction" -echo -signConfigtxAsPeerOrg 1 org3_update_in_envelope.pb - -echo -echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= " -echo -setGlobals 2 -set -x -peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA} -{ set +x; } 2>/dev/null - -echo -echo "========= Config transaction to add org3 to network submitted! =========== " -echo - -exit 0 diff --git a/test-network/scripts/org3-scripts/step2org3.sh b/test-network/scripts/org3-scripts/step2org3.sh deleted file mode 100755 index 7c2f5719..00000000 --- a/test-network/scripts/org3-scripts/step2org3.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -# -# Copyright IBM Corp. All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -# - -# This script is designed to be run in the org3cli container as the -# second step of the EYFN tutorial. It joins the org3 peers to the -# channel previously setup in the BYFN tutorial and install the -# chaincode as version 2.0 on peer0.org3. -# - -echo -echo "========= Getting Org3 on to your test network ========= " -echo -CHANNEL_NAME="$1" -DELAY="$2" -TIMEOUT="$3" -VERBOSE="$4" -: ${CHANNEL_NAME:="mychannel"} -: ${DELAY:="3"} -: ${TIMEOUT:="10"} -: ${VERBOSE:="false"} -COUNTER=1 -MAX_RETRY=5 - -# import environment variables -. scripts/org3-scripts/envVarCLI.sh - -## Sometimes Join takes time hence RETRY at least 5 times -joinChannelWithRetry() { - ORG=$1 - setGlobals $ORG - - set -x - peer channel join -b $CHANNEL_NAME.block >&log.txt - res=$? - { set +x; } 2>/dev/null - cat log.txt - if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then - COUNTER=$(expr $COUNTER + 1) - echo "peer0.org${ORG} failed to join the channel, Retry after $DELAY seconds" - sleep $DELAY - joinChannelWithRetry $PEER $ORG - else - COUNTER=1 - fi - verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' " -} - - -echo "Fetching channel config block from orderer..." -set -x -peer channel fetch 0 $CHANNEL_NAME.block -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt -res=$? -{ set +x; } 2>/dev/null -cat log.txt -verifyResult $res "Fetching config block from orderer has Failed" - -joinChannelWithRetry 3 -echo "===================== peer0.org3 joined channel '$CHANNEL_NAME' ===================== " - -echo -echo "========= Finished adding Org3 to your test network! ========= " -echo - -exit 0 diff --git a/test-network/scripts/org3-scripts/updateChannelConfig.sh b/test-network/scripts/org3-scripts/updateChannelConfig.sh new file mode 100755 index 00000000..eabbf71e --- /dev/null +++ b/test-network/scripts/org3-scripts/updateChannelConfig.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# This script is designed to be run in the cli container as the +# first step of the EYFN tutorial. It creates and submits a +# configuration transaction to add org3 to the test network +# + +CHANNEL_NAME="$1" +DELAY="$2" +TIMEOUT="$3" +VERBOSE="$4" +: ${CHANNEL_NAME:="mychannel"} +: ${DELAY:="3"} +: ${TIMEOUT:="10"} +: ${VERBOSE:="false"} +COUNTER=1 +MAX_RETRY=5 + + +# imports +. scripts/envVar.sh +. scripts/configUpdate.sh +. scripts/utils.sh + +infoln "Creating config transaction to add org3 to network" + +# Fetch the config for the channel, writing it to config.json +fetchChannelConfig 1 ${CHANNEL_NAME} config.json + +# Modify the configuration to append the new org +set -x +jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json +{ set +x; } 2>/dev/null + +# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb +createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb + +infoln "Signing config transaction" +signConfigtxAsPeerOrg 1 org3_update_in_envelope.pb + +infoln "Submitting transaction from a different peer (peer0.org2) which also signs it" +setGlobals 2 +set -x +peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA} +{ set +x; } 2>/dev/null + +successln "Config transaction to add org3 to network submitted" diff --git a/test-network/scripts/setAnchorPeer.sh b/test-network/scripts/setAnchorPeer.sh new file mode 100755 index 00000000..d0ac00d6 --- /dev/null +++ b/test-network/scripts/setAnchorPeer.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# import utils +. scripts/envVar.sh +. scripts/configUpdate.sh + + +# NOTE: this must be run in a CLI container since it requires jq and configtxlator +createAnchorPeerUpdate() { + infoln "Fetching channel config for channel $CHANNEL_NAME" + fetchChannelConfig $ORG $CHANNEL_NAME ${CORE_PEER_LOCALMSPID}config.json + + infoln "Generating anchor peer update transaction for Org${ORG} on channel $CHANNEL_NAME" + + if [ $ORG -eq 1 ]; then + HOST="peer0.org1.example.com" + PORT=7051 + elif [ $ORG -eq 2 ]; then + HOST="peer0.org2.example.com" + PORT=9051 + elif [ $ORG -eq 3 ]; then + HOST="peer0.org3.example.com" + PORT=11051 + else + errorln "Org${ORG} unknown" + fi + + set -x + # Modify the configuration to append the anchor peer + jq '.channel_group.groups.Application.groups.'${CORE_PEER_LOCALMSPID}'.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "'$HOST'","port": '$PORT'}]},"version": "0"}}' ${CORE_PEER_LOCALMSPID}config.json > ${CORE_PEER_LOCALMSPID}modified_config.json + { set +x; } 2>/dev/null + + # Compute a config update, based on the differences between + # {orgmsp}config.json and {orgmsp}modified_config.json, write + # it as a transaction to {orgmsp}anchors.tx + createConfigUpdate ${CHANNEL_NAME} ${CORE_PEER_LOCALMSPID}config.json ${CORE_PEER_LOCALMSPID}modified_config.json ${CORE_PEER_LOCALMSPID}anchors.tx +} + +updateAnchorPeer() { + peer channel update -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt + res=$? + cat log.txt + verifyResult $res "Anchor peer update failed" + successln "Anchor peer set for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME'" +} + +ORG=$1 +CHANNEL_NAME=$2 +setGlobalsCLI $ORG + +createAnchorPeerUpdate + +updateAnchorPeer diff --git a/test-network/scriptUtils.sh b/test-network/scripts/utils.sh similarity index 100% rename from test-network/scriptUtils.sh rename to test-network/scripts/utils.sh