Skip to content

Commit 121a44a

Browse files
nikhil550NIKHIL E GUPTA
andauthored
[FAB-17460] Move High Throughput sample to test network (#112)
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com> Co-authored-by: NIKHIL E GUPTA <negupta@us.ibm.com>
1 parent a2f3a66 commit 121a44a

17 files changed

+167
-180
lines changed

high-throughput/README.md

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,75 +94,56 @@ and assumed to be correct and at minimal risk to either company simply due to Am
9494
must be verified before approval and admittance to the chain.
9595

9696
## How
97-
This sample provides the chaincode and scripts required to run a high-throughput application. For ease of use, it runs on the same network which is brought
98-
up by `byfn.sh` in the `first-network` folder within `fabric-samples`, albeit with a few small modifications. The instructions to build the network
99-
and run some invocations are provided below.
97+
This sample provides the chaincode and scripts required to run a high-throughput application on the Fabric test network.
10098

101-
### Build your network
102-
1. `cd` into the `first-network` folder within `fabric-samples`, e.g. `cd ~/fabric-samples/first-network`
103-
2. Open `docker-compose-cli.yaml` in your favorite editor, and edit the following lines:
104-
* In the `volumes` section of the `cli` container, edit the second line which refers to the chaincode folder to point to the chaincode folder
105-
within the `high-throughput` folder, e.g.
106-
107-
`./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode` -->
108-
`./../high-throughput/chaincode/:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode`
109-
* Again in the `volumes` section, edit the fourth line which refers to the scripts folder so it points to the scripts folder within the
110-
`high-throughput` folder, e.g.
111-
112-
`./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/` -->
113-
`./../high-throughput/scripts/:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/`
99+
### Vendor the chaincode dependencies
100+
1. Change into the chaincode directory, e.g. `cd ~/fabric-samples/high-throughput/chaincode`
101+
2. Vendor the Go dependencies by running the following command: `GO111MODULE=on go mod vendor`
102+
3. The chaincode directory will now contain a `vendor` directory.
114103

115-
* Finally, comment out the `docker exec cli scripts/script.sh` command from the `byfn.sh` script by placing a `#` before it so that the standard BYFN end to end script doesn't run, e.g.
104+
### Start the network
116105

117-
`# docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $CC_SRC_LANGUAGE $CLI_TIMEOUT $VERBOSE`
106+
You can use the `startFabric.sh` script to create an instance of the Fabric test network with a single channel named `mychannel`. The script then deploys the `high-throughput` chaincode to the channel by installing it on the test network peers and committing the chaincode definition to the channel.
118107

119-
3. We can now bring our network up by typing in `./byfn.sh up -c mychannel`
120-
4. Open a new terminal window and enter the CLI container using `docker exec -it cli bash`, all operations on the network will happen within
121-
this container from now on.
108+
Change back into the `high-throughput` directory in `fabic-samples`. Start the network and deploy the chaincode by issuing the following command:
109+
```
110+
./startFabric.sh
111+
```
122112

123-
### Vendor the chaincode dependencies
124-
1. Outside of the CLI container, change into the chaincode directory, e.g. `cd ~/fabric-samples/high-throughput/chaincode`
125-
2. Vendor the Go dependencies by running the following command: `GO111MODULE=on go mod vendor`
126-
3. The chaincode directory will now contain a `vendor` directory.
113+
If successful, you will see messages of the Fabric test network being created and the chaincode being deployed, followed by the execution time of the script:
114+
```
115+
Total setup execution time : 141 secs ...
116+
```
127117

128-
### Install and define the chaincode
129-
1. Once you're in the CLI container run `cd scripts` to enter the `scripts` folder
130-
2. Set-up the environment variables by running `source setclienv.sh`
131-
3. Set-up your channels and anchor peers by running `./channel-setup.sh`
132-
4. Package and install your chaincode by running `./install-chaincode.sh 1`. The only argument is a number representing the chaincode version, every time
133-
you want to install and upgrade to a new chaincode version simply increment this value by 1 when running the command, e.g. `./install-chaincode.sh 2`
134-
5. Define your chaincode on the channel by running `./approve-commit-chaincode.sh 1`. The version argument serves the same purpose as in `./install-chaincode.sh 1`
135-
and should match the version of the chaincode you just installed. This script also invokes the chaincode `Init` function to start the chaincode container.
136-
You can also upgrade the chaincode to a newer version by running `./approve-commit-chaincode.sh 2`.
137-
6. Your chaincode is now installed and ready to receive invocations
118+
The `high-throughput` chaincode is now ready to receive invocations.
138119

139120
### Invoke the chaincode
140-
All invocations are provided as scripts in `scripts` folder; these are detailed below.
121+
All invocations are provided as scripts in `scripts` folder. You can use these scripts to create and remove assets that you put on the ledger.
141122

142123
#### Update
143-
The format for update is: `./update-invoke.sh name value operation` where `name` is the name of the variable to update, `value` is the value to
124+
The format for update is: `./scripts/update-invoke.sh name value operation` where `name` is the name of the variable to update, `value` is the value to
144125
add to the variable, and `operation` is either `+` or `-` depending on what type of operation you'd like to add to the variable. In the future,
145126
multiply/divide operations will be supported (or add them yourself to the chaincode as an exercise!)
146127

147-
Example: `./update-invoke.sh myvar 100 +`
128+
Example: `./scripts/update-invoke.sh myvar 100 +`
148129

149130
#### Get
150131
The format for get is: `./get-invoke.sh name` where `name` is the name of the variable to get.
151132

152-
Example: `./get-invoke.sh myvar`
153-
154-
#### Delete
155-
The format for delete is: `./delete-invoke.sh name` where `name` is the name of the variable to delete.
156-
157-
Example: `./delete-invoke.sh myvar`
133+
Example: `./scripts/get-invoke.sh myvar`
158134

159135
#### Prune
160136
Pruning takes all the deltas generated for a variable and combines them all into a single row, deleting all previous rows. This helps cleanup
161137
the ledger when many updates have been performed.
162138

163-
The format for pruning is: `./prune-invoke.sh name` where `name` is the name of the variable to prune.
139+
The format for pruning is: `./scripts/prune-invoke.sh name` where `name` is the name of the variable to prune.
140+
141+
Example: `./scripts/prune-invoke.sh myvar`
164142

165-
Example: `./prune-invoke.sh myvar`
143+
#### Delete
144+
The format for delete is: `./delete-invoke.sh name` where `name` is the name of the variable to delete.
145+
146+
Example: `./scripts/delete-invoke.sh myvar`
166147

167148
### Test the Network
168149
Two scripts are provided to show the advantage of using this system when running many parallel transactions at once: `many-updates.sh` and
@@ -178,6 +159,14 @@ errors in the peer and orderer logs.
178159
There are two other scripts, `get-traditional.sh`, which simply gets the value of a row in the traditional way, with no deltas, and `del-traditional.sh` will delete an asset in the traditional way.
179160

180161
Examples:
181-
`./many-updates.sh testvar 100 +` --> final value from `./get-invoke.sh testvar` should be 100000
162+
`./scripts/many-updates.sh testvar 100 +` --> final value from `./scripts/get-invoke.sh testvar` should be 100000
163+
164+
`./scripts/many-updates-traditional.sh testvar` --> final value from `./scripts/get-traditional.sh testvar` is undefined
165+
166+
### Clean up
167+
168+
When you are finished using the `high-throughput` chaincode, you can bring down the network and remove any accompanying artifacts using the `networkDown.sh` script.
182169

183-
`./many-updates-traditional.sh testvar` --> final value from `./get-traditional.sh testvar` is undefined
170+
```
171+
./networkDown.sh
172+
```

high-throughput/networkDown.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp All Rights Reserved
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Exit on first error
8+
set -ex
9+
10+
rm -rf bigdatacc.tar.gz log.txt
11+
12+
# Bring the test network down
13+
pushd ../test-network
14+
./network.sh down
15+
popd

high-throughput/scripts/approve-commit-chaincode.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,41 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7+
export CORE_PEER_TLS_ENABLED=true
78

89
echo "========== Query chaincode package ID =========="
9-
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
10-
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
10+
export CORE_PEER_MSPCONFIGPATH=../test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
11+
export CORE_PEER_ADDRESS=localhost:7051
1112
export CORE_PEER_LOCALMSPID="Org1MSP"
12-
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
13+
export CORE_PEER_TLS_ROOTCERT_FILE=../test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
1314
peer lifecycle chaincode queryinstalled >&log.txt
1415
export PACKAGE_ID=`sed -n '/Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt`
1516

1617
echo "========== Approve definition for Org1 =========="
17-
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
18-
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
18+
export CORE_PEER_MSPCONFIGPATH=../test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
19+
export CORE_PEER_ADDRESS=localhost:7051
1920
export CORE_PEER_LOCALMSPID="Org1MSP"
20-
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
21-
peer lifecycle chaincode install ${CC_NAME}.tar.gz
21+
export CORE_PEER_TLS_ROOTCERT_FILE=../test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
22+
peer lifecycle chaincode install bigdatacc.tar.gz
2223

23-
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --package-id ${PACKAGE_ID} --sequence $1
24+
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile ../test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name bigdatacc --version 0 --init-required --package-id ${PACKAGE_ID} --sequence 1
2425

2526
echo "========== Approve definition for Org2 =========="
26-
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
27-
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
27+
export CORE_PEER_MSPCONFIGPATH=../test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
28+
export CORE_PEER_ADDRESS=localhost:9051
2829
export CORE_PEER_LOCALMSPID="Org2MSP"
29-
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
30-
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --package-id ${PACKAGE_ID} --sequence $1
30+
export CORE_PEER_TLS_ROOTCERT_FILE=../test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
31+
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile ../test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name bigdatacc --version 0 --init-required --package-id ${PACKAGE_ID} --sequence 1
3132

32-
. query-status.sh
33+
. scripts/check-commit-readiness.sh
3334

34-
queryStatus $1 0 1 "\"Org1MSP\": true" "\"Org2MSP\": true"
35-
queryStatus $1 0 2 "\"Org1MSP\": true" "\"Org2MSP\": true"
35+
checkCommitReadiness 1 "\"Org1MSP\": true" "\"Org2MSP\": true"
36+
checkCommitReadiness 2 "\"Org1MSP\": true" "\"Org2MSP\": true"
3637

3738

38-
echo "========== Commit the definition the $CHANNEL_NAME =========="
39-
peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID $CHANNEL_NAME --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name $CC_NAME --version $1 --init-required --sequence $1 --waitForEvent --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
39+
echo "========== Commit the definition the mychannel =========="
40+
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile ../test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID mychannel --signature-policy "OR('Org1MSP.peer', 'Org2MSP.peer')" --name bigdatacc --version 0 --init-required --sequence 1 --waitForEvent --peerAddresses localhost:7051 --tlsRootCertFiles ../test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ../test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
4041

4142

4243
echo "========== Invoke the Init function =========="
43-
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n $CC_NAME --isInit -c '{"Args":["Init"]}'
44+
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile ../test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n bigdatacc --isInit -c '{"Args":["Init"]}'

high-throughput/scripts/channel-setup.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)