Skip to content

Commit

Permalink
[FAB-14779] QueryApprovalStatus step in byfn
Browse files Browse the repository at this point in the history
Between the approve and commit steps we add a QueryApprovalStatus to verify
whether peers are ready to commit the chaincode definition.

Change-Id: I18805a4180fa61da07d2bca321c6355660f772fc
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Mar 28, 2019
1 parent d24577f commit eb3fe08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
14 changes: 12 additions & 2 deletions first-network/scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ installChaincode 0 2
## query whether the chaincode is installed
queryInstalled 0 1

## approve the definition for both orgs
## approve the definition for org1
approveForMyOrg 1 0 1

## query the approval status on both orgs, expect org1 to have approved and org2 not to
queryStatus 1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": false"
queryStatus 1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": false"

## now approve also for org2
approveForMyOrg 1 0 2

## commit the definition
## query the approval status on both orgs, expect them both to have approved
queryStatus 1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": true"
queryStatus 1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": true"

## now that we know for sure both orgs have approved, commit the definition
commitChaincodeDefinition 1 0 1 0 2

## query on both orgs to see that the definition committed ok
Expand Down
51 changes: 46 additions & 5 deletions first-network/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ approveForMyOrg() {

if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
set -x
peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >&log.txt
peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${VERSION} --waitForEvent >&log.txt
set +x
else
set -x
peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >&log.txt
peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence ${VERSION} --waitForEvent >&log.txt
set +x
fi
cat log.txt
Expand All @@ -196,12 +196,12 @@ commitChaincodeDefinition() {
# it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
set -x
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence 1 --init-required >&log.txt
peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&log.txt
res=$?
set +x
else
set -x
peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence 1 --init-required >&log.txt
peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&log.txt
res=$?
set +x
fi
Expand All @@ -211,6 +211,47 @@ commitChaincodeDefinition() {
echo
}

# queryStatus VERSION PEER ORG
queryStatus() {
VERSION=$1
PEER=$2
ORG=$3
shift 3
setGlobals $PEER $ORG
echo "===================== Querying approval status on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME'... ===================== "
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 mycc $PEER_CONN_PARMS --version ${VERSION} --sequence ${VERSION} --init-required >&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} on channel '$CHANNEL_NAME' ===================== "
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
}

# queryCommitted VERSION PEER ORG
queryCommitted() {
VERSION=$1
Expand All @@ -228,7 +269,7 @@ queryCommitted() {
test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do
sleep $DELAY
echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs"
echo "Attempting to Query committed status on peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs"
set -x
peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name mycc >&log.txt
res=$?
Expand Down

0 comments on commit eb3fe08

Please sign in to comment.