Skip to content

Commit

Permalink
[op-geth] v0.2.0 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
VladStarr authored Apr 17, 2024
1 parent 8274dd7 commit e7d3c7a
Show file tree
Hide file tree
Showing 16 changed files with 670 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dysnix/op-geth/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: op-geth
description: Optimism op-geth execution-layer client Helm chart

version: 0.1.5
version: 0.2.0
appVersion: v1.101308.2

keywords:
Expand Down
14 changes: 12 additions & 2 deletions dysnix/op-geth/templates/configmap-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ data:
{{- include (print $.Template.BasePath "/scripts/_readiness.tpl") . | nindent 4 }}
liveness.sh: |-
{{- include (print $.Template.BasePath "/scripts/_liveness.tpl") . | nindent 4 }}
init-download.sh: |-
{{- include (print $.Template.BasePath "/scripts/_init-download.tpl") . | nindent 4 }}
wait-for-sync.sh: |-
{{- include (print $.Template.BasePath "/scripts/_wait-for-sync.tpl") . | nindent 4 }}
init-genesis.sh: |-
{{- include (print $.Template.BasePath "/scripts/_init-genesis.tpl") . | nindent 4 }}
{{- if or .Values.syncToS3.enabled .Values.initFromS3.enabled }}
init-from-s3.sh: |-
{{- include (print $.Template.BasePath "/scripts/_init-from-s3.tpl") . | nindent 4 }}
sync-to-s3.sh: |-
{{- include (print $.Template.BasePath "/scripts/_sync-to-s3.tpl") . | nindent 4 }}
s3-env.sh: |-
{{- include (print $.Template.BasePath "/scripts/_s3-env.tpl") . | nindent 4 }}
s3-cron.sh: |-
{{- include (print $.Template.BasePath "/scripts/_s3-cron.tpl") . | nindent 4 }}
{{- end }}
31 changes: 31 additions & 0 deletions dysnix/op-geth/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if and .Values.syncToS3.enabled .Values.serviceAccount.create }}
{{- $fullName := include "op-geth.fullname" . }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullName }}
labels: {{ include "op-geth.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources:
- configmaps
resourceNames:
- {{ $fullName }}-s3-config
verbs:
- get
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $fullName }}
labels: {{ include "op-geth.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ $fullName }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
name: {{ $fullName }}
apiGroup: rbac.authorization.k8s.io
{{- end }}
12 changes: 12 additions & 0 deletions dysnix/op-geth/templates/s3-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if or .Values.initFromS3.enabled .Values.syncToS3.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "op-geth.fullname" . }}-s3-config
data:
DATA_DIR: {{ tpl .Values.s3config.local.datadir . | quote }}
INITIALIZED_FILE: {{ tpl .Values.s3config.local.initializedFile . | quote }}
SYNC_TO_S3: "False"
S3_BASE_URL: {{ tpl .Values.s3config.remote.baseUrl . }}
FORCE_INIT: {{ ternary "True" "False" .Values.initFromS3.force | quote }}
{{- end }}
45 changes: 45 additions & 0 deletions dysnix/op-geth/templates/s3-cronjob-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{- if .Values.syncToS3.cronjob.enabled -}}
{{- $fullName := print (include "op-geth.fullname" .) "-s3-cronjob" }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $fullName }}
labels: {{ include "op-geth.labels" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $fullName }}
labels: {{ include "op-geth.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources:
- pods
verbs:
- get
- list
- watch
- delete
- apiGroups: [""]
resources:
- configmaps
resourceNames:
- {{ include "op-geth.fullname" . }}-s3-config
verbs:
- get
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $fullName }}
labels: {{ include "op-geth.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
name: {{ $fullName }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: Role
name: {{ $fullName }}
apiGroup: rbac.authorization.k8s.io
{{- end }}
71 changes: 71 additions & 0 deletions dysnix/op-geth/templates/s3-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{{- if .Values.syncToS3.cronjob.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "op-geth.fullname" . }}-sync-to-s3
labels:
{{- include "op-geth.labels" . | nindent 4 }}
spec:
{{- with .Values.syncToS3.cronjob }}
schedule: "{{ .schedule }}"
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
jobTemplate:
metadata:
name: {{ include "op-geth.fullname" $ }}-sync-to-s3
spec:
activeDeadlineSeconds: 60
backoffLimit: 0
template:
metadata:
labels:
{{- include "op-geth.labels" $ | nindent 12 }}
spec:
restartPolicy: OnFailure
{{- with .imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "op-geth.fullname" $ }}-s3-cronjob
{{- with .podSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
containers:
- name: enable-sync-to-s3
image: "{{ .image.repository }}:{{ .image.tag }}"
imagePullPolicy: {{ .image.pullPolicy | quote }}
{{- with .securityContext }}
securityContext:
{{- toYaml . | nindent 14 }}
{{- end }}
command:
- /bin/sh
- /scripts/s3-cron.sh
- enable_sync
- 5s
volumeMounts:
- name: scripts
mountPath: /scripts
{{- with .resources }}
resources:
{{- toYaml . | nindent 14 }}
{{- end }}
volumes:
- name: scripts
configMap:
name: {{ include "op-geth.fullname" $ }}-scripts
{{- end }}
{{- end }}
14 changes: 14 additions & 0 deletions dysnix/op-geth/templates/s3-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if or .Values.initFromS3.enabled .Values.syncToS3.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "op-geth.fullname" . }}-s3-secret
data:
{{- with .Values.s3config.remote }}
{{- if .endpointUrl }}
S3_ENDPOINT_URL: {{ .endpointUrl | toString | b64enc }}
{{- end }}
AWS_ACCESS_KEY_ID: {{ .accessKeyId | toString | b64enc }}
AWS_SECRET_ACCESS_KEY: {{ .secretAccessKey | toString | b64enc }}
{{- end }}
{{- end }}
23 changes: 0 additions & 23 deletions dysnix/op-geth/templates/scripts/_init-download.tpl

This file was deleted.

86 changes: 86 additions & 0 deletions dysnix/op-geth/templates/scripts/_init-from-s3.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env sh
# shellcheck disable=SC2086,SC3037

set -e

. /scripts/s3-env.sh

process_inputs() {
# download even if we are already initialized
if [ "$FORCE_INIT" = "True" ]; then
echo "Force init enabled, existing data will be deleted."
rm -f "$INITIALIZED_FILE"
fi
# check for S3 credentials
if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "S3 credentials are not provided, exiting"; exit 1
fi
}

progress() {
remote_stats=$("$S5CMD" cat "s3://${STATS_URL}")
case $1 in
"start")
while true; do
inodes=$(df -Phi "$DATA_DIR" | tail -n 1 | awk '{print $3}')
size=$(df -P -BG "$DATA_DIR" | tail -n 1 | awk '{print $3}')G
echo -e "$(date -Iseconds) | SOURCE TOTAL ${remote_stats} | DST USED Inodes:\t${inodes} Size:\t${size}"
sleep 2
done &
progress_pid=$! ;;
"stop")
kill "$progress_pid"
progress_pid=0 ;;
"*")
echo "Unknown arg" ;;
esac
}

