Skip to content

Commit 2777429

Browse files
committed
[FAB-14711] update byfn with new lifecycle
Change-Id: I24dd3e85f6dedab52b05ce3103ee06435f01f9a3 Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent aec3389 commit 2777429

File tree

7 files changed

+168
-100
lines changed

7 files changed

+168
-100
lines changed

first-network/configtx.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ Capabilities:
157157
# used with prior release orderers.
158158
# Set the value of the capability to true to require it.
159159
Application: &ApplicationCapabilities
160+
# V2.0 for Application enables the new non-backwards compatible
161+
# features and fixes of fabric v2.0.
162+
V2_0: true
160163
# V1.3 for Application enables the new non-backwards compatible
161-
# features and fixes of fabric v1.3.
162-
V1_3: true
164+
# features and fixes of fabric v1.3 (note, this need not be set if
165+
# later version capabilities are set)
166+
V1_3: false
163167
# V1.2 for Application enables the new non-backwards compatible
164168
# features and fixes of fabric v1.2 (note, this need not be set if
165169
# later version capabilities are set)

first-network/eyfn.sh

-9
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ function networkUp () {
117117
echo "ERROR !!!! Unable to have Org3 peers join network"
118118
exit 1
119119
fi
120-
echo
121-
echo "###############################################################"
122-
echo "##### Upgrade chaincode to have Org3 peers on the network #####"
123-
echo "###############################################################"
124-
docker exec cli ./scripts/step3org3.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE
125-
if [ $? -ne 0 ]; then
126-
echo "ERROR !!!! Unable to add Org3 peers on network"
127-
exit 1
128-
fi
129120
# finish by running the test
130121
docker exec Org3cli ./scripts/testorg3.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE
131122
if [ $? -ne 0 ]; then

first-network/scripts/script.sh

+25-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ VERBOSE="$5"
2222
LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]`
2323
COUNTER=1
2424
MAX_RETRY=10
25+
PACKAGE_ID=""
2526

2627
if [ "$LANGUAGE" = "node" ]; then
2728
CC_SRC_PATH="/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abstore/node/"
@@ -81,23 +82,43 @@ updateAnchorPeers 0 1
8182
echo "Updating anchor peers for org2..."
8283
updateAnchorPeers 0 2
8384

85+
## at first we package the chaincode
86+
packageChaincode 1 0 1
87+
8488
## Install chaincode on peer0.org1 and peer0.org2
8589
echo "Installing chaincode on peer0.org1..."
8690
installChaincode 0 1
8791
echo "Install chaincode on peer0.org2..."
8892
installChaincode 0 2
8993

90-
# Instantiate chaincode on peer0.org2
91-
echo "Instantiating chaincode on peer0.org2..."
92-
instantiateChaincode 0 2
94+
## query whether the chaincode is installed
95+
queryInstalled 0 1
96+
97+
## approve the definition for both orgs
98+
approveForMyOrg 1 0 1
99+
approveForMyOrg 1 0 2
100+
101+
## commit the definition
102+
commitChaincodeDefinition 1 0 1 0 2
103+
104+
## query on both orgs to see that the definition committed ok
105+
queryCommitted 1 0 1
106+
queryCommitted 1 0 2
107+
108+
# invoke init
109+
chaincodeInvoke 1 0 1 0 2
93110

94111
# Query chaincode on peer0.org1
95112
echo "Querying chaincode on peer0.org1..."
96113
chaincodeQuery 0 1 100
97114

98115
# Invoke chaincode on peer0.org1 and peer0.org2
99116
echo "Sending invoke transaction on peer0.org1 peer0.org2..."
100-
chaincodeInvoke 0 1 0 2
117+
chaincodeInvoke 0 0 1 0 2
118+
119+
# Query chaincode on peer0.org1
120+
echo "Querying chaincode on peer0.org1..."
121+
chaincodeQuery 0 1 90
101122

102123
## Install chaincode on peer1.org2
103124
echo "Installing chaincode on peer1.org2..."

first-network/scripts/step2org3.sh

+21-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ VERBOSE="$5"
2727
LANGUAGE=`echo "$LANGUAGE" | tr [:upper:] [:lower:]`
2828
COUNTER=1
2929
MAX_RETRY=5
30+
PACKAGE_ID=""
3031

3132
if [ "$LANGUAGE" = "node" ]; then
3233
CC_SRC_PATH="/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abstore/node/"
@@ -51,11 +52,28 @@ joinChannelWithRetry 0 3
5152
echo "===================== peer0.org3 joined channel '$CHANNEL_NAME' ===================== "
5253
joinChannelWithRetry 1 3
5354
echo "===================== peer1.org3 joined channel '$CHANNEL_NAME' ===================== "
54-
echo "Installing chaincode 2.0 on peer0.org3..."
55-
installChaincode 0 3 2.0
55+
56+
## at first we package the chaincode
57+
packageChaincode 1 0 3
58+
59+
echo "Installing chaincode on peer0.org3..."
60+
installChaincode 0 3
61+
62+
## query whether the chaincode is installed
63+
queryInstalled 0 3
64+
65+
## sanity check: expect the chaincode to be already committed
66+
queryCommitted 1 0 3
67+
68+
## approve it for our org, so that our peers know what package to invoke
69+
approveForMyOrg 1 0 3
70+
71+
# Query on chaincode on peer0.org3, check if the result is 90
72+
echo "Querying chaincode on peer0.org3..."
73+
chaincodeQuery 0 3 90
5674

5775
echo
58-
echo "========= Org3 is now halfway onto your first network ========= "
76+
echo "========= Finished adding Org3 to your first network! ========= "
5977
echo
6078

6179
exit 0

first-network/scripts/step3org3.sh

-55
This file was deleted.

first-network/scripts/testorg3.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ echo "Channel name : "$CHANNEL_NAME
5050
echo "Querying chaincode on peer0.org3..."
5151
chaincodeQuery 0 3 90
5252

53-
# Invoke chaincode on peer0.org1, peer0.org2, and peer0.org3
54-
echo "Sending invoke transaction on peer0.org1 peer0.org2 peer0.org3..."
55-
chaincodeInvoke 0 1 0 2 0 3
53+
# Invoke chaincode on peer0.org1 and peer0.org3
54+
echo "Sending invoke transaction on peer0.org1 peer0.org3..."
55+
chaincodeInvoke 0 0 1 0 3
5656

5757
# Query on chaincode on peer0.org3, peer0.org2, peer0.org1 check if the result is 80
5858
# We query a peer in each organization, to ensure peers from all organizations are in sync

first-network/scripts/utils.sh

+113-24
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,29 @@ joinChannelWithRetry() {
113113
verifyResult $res "After $MAX_RETRY attempts, peer${PEER}.org${ORG} has failed to join channel '$CHANNEL_NAME' "
114114
}
115115

116+
# packageChaincode VERSION PEER ORG
117+
packageChaincode() {
118+
VERSION=$1
119+
PEER=$2
120+
ORG=$3
121+
setGlobals $PEER $ORG
122+
set -x
123+
peer lifecycle chaincode package mycc.tar.gz --path ${CC_SRC_PATH} --lang ${LANGUAGE} --label mycc_${VERSION} >&log.txt
124+
res=$?
125+
set +x
126+
cat log.txt
127+
verifyResult $res "Chaincode packaging on peer${PEER}.org${ORG} has failed"
128+
echo "===================== Chaincode is packaged on peer${PEER}.org${ORG} ===================== "
129+
echo
130+
}
131+
132+
# installChaincode PEER ORG
116133
installChaincode() {
117134
PEER=$1
118135
ORG=$2
119136
setGlobals $PEER $ORG
120-
VERSION=${3:-1.0}
121137
set -x
122-
peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >&log.txt
138+
peer lifecycle chaincode install mycc.tar.gz >&log.txt
123139
res=$?
124140
set +x
125141
cat log.txt
@@ -128,45 +144,108 @@ installChaincode() {
128144
echo
129145
}
130146

131-
instantiateChaincode() {
147+
# queryInstalled PEER ORG
148+
queryInstalled() {
132149
PEER=$1
133150
ORG=$2
134151
setGlobals $PEER $ORG
135-
VERSION=${3:-1.0}
152+
set -x
153+
peer lifecycle chaincode queryinstalled >&log.txt
154+
res=$?
155+
set +x
156+
cat log.txt
157+
PACKAGE_ID=`sed -n '/Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt`
158+
verifyResult $res "Query installed on peer${PEER}.org${ORG} has failed"
159+
echo PackageID is ${PACKAGE_ID}
160+
echo "===================== Query installed successful on peer${PEER}.org${ORG} on channel ===================== "
161+
echo
162+
}
163+
164+
# approveForMyOrg VERSION PEER ORG
165+
approveForMyOrg() {
166+
VERSION=$1
167+
PEER=$2
168+
ORG=$3
169+
setGlobals $PEER $ORG
136170

137-
# while 'peer chaincode' command can get the orderer endpoint from the peer
138-
# (if join was successful), let's supply it directly as we know it using
139-
# the "-o" option
140171
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
141172
set -x
142-
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 "AND ('Org1MSP.peer','Org2MSP.peer')" >&log.txt
173+
peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >&log.txt
174+
set +x
175+
else
176+
set -x
177+
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
178+
set +x
179+
fi
180+
cat log.txt
181+
verifyResult $res "Chaincode definition approved on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' failed"
182+
echo "===================== Chaincode definition approved on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
183+
echo
184+
}
185+
186+
# commitChaincodeDefinition VERSION PEER ORG (PEER ORG)...
187+
commitChaincodeDefinition() {
188+
VERSION=$1
189+
shift
190+
parsePeerConnectionParameters $@
191+
res=$?
192+
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
193+
194+
# while 'peer chaincode' command can get the orderer endpoint from the
195+
# peer (if join was successful), let's supply it directly as we know
196+
# it using the "-o" option
197+
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
198+
set -x
199+
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
143200
res=$?
144201
set +x
145202
else
146203
set -x
147-
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 "AND ('Org1MSP.peer','Org2MSP.peer')" >&log.txt
204+
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
148205
res=$?
149206
set +x
150207
fi
151208
cat log.txt
152-
verifyResult $res "Chaincode instantiation on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' failed"
153-
echo "===================== Chaincode is instantiated on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
209+
verifyResult $res "Chaincode definition commit failed on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' failed"
210+
echo "===================== Chaincode definition committed on channel '$CHANNEL_NAME' ===================== "
154211
echo
155212
}
156213

