Skip to content

Commit

Permalink
kube setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Apr 13, 2020
1 parent f7a3384 commit 28b5370
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 51 deletions.
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
*
!target/x86_64-unknown-linux-musl/release/server
!target/x86_64-unknown-linux-musl/release/prover
!target/x86_64-unknown-linux-musl/release/plonk_step_by_step_prover
!docker/prover/prover-entry.sh
!keys/packed
!docker/nginx/nginx.conf
!bin/load_keys
!bin/
!contracts/build
!js/client/index.html
!js/client/dist
Expand Down
8 changes: 1 addition & 7 deletions bin/k8s-gen-resource-definitions
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ rm -rf etc/kube/gen/$ZKSYNC_ENV
mkdir -p etc/kube/gen/$ZKSYNC_ENV
envsubst < etc/kube/server.yaml > etc/kube/gen/$ZKSYNC_ENV/server.yaml
envsubst < etc/kube/nginx.yaml > etc/kube/gen/$ZKSYNC_ENV/nginx.yaml
envsubst < etc/kube/prover.yaml > etc/kube/gen/$ZKSYNC_ENV/prover.yaml

# Generate and apply secret for env config
. bin/k8s-secret > etc/kube/gen/$ZKSYNC_ENV/secret.yaml

for BLOCK_SIZE_CHUNKS in $(echo $BLOCK_CHUNK_SIZES | sed "s/,/ /g"); do
export BLOCK_SIZE_CHUNKS=$BLOCK_SIZE_CHUNKS
# If BLOCK_SIZE_CHUNKS = 10, then PROVER_CONTAINER_RESOURCES equals to the value of $PROVER_CONTAINER_RESOURCES_10
export PROVER_CONTAINER_RESOURCES=$(eval echo \$PROVER_$(echo -n $BLOCK_SIZE_CHUNKS)_CONTAINER_RESOURCES)
envsubst < etc/kube/prover.yaml > etc/kube/gen/$ZKSYNC_ENV/prover-$BLOCK_SIZE_CHUNKS.yaml
done
15 changes: 6 additions & 9 deletions bin/plonk-setup
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#!/bin/bash

USAGE='Usage: zksync plonk-setup [ check | download ] [monomial | all]
USAGE='Usage: zksync plonk-setup [ check | download ] [monomial | all] [powers]
Used to download and check plonk universal setup files.
Options:
check (default) | download checks or downloads missing setup files for $SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS in your env
check (default) | download checks or downloads missing setup files for powers defined in powers argument
monomial (default) | all chose to download setup files in monomial form or monomial and lagrange form (for current prover lagrange form is not needed)
powers (optional) coma separated setup powers of two to downaload/check
'

set -e

if [ -z $ZKSYNC_ENV ]; then
echo "$USAGE" && exit 1
fi


SETUP_DO_SPACE_DIR=https://universal-setup.ams3.digitaloceanspaces.com
COMMAND=${1:-check}
KEY_TYPE=${2:-monomial}
POWERS=${3-$SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS}
case $KEY_TYPE in
monomial|all)
;;
Expand All @@ -33,7 +30,7 @@ cd $ZKSYNC_HOME
mkdir -p keys/setup && cd keys/setup

