forked from AztecProtocol/Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-job
executable file
·50 lines (44 loc) · 1.46 KB
/
run-job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
cd /usr/src/setup-tools
function exit_if_ceremony_changed() {
# Get ceremony state. Retry if not valid json returned.
while : ; do
STATE=$(curl --retry 100 -L -s http://$MPC_SERVER_HOST/api/state)
[ -z $(echo "$STATE" | jq type) ] || break
echo "Bad json: $STATE"
sleep 1
done
# Exit if ceremony changed or completed.
NAME=$(echo $STATE | jq -j .name)
if [ "$NAME" != "$CEREMONYNAME" ]; then
echo "Ceremony name changed. Exiting."
exit 0
fi
CEREMONYSTATE=$(echo $STATE | jq -j .ceremonyState)
if [ "$CEREMONYSTATE" != "RANGE_PROOFS" ]; then
echo "Ceremony state no longer RANGE_PROOFS. Exiting."
exit 0
fi
}
while true; do
JOBNUM=$(curl --retry 100 -f -L -s http://$JOB_SERVER_HOST/job)
if [ "$?" -ne 0 -o -z "$JOBNUM" ]; then
sleep $[RANDOM%10+1]
exit_if_ceremony_changed
continue
fi
echo Computing range polynomial $JOBNUM
START=`date +%s`
echo ./compute_range_polynomial ../setup_db/generator_prep.dat ../setup_db/g1x_prep.dat $JOBNUM $KMAX 5
RESULT=$(./compute_range_polynomial ../setup_db/generator_prep.dat ../setup_db/g1x_prep.dat $JOBNUM $KMAX 5)
if [ "$?" -ne 0 ]; then
sleep 1
continue
fi
END=`date +%s`
exit_if_ceremony_changed
if [ -n "$RESULT" ]; then
curl --retry 100 --retry-delay 10 -L -s -X PUT -d "$RESULT" -H "Content-Type: text/plain" http://$JOB_SERVER_HOST/complete/$JOBNUM > /dev/null
fi
echo "Job $JOBNUM complete in $((END-START))s: $RESULT"
done