Skip to content

Commit

Permalink
Add snapshot download and import support for evm
Browse files Browse the repository at this point in the history
  • Loading branch information
puppetninja committed Sep 13, 2024
1 parent 857e111 commit d8ad4b1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
23 changes: 23 additions & 0 deletions charts/tezos/scripts/evm-snapshot-downloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set -e

TEZ_VAR=/var/tezos
EVM_DATA_DIR="${TEZ_VAR}/evm"
SNAPSHOT_FILE="${EVM_DATA_DIR}/snapshot.gz"

if [ ! -d "${TEZ_VAR}" ]; then
echo "ERROR: /var/tezos doesn't exist. There should be a volume mounted."
exit 1
fi

if [ -e "${EVM_DATA_DIR}/store.sqlite" ]; then
echo "EVM node data is already populated"
exit 0
fi

echo "Couldn't find a pre-existing evm snapshot."

echo "Downloading ${EVM_SNAPSHOT_URL}"
mkdir -p "${EVM_DATA_DIR}"
curl -LfsS ${EVM_SNAPSHOT_URL} | tee >(sha256sum > ${SNAPSHOT_FILE}.sha256sum) > "${SNAPSHOT_FILE}"

chown -R 1000:1000 "${EVM_SNAPSHOT_URL}"
23 changes: 23 additions & 0 deletions charts/tezos/scripts/evm-snapshot-importer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set -ex

TEZ_VAR=/var/tezos
TEZ_BIN=/usr/local/bin
EVM_DATA_DIR="${TEZ_VAR}/evm"
SNAPSHOT_FILE="${EVM_DATA_DIR}/snapshot.gz"

if [ ! -f ${SNAPSHOT_FILE} ]; then
echo "No snapshot to import."
exit 0
fi

if [ -e "${EVM_DATA_DIR}/store.sqlite" ]; then
echo "EVM node data is already populated"
exit 0
fi

"${TEZ_BIN}/octez-evm-node" snapshot import ${SNAPSHOT_FILE} --data-dir ${EVM_DATA_DIR}

echo "List populated data dir of evm "
find ${EVM_DATA_DIR}

rm -rvf ${SNAPSHOT_FILE}
35 changes: 32 additions & 3 deletions charts/tezos/templates/octez-rollup-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ spec:
value: {{ $k }}
{{- end }}
initContainers:
- name: snapshot-downloader
- name: octez-smartrollup-snapshot-downloader
image: "{{ $.Values.tezos_k8s_images.utils }}"
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
command:
Expand All @@ -164,7 +164,7 @@ spec:
env:
- name: SNAPSHOT_URL
value: {{ $v.snapshot_url }}
- name: snapshot-importer
- name: octez-smartrollup-snapshot-importer
image: "{{ $.Values.images.octez }}"
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
command:
Expand All @@ -179,6 +179,35 @@ spec:
env:
- name: NODE_RPC_URL
value: {{ $v.node_rpc_url }}
{{- if $v.evm.snapshot.enabled }}
- name: evm-snapshot-downloader
image: "{{ $.Values.tezos_k8s_images.utils }}"
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
command:
- /bin/sh
volumeMounts:
- mountPath: /var/tezos
name: var-volume
args:
- "-c"
- |
{{ tpl ($.Files.Get "scripts/evm-snapshot-downloader.sh") $ | indent 12 }}
env:
- name: EVM_SNAPSHOT_URL
value: {{ $v.evm.snapshot.url }}
- name: evm-snapshot-importer
image: "{{ $.Values.images.octez }}"
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
command:
- /bin/sh
volumeMounts:
- mountPath: /var/tezos
name: var-volume
args:
- "-c"
- |
{{ tpl ($.Files.Get "scripts/evm-snapshot-importer.sh") $ | indent 12 }}
{{- end }}
- image: {{ $.Values.tezos_k8s_images.utils }}
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
name: config-generator
Expand Down Expand Up @@ -265,4 +294,4 @@ spec:
name: rollup
{{- end }}
{{- end }}
{{- end }}
{{- end }}

0 comments on commit d8ad4b1

Please sign in to comment.