Skip to content

Commit

Permalink
FAB-8564 add debug commands to byfn
Browse files Browse the repository at this point in the history
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 <chrisfer@us.ibm.com>
  • Loading branch information
christo4ferris committed Feb 28, 2018
1 parent 831e9bf commit 10526d5
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion first-network/base/docker-compose-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions first-network/base/peer-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions first-network/byfn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion first-network/docker-compose-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion first-network/docker-compose-org3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions first-network/eyfn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions first-network/scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions first-network/scripts/step1org3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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! =========== "
Expand Down
2 changes: 2 additions & 0 deletions first-network/scripts/step2org3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions first-network/scripts/upgrade_to_v11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 30 additions & 0 deletions first-network/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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 <org> <configtx.pb>
Expand All @@ -203,7 +225,9 @@ signConfigtxAsPeerOrg() {
PEERORG=$1
TX=$2
setGlobals 0 $PEERORG
set -x
peer channel signconfigtx -f "${TX}"
set +x
}

# createConfigUpdate <channel_id> <original_config.json> <modified_config.json> <output.pb>
Expand All @@ -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 () {
Expand All @@ -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
Expand Down

0 comments on commit 10526d5

Please sign in to comment.