From 315d00295abc39917ee6e94869126236b4188ab9 Mon Sep 17 00:00:00 2001 From: gaudenzkessler <92718752+gaudenzkessler@users.noreply.github.com> Date: Wed, 23 Feb 2022 13:56:11 +0100 Subject: [PATCH] Connect four demo with 2 workers * increase sleep time for demo * connect-four demo with 2 workers start workers with python script: python local-setup/launch.py local-setup/simple-config.json start demo-script in cli/: ./demo_connect_four_two_workers.sh -p 9985 -A 2090 -B 3090 -m file Cherry-pick: 00f336e Co-authored-by: Gaudenz Kessler --- cli/demo_connect_four.sh | 4 + cli/demo_connect_four_two_workers.sh | 174 +++++++++++++++++++++++++++ local-setup/simple-config.json | 12 +- 3 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 cli/demo_connect_four_two_workers.sh diff --git a/cli/demo_connect_four.sh b/cli/demo_connect_four.sh index 7ddcaddd2f..65dfa24d4c 100644 --- a/cli/demo_connect_four.sh +++ b/cli/demo_connect_four.sh @@ -75,18 +75,22 @@ echo "" echo "* Issue ${BALANCE} tokens to Alice's account" ${CLIENT} trusted set-balance ${ACCOUNTALICE} ${BALANCE} --mrenclave=${MRENCLAVE} --direct echo "" +sleep 1 echo "* Issue ${BALANCE} tokens to Bob's account" ${CLIENT} trusted set-balance ${ACCOUNTBOB} ${BALANCE} --mrenclave=${MRENCLAVE} --direct echo "" +sleep 1 echo "Queue Game for Alice (Player 1)" ${CLIENT} queue-game ${ACCOUNTALICE} echo "" +sleep 1 echo "Queue Game for Bob (Player 2)" ${CLIENT} queue-game ${ACCOUNTBOB} echo "" +sleep 1 echo "waiting" sleep 45 diff --git a/cli/demo_connect_four_two_workers.sh b/cli/demo_connect_four_two_workers.sh new file mode 100644 index 0000000000..977b3d453b --- /dev/null +++ b/cli/demo_connect_four_two_workers.sh @@ -0,0 +1,174 @@ +#!/bin/bash + +# setup: +# build ajuna node with skip-ias-check +# cargo build --release --features skip-ias-check +# +# run ajuna node +# target/release/ajuna --dev --tmp --ws-port --port 30385 --rpc-port +# +# run worker +# rm light_client_db.bin +# rm -r shards +# rm -r sidechain_db +# export RUST_LOG=integritee_service=info,ita_stf=debug +# integritee-service init_shard +# integritee-service shielding-key +# integritee-service signing-key +# integritee-service -P -p -r 3485 run --dev --skip-ra +# +# then run this script + +# usage: +# export RUST_LOG=integritee-cli=info,ita_stf=info +# demo_connect_four.sh -p -A -B -m +# +# if -m is set, the mrenclave will be read from file + +while getopts ":m:p:A:B:" opt; do + case $opt in + m) + READMRENCLAVE=$OPTARG + ;; + p) + NPORT=$OPTARG + ;; + A) + WORKER1PORT=$OPTARG + ;; + B) + WORKER2PORT=$OPTARG + ;; + esac +done + +# using default port if none given as arguments +NPORT=${NPORT:-9944} +WORKER1PORT=${WORKER1PORT:-2000} +WORKER2PORT=${WORKER2PORT:-3000} + +echo "Using node-port ${NPORT}" +echo "Using trusted-worker-1-port ${WORKER1PORT}" +echo "Using trusted-worker-2-port ${WORKER2PORT}" + +BALANCE=1000 + +CLIENTWORKER1="./../bin/integritee-cli -p ${NPORT} -P ${WORKER1PORT}" +CLIENTWORKER2="./../bin/integritee-cli -p ${NPORT} -P ${WORKER2PORT}" + +if [ "$READMRENCLAVE" = "file" ] +then + read MRENCLAVE <<< $(cat ~/mrenclave.b58) + echo "Reading MRENCLAVE from file: ${MRENCLAVE}" +else + # this will always take the first MRENCLAVE found in the registry !! + read MRENCLAVE <<< $($CLIENT list-workers | awk '/ MRENCLAVE: / { print $2; exit }') + echo "Reading MRENCLAVE from worker list: ${MRENCLAVE}" +fi +[[ -z $MRENCLAVE ]] && { echo "MRENCLAVE is empty. cannot continue" ; exit 1; } + +echo "" +echo "* Create account for Alice" +ACCOUNTALICE=//Alice +echo " Alice's account = ${ACCOUNTALICE}" +echo "" + +echo "* Create account for Bob" +ACCOUNTBOB=//Bob +echo " Bob's account = ${ACCOUNTBOB}" +echo "" + +echo "* Issue ${BALANCE} tokens to Alice's account via Worker 1" +${CLIENTWORKER1} trusted set-balance ${ACCOUNTALICE} ${BALANCE} --mrenclave=${MRENCLAVE} --direct +echo "" +sleep 1 + +echo "* Issue ${BALANCE} tokens to Bob's account via Worker 2" +${CLIENTWORKER2} trusted set-balance ${ACCOUNTBOB} ${BALANCE} --mrenclave=${MRENCLAVE} --direct +echo "" +sleep 1 + +echo "Queue Game for Alice (Player 1)" +${CLIENTWORKER1} queue-game ${ACCOUNTALICE} +echo "" +sleep 1 + +echo "Queue Game for Bob (Player 2)" +${CLIENTWORKER2} queue-game ${ACCOUNTBOB} +echo "" +sleep 1 + +echo "waiting" +sleep 45 + +echo "Turn for Alice (Player 1 via Worker 1)" +${CLIENTWORKER1} trusted play-turn ${ACCOUNTALICE} 3 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Bob (Player 2 via Worker 2)" +${CLIENTWORKER2} trusted play-turn ${ACCOUNTBOB} 4 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Alice (Player 1 via Worker 1)" +${CLIENTWORKER1} trusted play-turn ${ACCOUNTALICE} 2 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Bob (Player 2 via Worker 2)" +${CLIENTWORKER2} trusted play-turn ${ACCOUNTBOB} 3 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "waiting" +sleep 5 + +echo "Board after 2 turns (queried by Bob via Worker 2)" +${CLIENTWORKER2} trusted get-board ${ACCOUNTBOB} --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + + +echo "Turn for Alice (Player 1 via Worker 1)" +${CLIENTWORKER1} trusted play-turn ${ACCOUNTALICE} 2 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Bob (Player 2 via Worker 2)" +${CLIENTWORKER2} trusted play-turn ${ACCOUNTBOB} 5 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Alice (Player 1 via Worker 1)" +${CLIENTWORKER1} trusted play-turn ${ACCOUNTALICE} 2 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Bob (Player 2 via Worker 2)" +${CLIENTWORKER2} trusted play-turn ${ACCOUNTBOB} 1 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "waiting" +sleep 5 + +echo "Board after 4 turns (queried by Alice via Worker 1)" +${CLIENTWORKER1} trusted get-board ${ACCOUNTALICE} --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "Turn for Alice (Player 1 via Worker 1)" +${CLIENTWORKER1} trusted play-turn ${ACCOUNTALICE} 2 --direct --mrenclave=${MRENCLAVE} +echo "" +sleep 1 + +echo "waiting" +sleep 5 + +echo "Board after end of game (queried by Alice via Worker 1)" +${CLIENTWORKER2} trusted get-board ${ACCOUNTBOB} --direct --mrenclave=${MRENCLAVE} +echo "" + + + diff --git a/local-setup/simple-config.json b/local-setup/simple-config.json index 743fc1c46d..7ed0a5f4fc 100644 --- a/local-setup/simple-config.json +++ b/local-setup/simple-config.json @@ -1,16 +1,16 @@ { "node": { - "bin": "../integritee-node/target/release/integritee-node", + "bin": "../Ajuna/target/release/ajuna-solo", "flags": [ "--tmp", "--dev", "-lruntime=info", "--ws-port", - "9990", + "9985", "--port", - "30390", + "30385", "--rpc-port", - "8990" + "9995" ] }, "workers": [ @@ -21,7 +21,7 @@ "-P", "2090", "-p", - "9990", + "9985", "-r", "3490", "-w", @@ -41,7 +41,7 @@ "-P", "3090", "-p", - "9990", + "9985", "-r", "3590", "-w",