diff --git a/shibarium/cometbft.Dockerfile b/shibarium/cometbft.Dockerfile new file mode 100644 index 00000000..cb83e992 --- /dev/null +++ b/shibarium/cometbft.Dockerfile @@ -0,0 +1,25 @@ +# Shibarium heimdall node Dockerfile +# Build from the base heimdall image + copy entrypoint scripts. +# Uses the standard cometbft-node pattern from vibe-node. +# +# Build args: +# CL_IMAGE - base heimdall image (default: shibaone/heimdall) +# CL_VERSION - heimdall version tag +# +# The entrypoint is init.sh which sources cometbft-common.sh and bootstraps +# the node before exec'ing heimdalld start. + +ARG CL_IMAGE=shibaone/heimdall +ARG CL_VERSION=TODO_VERIFY_VERSION + +FROM ${CL_IMAGE}:${CL_VERSION} + +# Copy the shared CometBFT helpers and chain-specific entrypoint +COPY ./scripts/cometbft-common.sh /usr/local/bin/cometbft-common.sh +COPY ./scripts/init.sh /usr/local/bin/init.sh + +# Make init.sh executable +RUN chmod +x /usr/local/bin/init.sh + +# Set entrypoint to our init script +ENTRYPOINT ["init.sh"] diff --git a/shibarium/scripts/init.sh b/shibarium/scripts/init.sh new file mode 100644 index 00000000..2af85089 --- /dev/null +++ b/shibarium/scripts/init.sh @@ -0,0 +1,103 @@ +#!/bin/sh +# Shibarium heimdall node entrypoint — thin bootstrap sourcing cometbft-common.sh. +# +# Bootstraps a heimdalld node: +# 1. source cometbft-common.sh for helpers (ct_*) +# 2. heimdalld init with moniker + chain-id +# 3. fetch genesis.json from GENESIS_URL if set +# 4. patch p2p config (bind 0.0.0.0:PORT, external_address) +# 5. merge seeds from env SEEDS + optional official seed list +# 6. set persistent_peers from env PERSISTENT_PEERS +# 7. enable REST server on :1317 +# 8. bind CometBFT RPC to 0.0.0.0:26657 +# 9. exec heimdalld start --home $CMT_HOME --chain --rest-server +# +# Environment: +# CMT_HOME heimdall home dir (default /root/.heimdalld) +# CHAIN_ID shibarium chain id (109 -> mainnet) +# GENESIS_URL URL to fetch genesis.json +# SEEDS comma-separated seed nodes (optional) +# PERSISTENT_PEERS comma-separated persistent peers (optional) +# IP external IP for p2p advertisement +# MONIKER node moniker (default d${DOMAIN:-local}) +# P2P_PORT p2p port (default 26656) +# +# NOTE: heimdall (bone fork) merged REST/LCD into the daemon, so REST runs +# in-process via --rest-server flag. No separate rest-server subcommand needed. + +set -e + +# Source the shared CometBFT helpers +. /usr/local/bin/cometbft-common.sh + +CMT_HOME="${CMT_HOME:-/root/.heimdalld}" +CHAIN_ID="${CHAIN_ID:-shibarium-mainnet}" +CHAIN="${CHAIN:-mainnet}" +P2P_PORT="${P2P_PORT:-26656}" +MONIKER="${MONIKER:-d${DOMAIN:-local}}" + +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" + +# Step 2: Fetch genesis if GENESIS_URL is set +if [ -n "$GENESIS_URL" ]; then + ct_log "Fetching genesis from $GENESIS_URL" + ct_fetch "$GENESIS_URL" "$CMT_HOME/config/genesis.json" required +fi + +# Step 3: Patch config.toml p2p settings +ct_patch_p2p "$CMT_HOME/config/config.toml" "$IP" "$P2P_PORT" + +# Step 4: Merge seeds from SEEDS env var (comma-separated) + optional official list +ct_merge_seeds "$CMT_HOME/config/config.toml" "$SEEDS" + +# Step 5: Set persistent peers if provided +ct_set_persistent_peers "$CMT_HOME/config/config.toml" "$PERSISTENT_PEERS" + +# Step 6: Set moniker +ct_set_moniker "$CMT_HOME/config/config.toml" "$MONIKER" + +# Step 7: Localize home paths (~/ -> /root/) +ct_localize_home "$CMT_HOME/config" + +# Step 8: Enable REST server on 1317 and bind CometBFT RPC to 0.0.0.0:26657 +# heimdalld (bone fork) uses --rest-server flag to enable in-process REST/LCD. +# The config.toml rpc settings are for CometBFT RPC (26657), not REST. +# REST is configured via --rest-server.addr flag in the start command. + +# Configure CometBFT RPC to bind to all interfaces on 26657 +ct_log "Configuring CometBFT RPC on 0.0.0.0:26657" +if [ -f "$CMT_HOME/config/config.toml" ]; then + sed -i 's|^rpc_laddr = .*|rpc_laddr = "tcp://0.0.0.0:26657"|' "$CMT_HOME/config/config.toml" + 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" +fi + +# Step 9: Seed priv_validator_state if present in config +ct_seed_priv_validator_state "$CMT_HOME" + +ct_log "Bootstrap complete. Starting heimdalld..." + +# Start heimdalld with REST server enabled +# --rest-server enables the in-process REST/LCD server +# --rest-server.addr binds REST to 0.0.0.0:1317 +# --rpc.laddr binds CometBFT RPC to 0.0.0.0:26657 +# --p2p.laddr binds P2P to 0.0.0.0: +exec heimdalld start \ + --home "$CMT_HOME" \ + --chain "$CHAIN" \ + --rest-server \ + --rest-server.addr=0.0.0.0:1317 \ + --rpc.laddr=tcp://0.0.0.0:26657 \ + --p2p.laddr=tcp://0.0.0.0:$P2P_PORT