From ae9e7e8df8e2932e235a89b79c31dc54c47a3cf6 Mon Sep 17 00:00:00 2001 From: Dave Enyeart Date: Fri, 9 Jun 2023 08:48:39 -0400 Subject: [PATCH 1/4] test-network-nano-bash chaincode id and waitForEvent improvements (#1052) - Use calculatepackageid to set CHAINCODE_ID - Use waitForEvent to wait for commit event intead of 2s sleep Signed-off-by: David Enyeart --- test-network-nano-bash/README.md | 12 ++++++----- .../chaincode_interaction.sh | 21 ++++++++----------- .../install&approve&commit_chaincode_peer1.sh | 10 ++++----- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/test-network-nano-bash/README.md b/test-network-nano-bash/README.md index 2095d9be..97993f91 100644 --- a/test-network-nano-bash/README.md +++ b/test-network-nano-bash/README.md @@ -100,10 +100,12 @@ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/cha peer lifecycle chaincode install basic.tar.gz ``` -The chaincode install may take a minute since the `fabric-ccenv` chaincode builder docker image will be downloaded if not already available on your machine. Copy the returned chaincode package ID into an environment variable for use in subsequent commands (your ID may be different): +The chaincode install may take a minute since the `fabric-ccenv` chaincode builder docker image will be downloaded if not already available on your machine. + +Copy the returned chaincode package ID into a `CHAINCODE_ID` environment variable for use in subsequent commands, or better yet use the peer `calculatepackageid` command to set the environment variable: ```shell -export CHAINCODE_ID=basic_1:faaa38f2fc913c8344986a7d1617d21f6c97bc8d85ee0a489c90020cd57af4a5 +export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid basic.tar.gz) && echo $CHAINCODE_ID ``` ## 2. Running the chaincode as a service @@ -121,7 +123,7 @@ cd .. peer lifecycle chaincode install chaincode-external/external-chaincode.tgz ``` -Copy the returned chaincode package ID into an environment variable for use in subsequent commands (your ID may be different): +Set the CHAINCODE_ID environment variable for use in subsequent commands: ```shell export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid chaincode-external/external-chaincode.tgz) && echo $CHAINCODE_ID @@ -172,11 +174,11 @@ Invoke the chaincode to create an asset (only a single endorser is required base Then query the asset, update it, and query again to see the resulting asset changes on the ledger. Note that you need to wait a bit for invoke transactions to complete. ```shell -peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt +peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' -peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt +peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' ``` diff --git a/test-network-nano-bash/chaincode_interaction.sh b/test-network-nano-bash/chaincode_interaction.sh index bc455f7d..44dc0e0f 100755 --- a/test-network-nano-bash/chaincode_interaction.sh +++ b/test-network-nano-bash/chaincode_interaction.sh @@ -1,16 +1,13 @@ #!/usr/bin/env sh - -# The sleep commands were added because the queries depend on each other and have some latency. +# +# SPDX-License-Identifier: Apache-2.0 +# . peer1admin.sh -peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/chaincode_interaction.log 2>&1 -sleep 2 - -peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' >> ./logs/chaincode_interaction.log 2>&1 -sleep 2 - -peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/chaincode_interaction.log 2>&1 -sleep 2 - -peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' >> ./logs/chaincode_interaction.log 2>&1 \ No newline at end of file +{ + peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["CreateAsset","1","blue","35","tom","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt + peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' + peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["UpdateAsset","1","blue","35","jerry","1000"]}' --waitForEvent --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt + peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' +} >> ./logs/chaincode_interaction.log 2>&1 diff --git a/test-network-nano-bash/install&approve&commit_chaincode_peer1.sh b/test-network-nano-bash/install&approve&commit_chaincode_peer1.sh index 1ab1322d..3932afc3 100755 --- a/test-network-nano-bash/install&approve&commit_chaincode_peer1.sh +++ b/test-network-nano-bash/install&approve&commit_chaincode_peer1.sh @@ -5,17 +5,17 @@ # look for binaries in local dev environment /build/bin directory and then in local samples /bin directory export PATH="${PWD}"/../../fabric/build/bin:"${PWD}"/../bin:"$PATH" - - + + . peer1admin.sh # Install Chaincode on Peer1 peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1 >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1 peer lifecycle chaincode install basic.tar.gz >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1 -# Extract the CHAINCODE_ID from the logs -id=$(sed -n '2s/.*Chaincode code package identifier: //p' ./logs/install\&approve\&commit_chaincode_peer_1.log) -export CHAINCODE_ID="$id" +# Set the CHAINCODE_ID from the created chaincode package +CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid basic.tar.gz) +export CHAINCODE_ID # Approve the chaincode using Peer1Admin peer lifecycle chaincode approveformyorg -o 127.0.0.1:6050 --channelID mychannel --name basic --version 1 --package-id "${CHAINCODE_ID}" --sequence 1 --tls --cafile "${PWD}"/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1 From bb98f1e582390c22f097d9a8cc5405c1f8156d15 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Mon, 12 Jun 2023 08:13:10 +0000 Subject: [PATCH 2/4] FSAT: Extend sleep time to stabilize integration test This patch extends the sleep time to wait for starting nginx by following the description on full-stack-asset-transfer-guide/justfile to stabilize the intergration test Signed-off-by: Tatsuya Sato --- .../infrastructure/kind_with_nginx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/full-stack-asset-transfer-guide/infrastructure/kind_with_nginx.sh b/full-stack-asset-transfer-guide/infrastructure/kind_with_nginx.sh index 3b556a22..82bba900 100755 --- a/full-stack-asset-transfer-guide/infrastructure/kind_with_nginx.sh +++ b/full-stack-asset-transfer-guide/infrastructure/kind_with_nginx.sh @@ -98,7 +98,7 @@ EOF function start_nginx() { kubectl apply -k https://github.com/hyperledger-labs/fabric-operator.git/config/ingress/kind - sleep 10 + sleep 20 kubectl wait --namespace ingress-nginx \ --for=condition=ready pod \ From 2c0fe754381c841144313ba476bdaaaf0f30e520 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Mon, 12 Jun 2023 06:53:17 +0000 Subject: [PATCH 3/4] Minor improvements on test-network-nano-bash - Fix typos - Update gitignore Signed-off-by: Tatsuya Sato --- test-network-nano-bash/.gitignore | 1 + test-network-nano-bash/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test-network-nano-bash/.gitignore b/test-network-nano-bash/.gitignore index aec1ab40..ad2d6f78 100644 --- a/test-network-nano-bash/.gitignore +++ b/test-network-nano-bash/.gitignore @@ -3,3 +3,4 @@ crypto-config/ data/ logs/ *.gz +chaincode-external/ diff --git a/test-network-nano-bash/README.md b/test-network-nano-bash/README.md index 97993f91..c968ccce 100644 --- a/test-network-nano-bash/README.md +++ b/test-network-nano-bash/README.md @@ -73,7 +73,7 @@ For BFT consensus type: ./network.sh start -o BFT ``` -After the network has started, use seperate terminals to run peer commands. +After the network has started, use separate terminals to run peer commands. You will need to configure the peer environment for each new terminal. For example to run against peer1, use: @@ -166,7 +166,7 @@ peer lifecycle chaincode commit -o 127.0.0.1:6050 --channelID mychannel --name b **Note:** after following the instructions above, the chaincode will only be installed on peer1 and will only be available in the peer1admin shell. Rerun the `peer lifecycle chaincode install` command in other peer admin shells to install it on the corresponding peer. -You will also need to rerun the `peer lifecycle chaincode approveformyorg` command to use the chaincode on peers in another organisation, e.g. using the peer3admin shell. +You will also need to rerun the `peer lifecycle chaincode approveformyorg` command to use the chaincode on peers in another organization, e.g. using the peer3admin shell. ## Interact with the chaincode @@ -182,11 +182,11 @@ peer chaincode invoke -o 127.0.0.1:6050 -C mychannel -n basic -c '{"Args":["Upda peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' ``` -For your convenience you can run `chaincode_interaction.sh` from peer1admin terminal to make this simple transaction. The ouput of the script is redirected to the logs folder.\ +For your convenience you can run `chaincode_interaction.sh` from peer1admin terminal to make this simple transaction. The output of the script is redirected to the logs folder.\ Congratulations, you have deployed a minimal Fabric network! Inspect the scripts if you would like to see the minimal set of commands that were required to deploy the network. # Stopping the network -If you started the Fabric componentes individually, utilize `Ctrl-C` in the orderer and peer terminal windows to kill the orderer and peer processes. You can run the scripts again to restart the components with their existing data, or run `./generate_artifacts` again to clean up the existing artifacts and data if you would like to restart with a clean environment. +If you started the Fabric components individually, utilize `Ctrl-C` in the orderer and peer terminal windows to kill the orderer and peer processes. You can run the scripts again to restart the components with their existing data, or run `./generate_artifacts` again to clean up the existing artifacts and data if you would like to restart with a clean environment. If you used the `network.sh` script, utilize `Ctrl-C` to kill the orderer and peer processes. You can restart the network with the existing data, or run `./network.sh clean` to remove old data before restarting. From bc3a6bfa05c3f3513225c11cee1be9fd747c6553 Mon Sep 17 00:00:00 2001 From: Pushp Vashisht Date: Tue, 20 Jun 2023 10:47:16 +0530 Subject: [PATCH 4/4] Fix typo (#1048) Signed-off-by: Pushp Vashisht --- .../docs/ApplicationDev/01-FabricGateway.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/full-stack-asset-transfer-guide/docs/ApplicationDev/01-FabricGateway.md b/full-stack-asset-transfer-guide/docs/ApplicationDev/01-FabricGateway.md index 75ba3bc8..8ad2273e 100644 --- a/full-stack-asset-transfer-guide/docs/ApplicationDev/01-FabricGateway.md +++ b/full-stack-asset-transfer-guide/docs/ApplicationDev/01-FabricGateway.md @@ -62,7 +62,7 @@ Notice that the client only needs to interact directly with the Gateway peer. Th For security, client applications should connect only to Gateway peers within their own organization or, if the client's organization does not host their own peers, to Gateway peers of a trusted organization. -The following diagram demonstrates recommended practice for enabling access to an organization cluster through a single endpoint address while maintaining high availability. This use of a load balancer or ingress controller as a proxy in front of a set of internal endpoints is commonly used when deploying Web or Application servers, so this pattern is well established. The gRPC communication between client and Gateway atually uses HTTP/2 as its transport. +The following diagram demonstrates recommended practice for enabling access to an organization cluster through a single endpoint address while maintaining high availability. This use of a load balancer or ingress controller as a proxy in front of a set of internal endpoints is commonly used when deploying Web or Application servers, so this pattern is well established. The gRPC communication between client and Gateway actually uses HTTP/2 as its transport. ![Fabric Gateway deployment](../images/ApplicationDev/fabric-gateway-deployment.png)