From 10526d5a1d8b15539a41dacfa34f74b0e3320950 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Tue, 27 Feb 2018 20:14:28 -0500 Subject: [PATCH] FAB-8564 add debug commands to byfn replace DEBUG level logging w/INFO, but add in shell debug statements for all fabric commands for improved UX Change-Id: I97a19db0373ecaf7a504cb95d4815a11cd64dfed Signed-off-by: Christopher Ferris --- .gitignore | 3 +++ first-network/base/docker-compose-base.yaml | 2 +- first-network/base/peer-base.yaml | 4 +-- first-network/byfn.sh | 10 +++++++ first-network/docker-compose-cli.yaml | 3 ++- first-network/docker-compose-org3.yaml | 3 ++- first-network/eyfn.sh | 4 +++ first-network/scripts/script.sh | 2 ++ first-network/scripts/step1org3.sh | 4 +++ first-network/scripts/step2org3.sh | 2 ++ first-network/scripts/upgrade_to_v11.sh | 4 +++ first-network/scripts/utils.sh | 30 +++++++++++++++++++++ 12 files changed, 66 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 20f9216e9f..84262045c1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ first-network/channel-artifacts/*.tx first-network/channel-artifacts/*.block first-network/crypto-config/* +first-network/docker-compose-e2e.yaml +first-network/ledgers +first-network/ledgers-backup chaincode-docker-devmode/myc.block chaincode-docker-devmode/chaincode/sacc/sacc diff --git a/first-network/base/docker-compose-base.yaml b/first-network/base/docker-compose-base.yaml index 4acacc7cbd..2450ed7c30 100644 --- a/first-network/base/docker-compose-base.yaml +++ b/first-network/base/docker-compose-base.yaml @@ -11,7 +11,7 @@ services: container_name: orderer.example.com image: hyperledger/fabric-orderer:$IMAGE_TAG environment: - - ORDERER_GENERAL_LOGLEVEL=debug + - ORDERER_GENERAL_LOGLEVEL=INFO - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block diff --git a/first-network/base/peer-base.yaml b/first-network/base/peer-base.yaml index 063001f601..7d51adae88 100644 --- a/first-network/base/peer-base.yaml +++ b/first-network/base/peer-base.yaml @@ -14,8 +14,8 @@ services: # bridge network as the peers # https://docs.docker.com/compose/networking/ - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn - #- CORE_LOGGING_LEVEL=ERROR - - CORE_LOGGING_LEVEL=DEBUG + - CORE_LOGGING_LEVEL=INFO + #- CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_TLS_ENABLED=true - CORE_PEER_GOSSIP_USELEADERELECTION=true - CORE_PEER_GOSSIP_ORGLEADER=false diff --git a/first-network/byfn.sh b/first-network/byfn.sh index 161a5dc615..b2a5a599da 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -287,7 +287,9 @@ function generateCerts (){ if [ -d "crypto-config" ]; then rm -Rf crypto-config fi + set -x cryptogen generate --config=./crypto-config.yaml + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate certificates..." exit 1 @@ -345,7 +347,9 @@ function generateChannelArtifacts() { echo "##########################################################" # Note: For some unknown reason (at least for now) the block file can't be # named orderer.genesis.block or the orderer will fail to launch! + set -x configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate orderer genesis block..." exit 1 @@ -354,7 +358,9 @@ function generateChannelArtifacts() { echo "#################################################################" echo "### Generating channel configuration transaction 'channel.tx' ###" echo "#################################################################" + set -x configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate channel configuration transaction..." exit 1 @@ -364,7 +370,9 @@ function generateChannelArtifacts() { echo "#################################################################" echo "####### Generating anchor peer update for Org1MSP ##########" echo "#################################################################" + set -x configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate anchor peer update for Org1MSP..." exit 1 @@ -374,8 +382,10 @@ function generateChannelArtifacts() { echo "#################################################################" echo "####### Generating anchor peer update for Org2MSP ##########" echo "#################################################################" + set -x configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate \ ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate anchor peer update for Org2MSP..." exit 1 diff --git a/first-network/docker-compose-cli.yaml b/first-network/docker-compose-cli.yaml index 89f648ab9b..8db9df767b 100644 --- a/first-network/docker-compose-cli.yaml +++ b/first-network/docker-compose-cli.yaml @@ -58,7 +58,8 @@ services: environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - - CORE_LOGGING_LEVEL=DEBUG + #- CORE_LOGGING_LEVEL=DEBUG + - CORE_LOGGING_LEVEL=INFO - CORE_PEER_ID=cli - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP diff --git a/first-network/docker-compose-org3.yaml b/first-network/docker-compose-org3.yaml index 5bbb3c5a1d..eb664407af 100644 --- a/first-network/docker-compose-org3.yaml +++ b/first-network/docker-compose-org3.yaml @@ -61,7 +61,8 @@ services: environment: - GOPATH=/opt/gopath - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock - - CORE_LOGGING_LEVEL=DEBUG + - CORE_LOGGING_LEVEL=INFO + #- CORE_LOGGING_LEVEL=DEBUG - CORE_PEER_ID=Org3cli - CORE_PEER_ADDRESS=peer0.org3.example.com:7051 - CORE_PEER_LOCALMSPID=Org3MSP diff --git a/first-network/eyfn.sh b/first-network/eyfn.sh index 1d0bf090fc..d8b4604351 100755 --- a/first-network/eyfn.sh +++ b/first-network/eyfn.sh @@ -182,7 +182,9 @@ function generateCerts (){ echo "###############################################################" (cd org3-artifacts + set -x cryptogen generate --config=./org3-crypto.yaml + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate certificates..." exit 1 @@ -203,7 +205,9 @@ function generateChannelArtifacts() { echo "##########################################################" (cd org3-artifacts export FABRIC_CFG_PATH=$PWD + set -x configtxgen -printOrg Org3MSP > ../channel-artifacts/org3.json + set +x if [ "$?" -ne 0 ]; then echo "Failed to generate Org3 config material..." exit 1 diff --git a/first-network/scripts/script.sh b/first-network/scripts/script.sh index 0cadf09f2b..4e0b6ab446 100755 --- a/first-network/scripts/script.sh +++ b/first-network/scripts/script.sh @@ -36,7 +36,9 @@ createChannel() { setGlobals 0 1 if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txt + set +x else peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt fi diff --git a/first-network/scripts/step1org3.sh b/first-network/scripts/step1org3.sh index 1e468d3c4d..ad607e35b6 100755 --- a/first-network/scripts/step1org3.sh +++ b/first-network/scripts/step1org3.sh @@ -43,7 +43,9 @@ apt-get -y update && apt-get -y install jq fetchChannelConfig ${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 ./channel-artifacts/org3.json > modified_config.json +set +x # 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 @@ -60,7 +62,9 @@ echo echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= " echo setGlobals 0 2 +set -x peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --tls --cafile ${ORDERER_CA} +set +x echo echo "========= Config transaction to add org3 to network submitted! =========== " diff --git a/first-network/scripts/step2org3.sh b/first-network/scripts/step2org3.sh index b5ccb36170..0ffaa01ddf 100755 --- a/first-network/scripts/step2org3.sh +++ b/first-network/scripts/step2org3.sh @@ -36,7 +36,9 @@ fi . scripts/utils.sh echo "Fetching channel config block from orderer..." +set -x peer channel fetch 0 $CHANNEL_NAME.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt +set +x res=$? cat log.txt verifyResult $res "Fetching config block from orderer has Failed" diff --git a/first-network/scripts/upgrade_to_v11.sh b/first-network/scripts/upgrade_to_v11.sh index 8ce98a675e..bb980db98a 100755 --- a/first-network/scripts/upgrade_to_v11.sh +++ b/first-network/scripts/upgrade_to_v11.sh @@ -85,9 +85,13 @@ addCapabilityToChannel() { fi if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --cafile $ORDERER_CA + set +x else + set -x peer channel update -f config_update_in_envelope.pb -c $CH_NAME -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA + set +x fi res=$? verifyResult $res "Config update for \"$GROUP\" on \"$CH_NAME\" failed" diff --git a/first-network/scripts/utils.sh b/first-network/scripts/utils.sh index 5a7005adb5..305a810383 100755 --- a/first-network/scripts/utils.sh +++ b/first-network/scripts/utils.sh @@ -69,9 +69,13 @@ updateAnchorPeers() { setGlobals $PEER $ORG if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txt + set +x else + set -x peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt + set +x fi res=$? cat log.txt @@ -87,7 +91,9 @@ joinChannelWithRetry () { ORG=$2 setGlobals $PEER $ORG + set -x peer channel join -b $CHANNEL_NAME.block >&log.txt + set +x res=$? cat log.txt if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then @@ -106,7 +112,9 @@ installChaincode () { ORG=$2 setGlobals $PEER $ORG VERSION=${3:-1.0} + set -x peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >&log.txt + set +x res=$? cat log.txt verifyResult $res "Chaincode installation on peer${PEER}.org${ORG} has Failed" @@ -123,9 +131,13 @@ instantiateChaincode () { # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), # lets supply it directly as we know it using the "-o" option if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -l ${LANGUAGE} -v ${VERSION} -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')" >&log.txt + set +x else + set -x peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -l ${LANGUAGE} -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer')" >&log.txt + set +x fi res=$? cat log.txt @@ -139,7 +151,9 @@ upgradeChaincode () { ORG=$2 setGlobals $PEER $ORG + set -x peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c '{"Args":["init","a","90","b","210"]}' -P "OR ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')" + set +x res=$? cat log.txt verifyResult $res "Chaincode upgrade on org${ORG} peer${PEER} has Failed" @@ -162,7 +176,9 @@ chaincodeQuery () { do sleep $DELAY echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s)-starttime)) secs" + set -x peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt + set +x test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}') test "$VALUE" = "$EXPECTED_RESULT" && let rc=0 done @@ -188,13 +204,19 @@ fetchChannelConfig() { echo "Fetching the most recent configuration block for the channel" if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL --cafile $ORDERER_CA + set +x else + set -x peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL --tls --cafile $ORDERER_CA + set +x fi 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 } # signConfigtxAsPeerOrg @@ -203,7 +225,9 @@ signConfigtxAsPeerOrg() { PEERORG=$1 TX=$2 setGlobals 0 $PEERORG + set -x peer channel signconfigtx -f "${TX}" + set +x } # createConfigUpdate @@ -214,12 +238,14 @@ createConfigUpdate() { 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 } chaincodeInvoke () { @@ -229,9 +255,13 @@ chaincodeInvoke () { # while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful), # lets supply it directly as we know it using the "-o" option if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then + set -x peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txt + set +x else + set -x peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txt + set +x fi res=$? cat log.txt