Skip to content

Commit

Permalink
feat(sawtooth-ledger): add single sawtooth test ledger image
Browse files Browse the repository at this point in the history
- Enclose starting sawtooth ledger into single container that will fetch and run the entire setup.
- Remove reduntant files, update the readme.
- Add SawtoothTestLedger class to simplify setting the test ledger in jest tests.
- Refactor electricity-trade to generate usage without sawtooth shell patching.
- Refactor electricity-trade to use new sawtooth ledger container and wait until it's healthy.

Closes: hyperledger-cacti#2108

Depends on: hyperledger-cacti#2030

Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH committed Jul 1, 2022
1 parent 54c1e3d commit bb7a75c
Show file tree
Hide file tree
Showing 32 changed files with 519 additions and 2,025 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
"vscc",
"wasm",
"Xdai",
"goquorum"
"goquorum",
"outsh"
],
"dictionaries": [
"typescript,node,npm,go,rust"
Expand Down
19 changes: 8 additions & 11 deletions examples/cactus-example-electricity-trade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ In this example, we use the Sawtooth intkey transaction processor as an applicat
- This script will start all ledger docker containers, networks, and will setup configuration needed to operate the sample app.
- (NOTICE: Before executing the above, your account needs to be added to the docker group (`usermod -a -G docker YourAccount` from root user))
- On success, this should start the following containers:
- `sawtooth-shell-default`
- `sawtooth-settings-tp-default`
- `sawtooth-intkey-tp-python-default`
- `sawtooth-xo-tp-python-default`
- `sawtooth-rest-api-default`
- `sawtooth-devmode-engine-rust-default`
- `sawtooth-validator-default`
- `sawtooth_all_in_one_ledger_1x`
- `geth1`
1. Launch electricity-trade and validators from local `docker-compose.yml` (use separate console for that, docker-compose will block your prompt):
Expand Down Expand Up @@ -131,10 +125,13 @@ In this example, we use the Sawtooth intkey transaction processor as an applicat
```
# Create intkey batch representing electricity usage
Writing to batches.intkey...
# Sumbit electricity usage
batches: 2, batch/sec: 159.92313264955962
{
"link": "http://rest-api:8008/batch_statuses?id=4e85337e170917c138e4f7de44c85c9dea9c5e17916fded672b90adb85a07ca009002580f8629660e26e1117e9ac15f4c1164d9dc05fc77ac8e212672dc5e97a"
}
# Increase usage
{
"link": "http://rest-api:8008/batch_statuses?id=88b4dfa2128c7ad4b646b4fe6be878948f7c17651baf9c6384080a9eaae5036e219c432b46f74331a2d56b80bf2dcc94496ff261d1a941f23210d637badacf14"
}
```
1. (Optional) Check the balance on Ethereum accounts using the following script
Expand Down
4 changes: 2 additions & 2 deletions examples/cactus-example-electricity-trade/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
ports:
- "5140:5140"
networks:
- sawtooth_net
- sawtooth_aio_testnet_1x
- cactus-example-electricity-trade-net
volumes:
- type: bind
Expand Down Expand Up @@ -61,7 +61,7 @@ services:
target: /etc/cactus

networks:
sawtooth_net:
sawtooth_aio_testnet_1x:
external: true
geth1net:
external: true
Expand Down
14 changes: 4 additions & 10 deletions examples/cactus-example-electricity-trade/script-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ echo ">> Remove the config files on your machine"
rm -rf ./etc/cactus/

echo ">> Stop and remove the docker containers"
docker rm -f sawtooth-shell-default \
sawtooth-settings-tp-default \
sawtooth-intkey-tp-python-default \
sawtooth-xo-tp-python-default \
sawtooth-rest-api-default \
sawtooth-devmode-engine-rust-default \
sawtooth-validator-default \
docker rm -f sawtooth_all_in_one_ledger_1x \
geth1 \
cactus-example-electricity-trade-blp \
cactus-example-electricity-trade-ethereum-validator \
cactus-example-electricity-trade-sawtooth-validator \
cmd-socketio-base-dummy

echo ">> Remove docker networks"
docker network rm sawtooth_net \
electricity-trade_default \
electricity-trade_electricity-trade-net \
docker network rm sawtooth_aio_testnet_1x \
cactus-example-electricity-trade_default \
cactus-example-electricity-trade_cactus-example-electricity-trade-net \
geth1net \
geth-testnet_default

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright 2020-2022 Hyperledger Cactus Contributors
# SPDX-License-Identifier: Apache-2.0

echo "# Create intkey batch representing electricity usage"
docker exec -it sawtooth-shell-default intkey create_batch --key-name MI000001 --value-set 50 --value-inc 24
echo "# Create intkey representing electricity usage"
docker exec -t sawtooth_all_in_one_ledger_1x shell intkey set MI000001 50 --url http://rest-api:8008

echo -e "\n# Sumbit electricity usage"
docker exec -it sawtooth-shell-default sawtooth batch submit -f batches.intkey --url http://rest-api:8008
echo "# Increase usage"
docker exec -t sawtooth_all_in_one_ledger_1x shell intkey inc MI000001 24 --url http://rest-api:8008
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ echo -e "\n\n# Destination Eth balance:"
curl localhost:5034/api/v1/bl/balance/9d624f7995e8bd70251f8265f2f9f2b49f169c55

echo -e "\n\n# Electricity usage"
docker exec -it sawtooth-shell-default intkey list --url http://rest-api:8008
docker exec -t sawtooth_all_in_one_ledger_1x shell intkey list --url http://rest-api:8008
16 changes: 13 additions & 3 deletions examples/cactus-example-electricity-trade/script-start-ledgers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ set -e

ROOT_DIR="../.." # Path to cactus root dir
CONFIG_VOLUME_PATH="./etc/cactus" # Docker volume with shared configuration
WAIT_TIME=10 # How often to check container status

export CACTUS_SAWTOOTH_LEDGER_CONTAINER_NAME="sawtooth_all_in_one_ledger_1x"

function start_ethereum_testnet() {
pushd "${ROOT_DIR}/tools/docker/geth-testnet"
Expand All @@ -21,12 +24,19 @@ function copy_ethereum_validator_config() {
}

function start_sawtooth_testnet() {
pushd "${ROOT_DIR}/tools/docker/sawtooth-testnet"
pushd "${ROOT_DIR}/tools/docker/sawtooth-all-in-one"
./script-start-docker.sh
popd

# Patch create_batch with our logic (will generate electricity usage)
docker cp ./tools/create_batch/create_batch3.py sawtooth-shell-default:/usr/lib/python3/dist-packages/sawtooth_intkey/client_cli/create_batch.py
# Wait for fabric cotnainer to become healthy
health_status="$(docker inspect -f '{{.State.Health.Status}}' ${CACTUS_SAWTOOTH_LEDGER_CONTAINER_NAME})"
while ! [ "${health_status}" == "healthy" ]
do
echo "Waiting for sawtooth container... current status => ${health_status}"
sleep $WAIT_TIME
health_status="$(docker inspect -f '{{.State.Health.Status}}' ${CACTUS_SAWTOOTH_LEDGER_CONTAINER_NAME})"
done
echo ">> Sawtooth ${CACTUS_FABRIC_ALL_IN_ONE_VERSION} started."
}

function copy_sawtooth_validator_config() {
Expand Down
Loading

0 comments on commit bb7a75c

Please sign in to comment.