download() {
for i in ${SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS//,/ }; do
for i in ${POWERS//,/ }; do
axel -c $SETUP_DO_SPACE_DIR/setup_2%5E$i.key || true #dont download file if it is already there
sleep 1 # to not receive “503 Slow Down”

Expand All @@ -46,7 +43,7 @@ download() {
}

check() {
for i in ${SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS//,/ }; do
for i in ${POWERS//,/ }; do
F1=setup_2"^$i".key
[ -f "$F1" ] || (echo Setup file $F1 not found. && exit 1)
if [ "$1" = "all" ]; then
Expand Down
5 changes: 1 addition & 4 deletions bin/verify-keys
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ pack reverse of unpack

set -e

if [ -z $ZKSYNC_ENV ]; then
echo "$USAGE" && exit 1
fi

COMMAND=${1:-unpack}
VERIFY_KEYS_TARBAL="verify-keys-`basename $KEY_DIR`-account-"$ACCOUNT_TREE_DEPTH"_-balance-$BALANCE_TREE_DEPTH.tar.gz"
cd $ZKSYNC_HOME


unpack() {
[ -f keys/packed/$VERIFY_KEYS_TARBAL ] || (echo Keys file $VERIFY_KEYS_TARBAL not found && exit 1)
tar xf keys/packed/$VERIFY_KEYS_TARBAL
Expand Down
24 changes: 20 additions & 4 deletions docker/prover/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
FROM alpine
RUN apk add --no-cache curl
COPY target/x86_64-unknown-linux-musl/release/prover /bin/
# Docs of env variables used for this image
# to test this locally just run
# docker build -t tmp_prover -f =(f envsubst < ./docker/prover/Dockerfile) .; docker run --rm tmp_prover:latest
#ENV NODE_NAME nodename
#ENV POD_NAME podname
#ENV SUPPORTED_BLOCK_CHUNKS_SIZES $SUPPORTED_BLOCK_CHUNKS_SIZES
#ENV SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS $SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS
#ENV BLOCK_CHUNK_SIZES $BLOCK_CHUNK_SIZES
#ENV KEY_DIR $KEY_DIR
#ENV ACCOUNT_TREE_DEPTH $ACCOUNT_TREE_DEPTH
#ENV BALANCE_TREE_DEPTH $BALANCE_TREE_DEPTH
#ENV PROVER_SERVER_URL $PROVER_SERVER_URL
#ENV REQ_SERVER_TIMEOUT $REQ_SERVER_TIMEOUT
#ENV RUST_BACKTRACE $RUST_BACKTRACE
#ENV RUST_LOG $RUST_LOG
COPY target/x86_64-unknown-linux-musl/release/plonk_step_by_step_prover /bin/
COPY docker/prover/prover-entry.sh /bin/
COPY bin/load_keys /bin/
COPY bin/plonk-setup /bin/
COPY bin/verify-keys /bin/
COPY keys/packed /keys/packed
COPY contracts/build/ /contracts/build/
RUN apk add --no-cache axel
RUN apk add --no-cache axel curl bash

CMD ["prover-entry.sh"]
30 changes: 25 additions & 5 deletions docker/prover/prover-entry.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
#!/bin/sh
#!/bin/bash

# remove quotes for docker-compose
# export KEY_FILES=`echo $KEY_FILES | sed -e 's/"\(.*\)/\1/g' -e 's/"$//g'`
export ZKSYNC_HOME="/"

echo NODE_NAME=$NODE_NAME
echo POD_NAME=$POD_NAME

. /bin/load_keys
echo SUPPORTED_BLOCK_CHUNKS_SIZES=$SUPPORTED_BLOCK_CHUNKS_SIZES
echo SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS=$SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS
echo BLOCK_CHUNK_SIZES=$BLOCK_CHUNK_SIZES


# we donwload only keys used in node (defined by $BLOCK_CHUNK_SIZES)
SUP_CHUNKS_ARR=($(echo $SUPPORTED_BLOCK_CHUNKS_SIZES | tr ',' "\n"))
SUP_CHUNKS_POW=($(echo $SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS | tr ',' "\n"))

REQUIRED_SETUP_POWS=""
for index in ${!SUP_CHUNKS_ARR[*]}; do
for my_size in ${BLOCK_CHUNK_SIZES//,/ }; do
if [ $my_size == ${SUP_CHUNKS_ARR[$index]} ]; then
REQUIRED_SETUP_POWS="$REQUIRED_SETUP_POS,${SUP_CHUNKS_POW[$index]}"
fi
done
done

echo Downloading setup powers $REQUIRED_SETUP_POWS

/bin/plonk-setup download monomial $REQUIRED_SETUP_POWS
/bin/verify-keys unpack

echo key download complete, starting prover

exec prover "$POD_NAME" 2>&1
exec plonk_step_by_step_prover "$POD_NAME" 2>&1
36 changes: 16 additions & 20 deletions etc/kube/prover.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${ZKSYNC_ENV}-prover-${BLOCK_SIZE_CHUNKS}
name: ${ZKSYNC_ENV}-prover-${BLOCK_CHUNK_SIZES}
namespace: ${ZKSYNC_ENV}
labels:
app: ${ZKSYNC_ENV}-prover-${BLOCK_SIZE_CHUNKS}
app: ${ZKSYNC_ENV}-prover-${BLOCK_CHUNK_SIZES}
spec:
selector:
matchLabels:
app: ${ZKSYNC_ENV}-prover-${BLOCK_SIZE_CHUNKS}
app: ${ZKSYNC_ENV}-prover-${BLOCK_CHUNK_SIZES}
template:
metadata:
labels:
app: ${ZKSYNC_ENV}-prover-${BLOCK_SIZE_CHUNKS}
app: ${ZKSYNC_ENV}-prover-${BLOCK_CHUNK_SIZES}
spec:
volumes:
- name: keys-dir
Expand All @@ -28,30 +28,26 @@ spec:
mountPath: /keys
readOnly: false
env:
- name: RUST_BACKTRACE
value: "${RUST_BACKTRACE}"
- name: CONTRACT_ADDR
value: "${CONTRACT_ADDR}"
- name: SUPPORTED_BLOCK_CHUNKS_SIZES
value: "${SUPPORTED_BLOCK_CHUNKS_SIZES}"
- name: SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS
value: "${SUPPORTED_BLOCK_CHUNKS_SIZES_SETUP_POWERS}"
- name: BLOCK_CHUNK_SIZES
value: "${BLOCK_CHUNK_SIZES}"
- name: KEY_DIR
value: "${KEY_DIR}"
- name: TX_BATCH_SIZE
value: "${TX_BATCH_SIZE}"
- name: MAX_OUTSTANDING_TXS
value: "${MAX_OUTSTANDING_TXS}"
- name: DB_POOL_SIZE
value: "${DB_POOL_SIZE}"
- name: ACCOUNT_TREE_DEPTH
value: "${ACCOUNT_TREE_DEPTH}"
- name: BLOCK_SIZE_CHUNKS
value: "${BLOCK_SIZE_CHUNKS}"
- name: KEYS_SPACE_URL
value: "${KEYS_SPACE_URL}"
- name: BALANCE_TREE_DEPTH
value: "${BALANCE_TREE_DEPTH}"
- name: PROVER_SERVER_URL
value: "${PROVER_SERVER_URL}"
- name: REQ_SERVER_TIMEOUT
value: "${REQ_SERVER_TIMEOUT}"
- name: BLOCK_CHUNK_SIZES
value: "${BLOCK_CHUNK_SIZES}"
- name: RUST_BACKTRACE
value: "${RUST_BACKTRACE}"
- name: RUST_LOG
value: "${RUST_LOG}"
- name: NODE_NAME
valueFrom:
fieldRef:
Expand Down

0 comments on commit 28b5370

Please sign in to comment.