Skip to content

Commit

Permalink
Connect four demo with 2 workers
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and cowboy-bebug committed Jun 8, 2022
1 parent 9a18b38 commit 086760e
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cli/demo_connect_four.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
174 changes: 174 additions & 0 deletions cli/demo_connect_four_two_workers.sh
Original file line number Diff line number Diff line change
@@ -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 <NODEPORT> --port 30385 --rpc-port <RPCPORT>
#
# 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 <WORKERPORT> -p <NODEPORT> -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 <NODEPORT> -A <WORKER1PORT> -B <WORKER2PORT> -m <FILENAME>
#
# if -m <FILENAME> is set, the mrenclave will be read from file <FILENAME>

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 ""



12 changes: 6 additions & 6 deletions local-setup/simple-config.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -21,7 +21,7 @@
"-P",
"2090",
"-p",
"9990",
"9985",
"-r",
"3490",
"-w",
Expand All @@ -41,7 +41,7 @@
"-P",
"3090",
"-p",
"9990",
"9985",
"-r",
"3590",
"-w",
Expand Down

0 comments on commit 086760e

Please sign in to comment.