shibarium heimdall init.sh: stop injecting rest_server (crash fix) + idempotent init

heimdall crash-looped on 'toml: key rest_server is already defined'. init.sh
inserted 'rest_server = true' after [rpc] on EVERY boot (non-idempotent), piling up
duplicates; rest_server is not a valid CometBFT config.toml key anyway — REST is
enabled by the --rest-server flag in the start command.

- Remove the rest_server / rest_server_addr config injection.
- Self-heal: strip any previously-injected rest_server lines (so already-corrupted
  volumes recover on next boot — no volume wipe needed).
- Guard heimdalld init to first boot only (config.toml absent) so restarts don't
  reset node identity or re-parse the existing config.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #16.
This commit is contained in:
rob
2026-06-20 03:24:37 +00:00
parent fb3dc6214c
commit 39d2fa93e2

View File

@@ -44,11 +44,26 @@ ct_log "Starting heimdalld bootstrap for chain ${CHAIN_ID} (home=${CMT_HOME})"
# Ensure home dir exists
mkdir -p "$CMT_HOME/config" "$CMT_HOME/data"
# Step 1: heimdalld init
ct_log "Running heimdalld init --home $CMT_HOME --chain $CHAIN"
heimdalld init --home "$CMT_HOME" --chain "$CHAIN"
# Self-heal: earlier builds injected `rest_server = true` into config.toml on EVERY
# boot (non-idempotent), accumulating duplicates until heimdalld died on
# "toml: key rest_server is already defined". rest_server is not a valid CometBFT
# config.toml key — REST is enabled by --rest-server in the start command — so strip
# any previously-injected copies before heimdalld reads the config.
if [ -f "$CMT_HOME/config/config.toml" ]; then
sed -i '/^rest_server = true$/d' "$CMT_HOME/config/config.toml"
fi
# Step 2: Fetch genesis if GENESIS_URL is set
# Step 1: heimdalld init — FIRST BOOT ONLY. Re-initializing an existing home resets
# node identity/state and re-parses the existing config; guard on config.toml.
if [ ! -f "$CMT_HOME/config/config.toml" ]; then
ct_log "First boot: heimdalld init --home $CMT_HOME --chain $CHAIN"
heimdalld init --home "$CMT_HOME" --chain "$CHAIN"
sed -i '/^rest_server = true$/d' "$CMT_HOME/config/config.toml" 2>/dev/null || true
else
ct_log "Already initialized — skipping heimdalld init"
fi
# Step 2: Fetch the shibarium (heimdall-109) genesis if GENESIS_URL is set (idempotent).
if [ -n "$GENESIS_URL" ]; then
ct_log "Fetching genesis from $GENESIS_URL"
ct_fetch "$GENESIS_URL" "$CMT_HOME/config/genesis.json" required
@@ -81,10 +96,10 @@ if [ -f "$CMT_HOME/config/config.toml" ]; then
sed -i 's|^cors_allowed_origins = .*|cors_allowed_origins = ["*" ]|' "$CMT_HOME/config/config.toml"
sed -i 's|^cors_allowed_methods = .*|cors_allowed_methods = ["HEAD", "GET", "POST", "OPTIONS"]|' "$CMT_HOME/config/config.toml"
sed -i 's|^cors_allowed_headers = .*|cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"]|' "$CMT_HOME/config/config.toml"
# Enable REST server in config (though --rest-server flag takes precedence)
sed -i 's|^\[rpc\]|[rpc]\nrest_server = true|' "$CMT_HOME/config/config.toml"
# Set REST server address
sed -i 's|^rest_server_addr = .*|rest_server_addr = "0.0.0.0:1317"|' "$CMT_HOME/config/config.toml"
# NOTE: do NOT inject `rest_server` / `rest_server_addr` into config.toml. REST/LCD
# is enabled by the --rest-server / --rest-server.addr flags in the start command
# below; injecting the key duplicates one heimdalld already defines and crashes it
# with "toml: key rest_server is already defined".
fi
# Step 9: Seed priv_validator_state if present in config