Skip to content

Commit 07ee58c

Browse files
committed
lean-quickstart: reset nemo db only with --generateGenesis
1 parent b8c32bf commit 07ee58c

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ After validators are up, **Nemo** (Lean consensus block/slot explorer; image `0x
130130

131131
It uses **`LEAN_API_URL`**: a comma-separated list of `http://<validator-ip>:<apiPort>` for **every** entry in `validator-config.yaml` (same IPs/ports as the devnet HTTP APIs). Rows with **empty `enrFields.ip`** are skipped (e.g. placeholder nodes until an IP is set).
132132

133-
- **Ansible deploy:** `sync-nemo-tooling.sh` writes `/etc/nemo/nemo.env`, **clears** `/opt/nemo/data`, runs **`docker pull`** on **`NEMO_IMAGE`** (default `0xpartha/nemo:latest`), then **`docker run --pull=always`** so the registry is checked again before start, and recreates the `nemo` container so SQLite is **always re-initialized** on each sync. When **`NEMO_IMAGE`** is a **multi-arch** manifest that lists the host CPU (`linux/arm64` or `linux/amd64`), the script passes **`--platform`** for that arch so Docker pulls the matching variant (no platform-mismatch warning). For **single-arch** tags, it omits **`--platform`** so pull/run still succeed. Optional **`NEMO_DOCKER_PLATFORM`** overrides the detected platform when the manifest includes it.
134-
- **Local devnet:** Same pull + `--pull=always` behavior; Nemo runs in Docker with `host.docker.internal` and data under `<NETWORK_DIR>/data/nemo-data` (cleared each run).
133+
- **Ansible deploy:** `sync-nemo-tooling.sh` writes `/etc/nemo/nemo.env`, runs **`docker pull`** on **`NEMO_IMAGE`** (default `0xpartha/nemo:latest`), then **`docker run --pull=always`** and recreates the `nemo` container. The SQLite data dir is **cleared only when `spin-node.sh` is run with `--generateGenesis`** (or when you set **`NEMO_RESET_DB=1`** manually). Otherwise the existing DB under **`/opt/nemo/data`** is reused. When **`NEMO_IMAGE`** is a **multi-arch** manifest that lists the host CPU (`linux/arm64` or `linux/amd64`), the script passes **`--platform`** for that arch so Docker pulls the matching variant (no platform-mismatch warning). For **single-arch** tags, it omits **`--platform`** so pull/run still succeed. Optional **`NEMO_DOCKER_PLATFORM`** overrides the detected platform when the manifest includes it.
134+
- **Local devnet:** Same pull + `--pull=always` behavior; Nemo runs in Docker with `host.docker.internal` and data under `<NETWORK_DIR>/data/nemo-data` (wiped only with **`--generateGenesis`**, same as remote).
135135

136136
UI: `http://<tooling-host>:5455` (override with `NEMO_HOST_PORT`). Skip with **`--skip-nemo`** or **`NEMO_SYNC_DISABLED=1`**. Env vars: see `sync-nemo-tooling.sh`.
137137

spin-node.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,9 @@ if [ "$deployment_mode" == "ansible" ]; then
477477
fi
478478

479479
if [ -z "$skipNemo" ]; then
480-
if ! "$scriptDir/sync-nemo-tooling.sh" "$validator_config_file" "$scriptDir" "$sshKeyFile" "$useRoot"; then
480+
_nemo_reset_db=0
481+
[ -n "$generateGenesis" ] && _nemo_reset_db=1
482+
if ! NEMO_RESET_DB="$_nemo_reset_db" "$scriptDir/sync-nemo-tooling.sh" "$validator_config_file" "$scriptDir" "$sshKeyFile" "$useRoot"; then
481483
echo "Warning: Nemo tooling sync failed. Pass --sshKey <path-to-key> if the tooling server requires it, or use --skip-nemo to skip."
482484
fi
483485
fi
@@ -714,10 +716,12 @@ if [ -z "$skipLeanpoint" ]; then
714716
fi
715717
fi
716718

717-
# Nemo explorer: same tooling server (Ansible) or local Docker; fresh DB each deploy unless --skip-nemo
719+
# Nemo explorer: same tooling server (Ansible) or local Docker; DB reset only with --generateGenesis
718720
local_nemo_deployed=0
719721
if [ -z "$skipNemo" ]; then
720-
if "$scriptDir/sync-nemo-tooling.sh" "$validator_config_file" "$scriptDir" "$sshKeyFile" "$useRoot" "$dataDir"; then
722+
_nemo_reset_db=0
723+
[ -n "$generateGenesis" ] && _nemo_reset_db=1
724+
if NEMO_RESET_DB="$_nemo_reset_db" "$scriptDir/sync-nemo-tooling.sh" "$validator_config_file" "$scriptDir" "$sshKeyFile" "$useRoot" "$dataDir"; then
721725
local_nemo_deployed=1
722726
else
723727
echo "Warning: Nemo deploy failed. Pass --sshKey if needed, or --skip-nemo to skip."

sync-nemo-tooling.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# sync-nemo-tooling.sh — Build LEAN_API_URL from validator-config.yaml (all validators +
33
# their apiPort/httpPort), deploy Nemo on the tooling server or locally.
44
#
5-
# On every deploy: SQLite data dir is wiped so Nemo starts with a fresh DB.
5+
# SQLite under the Nemo data dir is wiped only when NEMO_RESET_DB=1 (spin-node sets this when
6+
# --generateGenesis is passed). Otherwise the existing DB is reused.
67
# Image: docker pull NEMO_IMAGE, then docker run --pull=always so :latest is refreshed from the registry.
78
#
89
# Usage:
910
# sync-nemo-tooling.sh <validator_config_file> <script_dir> [ssh_key_file] [use_root] [local_data_dir]
1011
#
1112
# - If local_data_dir (5th arg) is set: run Nemo in Docker locally with host.docker.internal
12-
# (--docker URL generation). Data: <local_data_dir>/nemo-data (cleared each run).
13-
# - Otherwise: rsync env file to tooling server, clear remote data dir, recreate container.
13+
# (--docker URL generation). Data: <local_data_dir>/nemo-data.
14+
# - Otherwise: rsync env file to tooling server, recreate container.
1415
#
1516
# Env (optional):
1617
# TOOLING_SERVER (default: 46.225.10.32)
@@ -29,9 +30,18 @@
2930
# --platform is only passed when the registry manifest lists that architecture
3031
# (multi-arch index). Single-arch images omit it so pull/run still work; publish
3132
# a multi-arch image (see nemo/docker-bake.hcl) to get native pulls without emulation.
33+
# NEMO_RESET_DB If 1 or true: delete SQLite files in the Nemo data dir before start.
34+
# If unset or 0: reuse existing DB. spin-node sets 1 only with --generateGenesis.
3235

3336
set -e
3437

38+
nemo_should_reset_db() {
39+
case "${NEMO_RESET_DB:-0}" in
40+
1 | true | yes) return 0 ;;
41+
*) return 1 ;;
42+
esac
43+
}
44+
3545
# Map kernel machine name to Docker platform (multi-arch images, e.g. 0xpartha/nemo:latest).
3646
nemo_docker_platform_from_uname() {
3747
case "${1:-}" in
@@ -131,7 +141,12 @@ if [ -n "$local_data_dir" ]; then
131141
mkdir -p "$local_data_dir"
132142
nemo_data="$local_data_dir/nemo-data"
133143
mkdir -p "$nemo_data"
134-
rm -rf "${nemo_data:?}/"*
144+
if nemo_should_reset_db; then
145+
rm -rf "${nemo_data:?}/"*
146+
echo "Nemo: cleared local data dir (NEMO_RESET_DB=1)."
147+
else
148+
echo "Nemo: reusing local data dir ${nemo_data} (set NEMO_RESET_DB=1 to wipe)."
149+
fi
135150
env_local="$local_data_dir/nemo.env"
136151
python3 "$convert_script" --write-nemo-env "$env_local" "$validator_config_file" --docker || {
137152
echo "Error: Nemo env generation failed."
@@ -164,7 +179,13 @@ python3 "$convert_script" --write-nemo-env "$out_env" "$validator_config_file" |
164179
}
165180

166181
remote_env_dir=$(dirname "$REMOTE_NEMO_ENV_PATH")
167-
$ssh_cmd "$remote_target" "mkdir -p $remote_env_dir $REMOTE_NEMO_DATA_DIR && rm -rf ${REMOTE_NEMO_DATA_DIR}/*"
182+
if nemo_should_reset_db; then
183+
$ssh_cmd "$remote_target" "mkdir -p $remote_env_dir $REMOTE_NEMO_DATA_DIR && rm -rf ${REMOTE_NEMO_DATA_DIR}/*"
184+
echo "Nemo: cleared remote data dir on $TOOLING_SERVER (NEMO_RESET_DB=1)."
185+
else
186+
$ssh_cmd "$remote_target" "mkdir -p $remote_env_dir $REMOTE_NEMO_DATA_DIR"
187+
echo "Nemo: reusing remote data dir $REMOTE_NEMO_DATA_DIR (set NEMO_RESET_DB=1 to wipe)."
188+
fi
168189
rsync -e "$ssh_cmd" "$out_env" "${remote_target}:${REMOTE_NEMO_ENV_PATH}"
169190

170191
# Remote Docker: match tooling host arch when the registry publishes that variant in a multi-arch manifest.
@@ -173,4 +194,4 @@ remote_plat_args=$(nemo_docker_platform_args_for_machine "$remote_uname")
173194

174195
$ssh_cmd "$remote_target" "docker pull $remote_plat_args $NEMO_IMAGE && docker stop $NEMO_CONTAINER 2>/dev/null || true; docker rm -f $NEMO_CONTAINER 2>/dev/null || true; docker run -d --pull=always $remote_plat_args --name $NEMO_CONTAINER --restart unless-stopped -p ${NEMO_HOST_PORT}:5053 --env-file $REMOTE_NEMO_ENV_PATH -v $REMOTE_NEMO_DATA_DIR:/data $NEMO_IMAGE"
175196

176-
echo "Nemo deployed on $TOOLING_SERVER at port ${NEMO_HOST_PORT} (fresh DB under $REMOTE_NEMO_DATA_DIR, image $NEMO_IMAGE)."
197+
echo "Nemo deployed on $TOOLING_SERVER at port ${NEMO_HOST_PORT} (data $REMOTE_NEMO_DATA_DIR, image $NEMO_IMAGE)."

0 commit comments

Comments
 (0)