Merge branch 'hyperledger:main' into main

This commit is contained in:
yjwxfq 2023-06-20 15:16:11 +08:00 committed by GitHub
commit af778493f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions

View file

@ -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. 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) ![Fabric Gateway deployment](../images/ApplicationDev/fabric-gateway-deployment.png)

View file

@ -98,7 +98,7 @@ EOF
function start_nginx() { function start_nginx() {
kubectl apply -k https://github.com/hyperledger-labs/fabric-operator.git/config/ingress/kind kubectl apply -k https://github.com/hyperledger-labs/fabric-operator.git/config/ingress/kind
sleep 10 sleep 20
kubectl wait --namespace ingress-nginx \ kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \ --for=condition=ready pod \

View file

@ -3,3 +3,4 @@ crypto-config/
data/ data/
logs/ logs/
*.gz *.gz
chaincode-external/

View file

@ -73,7 +73,7 @@ For BFT consensus type:
./network.sh start -o BFT ./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. You will need to configure the peer environment for each new terminal.
For example to run against peer1, use: For example to run against peer1, use:
@ -100,10 +100,12 @@ peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/cha
peer lifecycle chaincode install basic.tar.gz 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 ```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 ## 2. Running the chaincode as a service
@ -121,7 +123,7 @@ cd ..
peer lifecycle chaincode install chaincode-external/external-chaincode.tgz 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 ```shell
export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid chaincode-external/external-chaincode.tgz) && echo $CHAINCODE_ID export CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid chaincode-external/external-chaincode.tgz) && echo $CHAINCODE_ID
@ -164,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. **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. 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 ## Interact with the chaincode
@ -172,19 +174,19 @@ 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. 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 ```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 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"]}' 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. 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 # 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. 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.

View file

@ -1,16 +1,13 @@
#!/usr/bin/env sh #!/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 . 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 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 query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}' >> ./logs/chaincode_interaction.log 2>&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
sleep 2 peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","1"]}'
} >> ./logs/chaincode_interaction.log 2>&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 >> ./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

View file

@ -13,9 +13,9 @@ export PATH="${PWD}"/../../fabric/build/bin:"${PWD}"/../bin:"$PATH"
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 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 peer lifecycle chaincode install basic.tar.gz >> ./logs/install\&approve\&commit_chaincode_peer_1.log 2>&1
# Extract the CHAINCODE_ID from the logs # Set the CHAINCODE_ID from the created chaincode package
id=$(sed -n '2s/.*Chaincode code package identifier: //p' ./logs/install\&approve\&commit_chaincode_peer_1.log) CHAINCODE_ID=$(peer lifecycle chaincode calculatepackageid basic.tar.gz)
export CHAINCODE_ID="$id" export CHAINCODE_ID
# Approve the chaincode using Peer1Admin # 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 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