Skip to content

Commit 779f8f3

Browse files
committed
[FAB-15649]Fix Fabcar to install Chaincode on all peers
CI Fabcar javascript test fails because a query proposal is sent to a peer which does not have Chaincode. The query handler in fabric-network does not consider if Chaincode is installed on target peers. As a workaround, this CR adds steps installing Chaincode on all peers during the setup. Change-Id: Iaff0c5bde8c54cef12a176b55e13d70173ee8108 Signed-off-by: Yuki Kondo <yuki.kondo@hal.hitachi.com>
1 parent 7c5f5d3 commit 779f8f3

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

fabcar/startFabric.sh

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/user
5050
ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
5151
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
5252

53-
PEER_ORG1="docker exec
53+
PEER0_ORG1="docker exec
5454
-e CORE_PEER_LOCALMSPID=Org1MSP
5555
-e CORE_PEER_ADDRESS=peer0.org1.example.com:7051
5656
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH}
@@ -61,7 +61,18 @@ peer
6161
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
6262
--orderer=orderer.example.com:7050"
6363

64-
PEER_ORG2="docker exec
64+
PEER1_ORG1="docker exec
65+
-e CORE_PEER_LOCALMSPID=Org1MSP
66+
-e CORE_PEER_ADDRESS=peer1.org1.example.com:8051
67+
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH}
68+
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE}
69+
cli
70+
peer
71+
--tls=true
72+
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
73+
--orderer=orderer.example.com:7050"
74+
75+
PEER0_ORG2="docker exec
6576
-e CORE_PEER_LOCALMSPID=Org2MSP
6677
-e CORE_PEER_ADDRESS=peer0.org2.example.com:9051
6778
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH}
@@ -72,28 +83,43 @@ peer
7283
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
7384
--orderer=orderer.example.com:7050"
7485

86+
PEER1_ORG2="docker exec
87+
-e CORE_PEER_LOCALMSPID=Org2MSP
88+
-e CORE_PEER_ADDRESS=peer1.org2.example.com:10051
89+
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH}
90+
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE}
91+
cli
92+
peer
93+
--tls=true
94+
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
95+
--orderer=orderer.example.com:7050"
96+
7597
echo "Packaging smart contract on peer0.org1.example.com"
76-
${PEER_ORG1} lifecycle chaincode package \
98+
${PEER0_ORG1} lifecycle chaincode package \
7799
fabcar.tar.gz \
78100
--path "$CC_SRC_PATH" \
79101
--lang "$CC_RUNTIME_LANGUAGE" \
80102
--label fabcarv1
81103

82104
echo "Installing smart contract on peer0.org1.example.com"
83-
${PEER_ORG1} lifecycle chaincode install \
105+
${PEER0_ORG1} lifecycle chaincode install \
106+
fabcar.tar.gz
107+
108+
echo "Installing smart contract on peer1.org1.example.com"
109+
${PEER1_ORG1} lifecycle chaincode install \
84110
fabcar.tar.gz
85111

86112
echo "Determining package ID for smart contract on peer0.org1.example.com"
87113
REGEX='Package ID: (.*), Label: fabcarv1'
88-
if [[ `${PEER_ORG1} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
114+
if [[ `${PEER0_ORG1} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
89115
PACKAGE_ID_ORG1=${BASH_REMATCH[1]}
90116
else
91117
echo Could not find package ID for fabcarv1 chaincode on peer0.org1.example.com
92118
exit 1
93119
fi
94120

95121
echo "Approving smart contract for org1"
96-
${PEER_ORG1} lifecycle chaincode approveformyorg \
122+
${PEER0_ORG1} lifecycle chaincode approveformyorg \
97123
--package-id ${PACKAGE_ID_ORG1} \
98124
--channelID mychannel \
99125
--name fabcar \
@@ -103,26 +129,29 @@ ${PEER_ORG1} lifecycle chaincode approveformyorg \
103129
--waitForEvent
104130

105131
echo "Packaging smart contract on peer0.org2.example.com"
106-
${PEER_ORG2} lifecycle chaincode package \
132+
${PEER0_ORG2} lifecycle chaincode package \
107133
fabcar.tar.gz \
108134
--path "$CC_SRC_PATH" \
109135
--lang "$CC_RUNTIME_LANGUAGE" \
110136
--label fabcarv1
111137

112138
echo "Installing smart contract on peer0.org2.example.com"
113-
${PEER_ORG2} lifecycle chaincode install fabcar.tar.gz
139+
${PEER0_ORG2} lifecycle chaincode install fabcar.tar.gz
140+
141+
echo "Installing smart contract on peer1.org2.example.com"
142+
${PEER1_ORG2} lifecycle chaincode install fabcar.tar.gz
114143

115144
echo "Determining package ID for smart contract on peer0.org2.example.com"
116145
REGEX='Package ID: (.*), Label: fabcarv1'
117-
if [[ `${PEER_ORG2} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
146+
if [[ `${PEER0_ORG2} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
118147
PACKAGE_ID_ORG2=${BASH_REMATCH[1]}
119148
else
120149
echo Could not find package ID for fabcarv1 chaincode on peer0.org2.example.com
121150
exit 1
122151
fi
123152

124153
echo "Approving smart contract for org2"
125-
${PEER_ORG2} lifecycle chaincode approveformyorg \
154+
${PEER0_ORG2} lifecycle chaincode approveformyorg \
126155
--package-id ${PACKAGE_ID_ORG2} \
127156
--channelID mychannel \
128157
--name fabcar \
@@ -132,7 +161,7 @@ ${PEER_ORG2} lifecycle chaincode approveformyorg \
132161
--waitForEvent
133162

134163
echo "Committing smart contract"
135-
${PEER_ORG1} lifecycle chaincode commit \
164+
${PEER0_ORG1} lifecycle chaincode commit \
136165
--channelID mychannel \
137166
--name fabcar \
138167
--version 1.0 \
@@ -145,15 +174,20 @@ ${PEER_ORG1} lifecycle chaincode commit \
145174
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
146175

147176
echo "Submitting initLedger transaction to smart contract on mychannel"
148-
${PEER_ORG1} chaincode invoke \
177+
echo "The transaction is sent to all of the peers so that chaincode is built before receiving the following requests"
178+
${PEER0_ORG1} chaincode invoke \
149179
-C mychannel \
150180
-n fabcar \
151181
-c '{"function":"initLedger","Args":[]}' \
152182
--waitForEvent \
153183
--waitForEventTimeout 300s \
154184
--peerAddresses peer0.org1.example.com:7051 \
185+
--peerAddresses peer1.org1.example.com:8051 \
155186
--peerAddresses peer0.org2.example.com:9051 \
187+
--peerAddresses peer1.org2.example.com:10051 \
188+
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
156189
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
190+
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE} \
157191
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
158192

159193
cat <<EOF

0 commit comments

Comments
 (0)