check_lockfile() {
if "$S5CMD" cat "s3://${LOCKFILE_URL}" >/dev/null 2>&1; then
echo "Found existing lockfile, snapshot might be corrupted. Aborting download.."
exit 1
fi
}

# stop all background tasks
interrupt() {
echo "Got interrupt signal, stopping..."
for i in "$@"; do kill $i; done
}

sync() {
# check if we are already initialized
if [ -f "$INITIALIZED_FILE" ]; then
echo "Blockchain already initialized. Exiting..."
exit 0
fi
# s5cmd does not support "true" sync, it does not save object's timestamps
# so we cleanup local datadir on our own
# https://github.com/peak/s5cmd/issues/532
echo "Cleaning up local data..."
rm -rf "${DATA_DIR}"
mkdir -p "${DATA_DIR}"

echo "Starting download data from S3..."

# handle interruption / termination
trap 'interrupt ${progress_pid}' INT TERM
progress start

# download remote snapshot to an empty datadir
time "$S5CMD" --stat --log error sync "s3://${S3_DATA_DIR}/*" "${DATA_DIR}/"
progress stop

# all done, mark as initialized
touch "$INITIALIZED_FILE"
}


main() {
process_inputs
check_lockfile
sync
}

main
2 changes: 1 addition & 1 deletion dysnix/op-geth/templates/scripts/_liveness.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set -e

AGE_THRESHOLD=$1
STATE_FILE=${2:-"/root/.ethereum/saved_block_number.txt"}
STATE_FILE=${2:-"{{ .Values.config.datadir }}/saved_block_number.txt"}
HTTP_PORT="{{ .Values.config.http.port }}"

if [ -z "${AGE_THRESHOLD}" ] || [ -z "${STATE_FILE}" ]; then
Expand Down
Loading

0 comments on commit e7d3c7a

Please sign in to comment.