157-
upgradeChaincode() {
158-
PEER=$1
159-
ORG=$2
214+
# queryCommitted VERSION PEER ORG
215+
queryCommitted() {
216+
VERSION=$1
217+
PEER=$2
218+
ORG=$3
160219
setGlobals $PEER $ORG
220+
EXPECTED_RESULT="Version: ${VERSION}, Sequence: ${VERSION}, Endorsement Plugin: escc, Validation Plugin: vscc"
221+
echo "===================== Querying chaincode definition on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME'... ===================== "
222+
local rc=1
223+
local starttime=$(date +%s)
161224

162-
set -x
163-
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 "AND ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
164-
res=$?
165-
set +x
166-
cat log.txt
167-
verifyResult $res "Chaincode upgrade on peer${PEER}.org${ORG} has failed"
168-
echo "===================== Chaincode is upgraded on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
225+
# continue to poll
226+
# we either get a successful response, or reach TIMEOUT
227+
while
228+
test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0
229+
do
230+
sleep $DELAY
231+
echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs"
232+
set -x
233+
peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name mycc >&log.txt
234+
res=$?
235+
set +x
236+
test $res -eq 0 && VALUE=$(cat log.txt | grep -o '^Version: [0-9], Sequence: [0-9], Endorsement Plugin: escc, Validation Plugin: vscc')
237+
test "$VALUE" = "$EXPECTED_RESULT" && let rc=0
238+
done
169239
echo
240+
cat log.txt
241+
if test $rc -eq 0; then
242+
echo "===================== Query chaincode definition successful on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
243+
else
244+
echo "!!!!!!!!!!!!!!! Query chaincode definition result on peer${PEER}.org${ORG} is INVALID !!!!!!!!!!!!!!!!"
245+
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
246+
echo
247+
exit 1
248+
fi
170249
}
171250

172251
chaincodeQuery() {
@@ -293,24 +372,34 @@ parsePeerConnectionParameters() {
293372
PEERS="$(echo -e "$PEERS" | sed -e 's/^[[:space:]]*//')"
294373
}
295374

296-
# chaincodeInvoke <peer> <org> ...
375+
# chaincodeInvoke IS_INIT PEER ORG (PEER ORG) ...
297376
# Accepts as many peer/org pairs as desired and requests endorsement from each
298377
chaincodeInvoke() {
378+
IS_INIT=$1
379+
shift
299380
parsePeerConnectionParameters $@
300381
res=$?
301382
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
302383

384+
if [ "${IS_INIT}" -eq "1" ]; then
385+
CCARGS='{"Args":["Init","a","100","b","100"]}'
386+
INIT_ARG="--isInit"
387+
else
388+
CCARGS='{"Args":["invoke","a","b","10"]}'
389+
INIT_ARG=""
390+
fi
391+
303392
# while 'peer chaincode' command can get the orderer endpoint from the
304393
# peer (if join was successful), let's supply it directly as we know
305394
# it using the "-o" option
306395
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
307396
set -x
308-
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c '{"Args":["invoke","a","b","10"]}' >&log.txt
397+
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS ${INIT_ARG} -c ${CCARGS} >&log.txt
309398
res=$?
310399
set +x
311400
else
312401
set -x
313-
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c '{"Args":["invoke","a","b","10"]}' >&log.txt
402+
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS ${INIT_ARG} -c ${CCARGS} >&log.txt
314403
res=$?
315404
set +x
316405
fi

0 commit comments

Comments
 (0)