diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d5f47f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,153 @@ +name: CI + +on: + push: + branches: ["main"] + pull_request: + +permissions: + contents: read + +jobs: + validate: + name: Validate Scripts, Compose, and Config Consistency + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check POSIX shell syntax + run: | + for f in morph-node/*.sh; do + echo "Checking syntax: $f" + sh -n "$f" + done + + - name: Run shellcheck + run: shellcheck -S warning morph-node/*.sh + + - name: Validate Docker Compose configs + run: | + docker compose -f morph-node/docker-compose.yml --env-file morph-node/.env config -q + docker compose -f morph-node/docker-compose.yml --env-file morph-node/.env_hoodi config -q + docker compose -f morph-node/docker-compose.reth.yml --env-file morph-node/.env config -q + docker compose -f morph-node/docker-compose.reth.yml --env-file morph-node/.env_hoodi config -q + + - name: Dry-run Makefile targets + run: | + make -C morph-node -n generate-jwt generate-jwt-hoodi \ + download-and-decompress-mainnet-snapshot download-and-decompress-hoodi-snapshot \ + download-and-decompress-mainnet-reth-snapshot download-and-decompress-hoodi-reth-snapshot \ + clean-mainnet-binary clean-hoodi-binary clean-mainnet-reth clean-hoodi-reth \ + stop-reth-node rm-reth-node stop-hoodi-reth-node rm-hoodi-reth-node \ + stop-binary >/dev/null + + - name: Verify JSON, versions, snapshots, and data.zip consistency + run: | + python3 - <<'PY' + import json + import pathlib + import re + import zipfile + + root = pathlib.Path(".") + + # 1. Validate JSON files + json_files = [ + "mainnet/reth-data/static-nodes.json", + "hoodi/reth-data/static-nodes.json", + "mainnet/geth-data/static-nodes.json", + "hoodi/geth-data/static-nodes.json", + "mainnet/geth-data/genesis.json", + "hoodi/geth-data/genesis.json", + "mainnet/node-data/config/genesis.json", + "hoodi/node-data/config/genesis.json", + ] + for rel in json_files: + with (root / rel).open() as fh: + json.load(fh) + print(f"Validated {len(json_files)} JSON files.") + + # 2. Check Docker image tag & Makefile/README RETH_VERSION alignment + compose_geth = (root / "morph-node/docker-compose.yml").read_text() + compose_reth = (root / "morph-node/docker-compose.reth.yml").read_text() + makefile = (root / "morph-node/Makefile").read_text() + readme = (root / "README.md").read_text() + + node_geth = re.search(r"ghcr\.io/morph-l2/node:([0-9A-Za-z._-]+)", compose_geth) + node_reth = re.search(r"ghcr\.io/morph-l2/node:([0-9A-Za-z._-]+)", compose_reth) + assert node_geth and node_reth, "Missing morph-l2/node image tag" + assert node_geth.group(1) == node_reth.group(1), ( + f"Node image tag mismatch: docker-compose.yml={node_geth.group(1)} " + f"vs docker-compose.reth.yml={node_reth.group(1)}" + ) + + reth_img = re.search(r"ghcr\.io/morph-l2/morph-reth:v([0-9A-Za-z._-]+)", compose_reth) + reth_mk = re.search(r"^RETH_VERSION\s*\?=\s*([0-9A-Za-z._-]+)", makefile, re.M) + assert reth_img and reth_mk, "Missing morph-reth version" + assert reth_img.group(1) == reth_mk.group(1), ( + f"Reth version mismatch: docker-compose.reth.yml=v{reth_img.group(1)} " + f"vs Makefile={reth_mk.group(1)}" + ) + assert f"(default `{reth_img.group(1)}`, kept in sync with the image in" in readme, ( + f"README.md default RETH_VERSION out of sync with v{reth_img.group(1)}" + ) + print(f"Versions aligned: node={node_geth.group(1)}, morph-reth=v{reth_img.group(1)}.") + + # 3. Parse README snapshot tables and verify .env / .env_hoodi defaults match + table_rows = {} + row_re = re.compile( + r"^\|\s*\[([^\]]+)\]\(([^)]+)\)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|\s*(\d+)\s*\|$", + re.M, + ) + for name, url, deriv, l1msg, l2base in row_re.findall(readme): + net = "mainnet" if "/mainnet/" in url else "hoodi" + table_rows[(net, name)] = (deriv, l1msg, l2base) + + def parse_env(path: pathlib.Path) -> dict[str, str]: + env = {} + for line in path.read_text().splitlines(): + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + k, v = line.split("=", 1) + env[k.strip()] = v.strip() + return env + + env_mainnet = parse_env(root / "morph-node/.env") + env_hoodi = parse_env(root / "morph-node/.env_hoodi") + + checks = [ + ("mainnet", env_mainnet["MAINNET_SNAPSHOT_NAME"], + (env_mainnet["DERIVATION_START_HEIGHT"], env_mainnet["L1_MSG_START_HEIGHT"], env_mainnet["L2_BASE_HEIGHT"])), + ("mainnet", env_mainnet["MAINNET_RETH_SNAPSHOT_NAME"], + (env_mainnet["RETH_DERIVATION_START_HEIGHT"], env_mainnet["RETH_L1_MSG_START_HEIGHT"], env_mainnet["RETH_L2_BASE_HEIGHT"])), + ("hoodi", env_hoodi["HOODI_SNAPSHOT_NAME"], + (env_hoodi["DERIVATION_START_HEIGHT"], env_hoodi["L1_MSG_START_HEIGHT"], env_hoodi["L2_BASE_HEIGHT"])), + ("hoodi", env_hoodi["HOODI_RETH_SNAPSHOT_NAME"], + (env_hoodi["RETH_DERIVATION_START_HEIGHT"], env_hoodi["RETH_L1_MSG_START_HEIGHT"], env_hoodi["RETH_L2_BASE_HEIGHT"])), + ] + for net, snap, heights in checks: + assert (net, snap) in table_rows, f"{net} snapshot {snap} from env file is not listed in README.md" + assert table_rows[(net, snap)] == heights, ( + f"Height mismatch for {net}/{snap}: env={heights} vs README={table_rows[(net, snap)]}" + ) + print("All .env / .env_hoodi default snapshots and heights match README.md.") + + # 4. Verify data.zip archives are clean and up to date with tracked files + for net in ("mainnet", "hoodi"): + zpath = root / net / "data.zip" + with zipfile.ZipFile(zpath) as zf: + names = zf.namelist() + assert not any(".DS_Store" in n or "__MACOSX" in n for n in names), f"Junk metadata in {zpath}" + for member in ( + "node-data/config/config.toml", + "node-data/config/genesis.json", + "reth-data/static-nodes.json", + ): + assert member in names, f"Missing {member} in {zpath}" + assert zf.read(member) == (root / net / member).read_bytes(), ( + f"{zpath}:{member} diverges from {net}/{member}" + ) + print("Verified mainnet/data.zip and hoodi/data.zip match tracked configs.") + PY diff --git a/.gitignore b/.gitignore index 62c8935..35f5c44 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.idea/ \ No newline at end of file +.idea/ +morph-node/.geth.pid +morph-node/.reth.pid +morph-node/.node.pid \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 8cf7a27..ba5e35c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "morph"] path = morph url = https://github.com/morph-l2/morph.git +[submodule "morph-reth"] + path = morph-reth + url = https://github.com/morph-l2/morph-reth.git diff --git a/README.md b/README.md index a20726a..ce4eca8 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,24 @@ # run-morph-node -`run-morph-node` is a repository designed to facilitate the deployment and management of Morph nodes using Docker. Morph is an innovative platform that enhances Ethereum Layer 2 scalability by combining optimistic rollups and zk technology, aiming to revolutionize consumer blockchain applications. +`run-morph-node` is a repository designed to facilitate the deployment and management of Morph nodes using Docker or standalone binaries. Morph is an innovative platform that enhances Ethereum Layer 2 scalability by combining optimistic rollups and zk technology, aiming to revolutionize consumer blockchain applications. ## Features -- **Dockerized Deployment**: Simplifies the process of setting up Morph nodes using Docker containers. +- **Dockerized & Binary Deployment**: Run Morph nodes via Docker Compose or standalone host binaries. - **Network Support**: Provides configurations for both Mainnet and Hoodi testnet environments. -- **Execution Client Choice**: Run the node with either **geth** (`go-ethereum`) or **reth** (`morph-reth`) as the execution client. -- **Snapshot Synchronization**: Supports synchronizing node data from snapshots to expedite the setup process. +- **Execution Client Choice**: Run the execution layer with **reth** (`morph-reth`, progressively replacing `go-ethereum`) or **geth** (`go-ethereum`). +- **Snapshot Synchronization**: Supports resumable snapshot downloads with automatic SHA-256 verification. ## Prerequisites -Before setting up a Morph node, ensure you have the following installed: - -- **Docker**: Containerization platform to run the node. -- **Docker Compose**: Tool for defining and running multi-container Docker applications. +- **Docker mode**: + - **Docker** and **Docker Compose v2** (`docker compose`; legacy `docker-compose` is used as a fallback). + - `wget`, `tar`, `openssl` (and optionally `pigz` for faster multi-core snapshot extraction). +- **Binary mode**: + - **morph-reth**: either download a pre-built Linux (`x86_64` / `aarch64`) binary with `make download-reth-binary`, or build from source with **Rust >= 1.95**, **Cargo**, `libclang-dev`, and `pkg-config`. + - **morphnode / geth**: **Go >= 1.24** to build from the pinned git submodules. +- **CPU baseline for pre-built `morph-reth` artifacts**: + - Published `ghcr.io/morph-l2/morph-reth` Docker images and Linux `x86_64` GitHub Release binaries are compiled with `x86-64-v3 + pclmulqdq` (Intel Haswell+ / AMD Excavator+). Older x86_64 CPUs (or VMs exposing `qemu64` / `x86-64-v1`) will crash with `SIGILL` and should build from source with `make build-reth`. ## Quick Start @@ -24,201 +28,283 @@ Before setting up a Morph node, ensure you have the following installed: git clone https://github.com/morph-l2/run-morph-node.git ``` -2. **Navigate to the Project Directory**: +2. **Navigate to the Node Directory**: ```bash - cd run-morph-node + cd run-morph-node/morph-node ``` 3. **Configure Environment Variables**: - Edit the `.env` file to set the appropriate values for your setup if needed. For instance, specify the `MORPH_HOME` if you plan to user your specified directory as your node data home. By default, it takes `./mainnet` as the node data home for mainnet network. - -4. **Download and Decompress Snapshot (Optional but Recommended)**: - -- To expedite synchronization, download the latest snapshot: - - ```bash - make download-and-decompress-mainnet-snapshot - ``` - -- For Hoodi testnet, use the corresponding command: - - ```bash - make download-and-decompress-hoodi-snapshot - ``` - -- After downloading the snapshot, you need to manually place the decompressed data files in the appropriate node data directories. Alternatively, use the `quickstart-*` targets (e.g. `make quickstart-mainnet-node`) which handle snapshot download and placement automatically. - - `make download-and-decompress-*` now extracts snapshots under network directories (`../mainnet` or `../hoodi`). - - For example, if the snapshot folder is named `snapshot-20260415-1`, move the directory to the `MORPH_HOME` directories: - ``` - mv ${MORPH_HOME}/snapshot-20260415-1/geth ${MORPH_HOME}/geth-data - mv ${MORPH_HOME}/snapshot-20260415-1/data/* ${MORPH_HOME}/node-data/data - ``` - - - The folder structure will be like - ``` - └── ${MORPH_HOME} - ├── geth-data // data directory for geth - │ └── geth // directory from snapshot/geth - └── node-data // data directory for node - ├── config - │ ├── config.toml - │ └── genesis.json - └── data // data directory from snapshot/node - ``` - - - **Reth uses a different snapshot** (the `*-reth-*` rows in the snapshot - table) with a different execution-client layout. Its tarball contains a - `reth-data/` tree plus the same `data/` for the node. `static-nodes.json` - is not in the snapshot; the `quickstart-*-reth-*` / `setup-snapshot-data-reth` - helpers copy it from `geth-data/` into `reth-data/` for `--trusted-peers`. - For example, if the reth snapshot folder is named `snapshot-archive-reth-20260902-1`, - move the directories into the `MORPH_HOME` directories: - ``` - mv ${MORPH_HOME}/snapshot-archive-reth-20260902-1/reth-data/* ${MORPH_HOME}/reth-data - mv ${MORPH_HOME}/snapshot-archive-reth-20260902-1/data/* ${MORPH_HOME}/node-data/data - ``` - The folder structure will be like - ``` - └── ${MORPH_HOME} - ├── reth-data // data directory for reth - │ ├── db // from snapshot/reth-data - │ ├── static_files // from snapshot/reth-data - │ ├── rocksdb // from snapshot/reth-data - │ ├── morph // from snapshot/reth-data - │ └── static-nodes.json // copied from geth-data, parsed into --trusted-peers - └── node-data // data directory for node - ├── config - │ ├── config.toml - │ └── genesis.json - └── data // data directory from snapshot/node - ``` - - -5. **Run the Node**: - -- Start the node using Docker Compose: - - ```bash - make run-node - ``` - - For Hoodi testnet, run - - ```bash - make run-hoodi-node - ``` - -- This command will set up and run the node based on the configurations specified in your .env file. - -### Running with reth instead of geth - -The node can run with **reth** (`morph-reth`) as its execution client instead of -geth. Reth uses a **separate execution-client data directory** (`${MORPH_HOME}/reth-data`) -and, importantly, a **different snapshot** than geth (see the [Snapshot Information](#snapshot-information) -table — reth snapshots are the `*-reth-*` rows). The `morph-node` (derivation) side -is identical; only the execution client and its snapshot differ. - -- Start a reth-backed node with Docker Compose: - - ```bash - make run-reth-node # mainnet - make run-hoodi-reth-node # hoodi - ``` - - Stop / remove: - - ```bash - make stop-reth-node - make rm-reth-node - ``` - -- Or use a one-command quickstart (downloads the reth snapshot, places the data, and runs): - - ```bash - make quickstart-mainnet-reth-node # mainnet, Docker - make quickstart-hoodi-reth-node # hoodi, Docker - ``` - -- **Binary mode** (build `morph-reth` from source with `cargo`, then run the binaries directly): - - ```bash - make build-reth-all # builds morph-reth + morphnode into ./bin - make run-reth-node-binary # mainnet - make run-hoodi-reth-node-binary # hoodi - make stop-binary # stops geth/reth/morphnode - # or one-command: make quickstart-mainnet-reth-node-binary / quickstart-hoodi-reth-node-binary - ``` - - `build-reth` clones `morph-reth` into `../morph-reth` and checks out a pinned - tag `v$(RETH_VERSION)` (default `1.5.0`, kept in sync with the image in - `docker-compose.reth.yml`) so the binary and Docker paths run the same version. - Bump it in one place with `make set-versions RETH_VERSION=1.4.0 ...` (rewrites the - compose image tag), or build a one-off with `make build-reth RETH_VERSION=1.4.0`. - -`morph-reth` reads the boot nodes from `static-nodes.json` and passes them to -`--trusted-peers` (discovery is disabled). The snapshot does **not** contain -`static-nodes.json`, so the snapshot setup copies it from `${MORPH_HOME}/geth-data/static-nodes.json` -into `${MORPH_HOME}/reth-data/`. The reth launch command used by the entrypoint is: + Edit `.env` (Mainnet) or `.env_hoodi` (Hoodi) if needed. For example, set `MORPH_HOME` (or `RETH_HOME` independently) to store data on an external disk, and replace the public `L1_ETH_RPC` / `L1_BEACON_CHAIN_RPC` defaults with dedicated endpoints for production or validator workloads. -```bash -morph-reth node \ - --chain \ - --datadir $RETH_DATA_DIR \ - --http --http.addr 0.0.0.0 --http.port 8545 --http.corsdomain '*' \ - --http.api web3,eth,txpool,net,trace \ - --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.origins '*' \ - --ws.api web3,eth,txpool,net,trace \ - --authrpc.addr 0.0.0.0 --authrpc.port 8551 --authrpc.jwtsecret /jwt-secret.txt \ - --disable-discovery --nat none \ - --metrics 0.0.0.0:6060 \ - --log.file.directory $LOG_DIR --log.file.filter info \ - --trusted-peers $TRUSTED_PEERS # parsed from static-nodes.json -``` +4. **One-Command Quickstart (Recommended)**: -### Running as a validator (batch verification mode) + Downloads the matching snapshot (with automatic `.sha256` verification), places the data, generates `jwt-secret.txt`, and starts the node: + + ```bash + # morph-reth (Docker) + make quickstart-mainnet-reth-node + make quickstart-hoodi-reth-node + + # go-ethereum (Docker) + make quickstart-mainnet-node + make quickstart-hoodi-node + ``` + +5. **Manual Snapshot Download and Placement (Optional)**: + + - Download and extract the latest **reth** snapshot (verifies `.sha256` automatically; set `SKIP_SHA256_CHECK=1` to bypass): + + ```bash + make download-and-decompress-mainnet-reth-snapshot + make download-and-decompress-hoodi-reth-snapshot + ``` + + - Or download the latest **geth** snapshot: + + ```bash + make download-and-decompress-mainnet-snapshot + make download-and-decompress-hoodi-snapshot + ``` + + - **Reth snapshot layout** (`*-reth-*` rows in the snapshot table): its tarball contains a `reth-data/` tree plus `data/` for `morph-node`. `static-nodes.json` is already tracked in `mainnet/reth-data/` and `hoodi/reth-data/` and parsed into `--trusted-peers`. When placing manually (first `set -a; source .env; set +a` or `.env_hoodi`), clear any previous `node-data/data/` and `node-data/node-data/` contents first so `mv` does not collide with stale directories and `morphnode` starts from the snapshot's L1 heights: + + ```bash + rm -rf ${RETH_HOME}/reth-data/db ${RETH_HOME}/reth-data/static_files \ + ${RETH_HOME}/reth-data/rocksdb ${RETH_HOME}/reth-data/morph \ + ${RETH_HOME}/reth-data/historical-proofs ${RETH_HOME}/reth-data/reth.toml + rm -rf ${RETH_HOME}/node-data/data/* ${RETH_HOME}/node-data/node-data + mv ${RETH_HOME}/snapshot-archive-reth-20261117-1/reth-data/* ${RETH_HOME}/reth-data/ + mv ${RETH_HOME}/snapshot-archive-reth-20261117-1/data/* ${RETH_HOME}/node-data/data/ + ``` + + Directory layout: + + ```text + └── ${RETH_HOME} + ├── reth-data // data directory for morph-reth + │ ├── db // from snapshot/reth-data + │ ├── static_files // from snapshot/reth-data + │ ├── rocksdb // from snapshot/reth-data + │ ├── morph // from snapshot/reth-data (reference index) + │ ├── logs // rotating reth.log files under logs// + │ └── static-nodes.json // tracked in repo, parsed into --trusted-peers + └── node-data // data directory for morph-node + ├── config + │ ├── config.toml + │ └── genesis.json + └── data // data directory from snapshot/data + ``` + + - **Geth snapshot layout**: + + ```bash + rm -rf ${MORPH_HOME}/geth-data/geth ${MORPH_HOME}/node-data/data/* ${MORPH_HOME}/node-data/node-data + mv ${MORPH_HOME}/snapshot-20261117-1/geth ${MORPH_HOME}/geth-data/ + mv ${MORPH_HOME}/snapshot-20261117-1/data/* ${MORPH_HOME}/node-data/data/ + ``` + + Directory layout: + + ```text + └── ${MORPH_HOME} + ├── geth-data // data directory for geth + │ └── geth // directory from snapshot/geth + └── node-data // data directory for morph-node + ├── config + │ ├── config.toml + │ └── genesis.json + └── data // data directory from snapshot/data + ``` + +6. **Run the Node**: + + ```bash + # morph-reth (detached Docker Compose) + make run-reth-node # mainnet + make run-hoodi-reth-node # hoodi + + # go-ethereum (detached Docker Compose) + make run-node # mainnet + make run-hoodi-node # hoodi + ``` + +### Running with `morph-reth` + +`morph-reth` uses a **separate execution-client data directory** (`${RETH_HOME}/reth-data`) and a **different snapshot** than `geth` (the `*-reth-*` rows in the [Snapshot Information](#snapshot-information) table). The `morph-node` consensus/derivation layer is identical, but its `node-data/data` MUST come from the same paired snapshot as `reth-data`. + +- **Docker Compose**: + + ```bash + make run-reth-node # mainnet (detached, sets RETH_UID/RETH_GID to host user) + make run-hoodi-reth-node # hoodi + make stop-reth-node # stops mainnet morph-node first, then morph-reth cleanly + make rm-reth-node + make stop-hoodi-reth-node # stops hoodi stack (when RETH_CONTAINER_NAME differs in .env_hoodi) + make rm-hoodi-reth-node + make clean-mainnet-reth # clean mainnet reth + node DBs (keeps config & static-nodes.json) + make clean-hoodi-reth # clean hoodi reth + node DBs + ``` + + > **Bind-mount permissions on Linux**: the published `ghcr.io/morph-l2/morph-reth` image sets `USER morph-reth` (non-root system UID), while `ghcr.io/morph-l2/node` and `ghcr.io/morph-l2/go-ethereum` default to `root`. All Makefile targets automatically pass host UID/GID (`RETH_UID`/`RETH_GID` for `docker-compose.reth.yml`, `MORPH_UID`/`MORPH_GID` for `docker-compose.yml`) to both the execution client and `morph-node` containers so host bind mounts stay owned by your host user (ensuring `make clean-*`, snapshot updates, and switching between Docker and binary modes work without `Permission denied`). Direct `docker compose` invocations fall back to `0:0` unless overridden. + +- **Binary mode** (pre-built Linux binary or build from the pinned `morph-reth` git submodule): + + ```bash + # Option A (Linux x86_64 / aarch64): download official verified release binary + make download-reth-binary build-morphnode + + # Option B: build both morph-reth and morphnode from source + make build-reth-all + + # Start / stop + make run-reth-node-binary # mainnet + make run-hoodi-reth-node-binary # hoodi + make stop-binary # stops morphnode first, then waits for reth/geth DB flush + + # Or one-command quickstart (builds from source + downloads reth snapshot + runs) + make quickstart-mainnet-reth-node-binary + make quickstart-hoodi-reth-node-binary + ``` + + `build-reth` initializes the `morph-reth` git submodule (`../morph-reth`) and builds the pinned tag `v$(RETH_VERSION)` (default `1.5.0`, kept in sync with the image in `docker-compose.reth.yml`) using the `profiling` Cargo profile (override with `RETH_BUILD_PROFILE=release`). Both `build-reth` and `download-reth-binary` verify the installed binary's `--version` against `RETH_VERSION` and automatically refresh it on version bumps (or when `FORCE_BUILD=1`). Bump all versions together with: + + ```bash + make set-versions GETH_VERSION=2.2.8 NODE_VERSION=0.6.5 RETH_VERSION=1.5.0 + ``` + +- **Launch command & customization**: + + `entrypoint-reth.sh` parses `static-nodes.json` into `--trusted-peers` (with discovery disabled) and launches: -There is no separate validator service anymore — every node self-verifies L1 batches. The -mode is controlled by `DERIVATION_VERIFY_MODE` (`--derivation.verify-mode`) in the env file: + ```bash + morph-reth node \ + --chain \ + --datadir $RETH_DATADIR \ + --ipcdisable \ + --http --http.addr 0.0.0.0 --http.port 8545 --http.corsdomain '*' \ + --http.api "$RETH_HTTP_API" \ + --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.origins '*' \ + --ws.api "$RETH_WS_API" \ + --authrpc.addr 0.0.0.0 --authrpc.port 8551 --authrpc.jwtsecret /jwt-secret.txt \ + --disable-discovery --nat none \ + --metrics 0.0.0.0:6060 \ + --log.file.directory "$LOG_DIR" --log.file.filter "$RETH_LOG_FILTER" \ + --trusted-peers "$TRUSTED_PEERS" \ + $RETH_EXTRA_FLAGS + ``` -- `local` (default): rebuild the blob from local L2 blocks and compare versioned hashes - against L1. No beacon fetch on the happy path. -- `layer1`: pull the L1 beacon blob, decode it, and derive via the engine — equivalent to - the former validator node. + Configurable environment variables in `.env` / `.env_hoodi`: + - `RETH_HTTP_API` / `RETH_WS_API`: default `web3,debug,eth,txpool,net,trace`. Note: in `morph-reth v1.5.0` the `morph_` RPC namespace (`morph_getTransactionHashesByReference`) is registered unconditionally and `"morph"` is rejected by `--http.api`/`--ws.api`. When upgrading to a release containing `morph-reth` PR #241 (`>v1.5.0`), append `,morph` to `RETH_HTTP_API` / `RETH_WS_API` to keep `morph_` methods enabled. + - `RETH_EXTRA_FLAGS`: extra CLI flags appended verbatim to `morph-reth node` (e.g. `--full`, `--txpool.*`, `--engine.persistence-threshold`). + - `RETH_LOG_FILTER`: rotating log file filter (default `info`, written under `reth-data/logs//reth.log`). + - `RETH_METRICS_PORT` / `RETH_P2P_PORT` / `RETH_RPC_PORT` / `RETH_WS_PORT`: host port bindings for Docker Compose (Prometheus metrics on `6060` work with the unified Grafana dashboard shipped in `morph-reth/etc/`). -`L1_BEACON_CHAIN_RPC` is required in **both** modes — the node exits at startup without it. -`local` just doesn't fetch the blob on the happy path; `layer1` fetches it every batch. +- **Storage & pruning constraint**: -`layer1` is what the former validator node did. Two ways to enable it: + `morph-reth` runs in archive mode by default, matching `snapshot-archive-reth-*`. Do **not** pass `--minimal` or `--prune.bodies.*` in `RETH_EXTRA_FLAGS`: Morph's mandatory reference index requires canonical block bodies from Jade onward, and `morph-reth` refuses to start if bodies-history pruning is configured. -- **Validator commands** (kept for backward compatibility): `make run-validator` / - `make run-hoodi-validator` (or the `-binary` variants) run the single node in `layer1` - mode. Stop/remove with `make stop-validator` / `make rm-validator` (aliases of - `make stop-node` / `make rm-node`). -- **Env var:** set `DERIVATION_VERIFY_MODE=layer1` in `.env` / `.env_hoodi`, then `make run-node`. +- **Historical proofs (`--proofs-history`, optional for prover-facing nodes)**: -There is no separate validator container anymore — both paths run the same `morph-node`. + Set `RETH_PROOFS_HISTORY=true` (and optionally `RETH_PROOFS_WINDOW`, `RETH_PROOF_PERMITS`) in `.env` / `.env_hoodi` **only on a restored post-Jade paired snapshot** (never an empty DB). `entrypoint-reth.sh` verifies `${RETH_DATADIR}/db` exists, idempotently runs `morph-reth proofs init`, and launches `morph-reth node --proofs-history`. -> `L1_SEQUENCER_CONTRACT` and `CONSENSUS_SWITCH_HEIGHT` are hardcoded per-network defaults -> in the binary and must not be set as operator config. + On first start, `proofs init` copies the full state at the current tip into `reth-data/historical-proofs`; on mainnet this can take a long time (progress and ETA are logged as `Processed entries`). The engine RPC only opens after it finishes, so binary mode (`run-binary-reth.sh`) waits without a timeout when `RETH_PROOFS_HISTORY=true` (set `RETH_READY_TIMEOUT=` to bound it), and in Docker the healthcheck reports `unhealthy` until then (the container is not restarted). Init is resumable: stopping during init (Ctrl+C, `make stop-binary`, `docker stop`) interrupts it cleanly and the next start continues from the last committed batch, as long as the chain tip has not moved in between. If the node was run without `RETH_PROOFS_HISTORY` after an interrupted init, delete `reth-data/historical-proofs` before enabling it again. + +### Running with `go-ethereum` (`geth`) + +- **Docker Compose**: + + ```bash + make run-node # mainnet (detached, sets MORPH_UID/MORPH_GID to host user) + make run-hoodi-node # hoodi + make stop-node # stops morph-node first, then morph-geth cleanly + make rm-node + make clean-mainnet-binary # clean mainnet geth + node DBs (keeps config & static-nodes.json) + make clean-hoodi-binary # clean hoodi geth + node DBs + ``` + +- **Binary mode** (build `geth` + `morphnode` from the pinned git submodules): + + ```bash + make build # builds ./bin/geth and ./bin/morphnode + make run-node-binary # mainnet + make run-hoodi-node-binary # hoodi + make stop-binary # stops morphnode first, then waits for geth DB flush + + # Or one-command quickstart (builds + downloads geth snapshot + runs) + make quickstart-mainnet-node-binary + make quickstart-hoodi-node-binary + ``` + +### Migrating from `geth` to `morph-reth` + +Because `morph-reth` and `geth` use different snapshot formats and their EL state must stay locked to `morph-node`'s `node-data/data` at the exact same block height, do **not** point `morph-reth` at a `geth` datadir or reuse `node-data/data` from a running `geth` node. + +- **Option A — In-place cutover**: + + 1. Stop and remove the `geth` stack: `make stop-node && make rm-node` (or `make stop-binary`). + 2. Clean old snapshot data (keeps `config.toml`, `genesis.json`, `static-nodes.json`): `make clean-mainnet-binary` (or `make clean-hoodi-binary`). + 3. Bootstrap and start `morph-reth` with its paired snapshot: `make quickstart-mainnet-reth-node` (or `make quickstart-hoodi-reth-node`). Note: `setup-snapshot-data-reth` also safely replaces any leftover `node-data/data/*` and `node-data/node-data` automatically. + 4. Once verified, you can reclaim disk space from `${MORPH_HOME}/geth-data/geth`. + +- **Option B — Side-by-side / shadow run before cutting over traffic**: + + Use distinct `RETH_HOME`, `JWT_SECRET_FILE`, ports, container names, and `COMPOSE_PROJECT_NAME` so `morph-reth` runs alongside an existing `geth` node without collisions: + + ```bash + # 1. One-command bootstrap + foreground shadow run (creates jwt-secret.txt, + # copies config/static-nodes.json, restores the reth snapshot, and starts both containers): + make quickstart-mainnet-reth-node \ + RETH_HOME=/data/morph-mainnet-reth \ + JWT_SECRET_FILE=/data/morph-mainnet-reth/jwt-secret.txt \ + RETH_RPC_PORT=18545 RETH_WS_PORT=18546 RETH_METRICS_PORT=16060 RETH_P2P_PORT=30304 \ + RETH_CONTAINER_NAME=morph-reth-shadow RETH_NODE_CONTAINER_NAME=morph-node-shadow \ + COMPOSE_PROJECT_NAME=morph-reth-shadow + + # 2. Or, after bootstrapping RETH_HOME and jwt-secret.txt, run detached: + RETH_UID=$(id -u) RETH_GID=$(id -g) \ + RETH_HOME=/data/morph-mainnet-reth \ + JWT_SECRET_FILE=/data/morph-mainnet-reth/jwt-secret.txt \ + RETH_RPC_PORT=18545 RETH_WS_PORT=18546 RETH_METRICS_PORT=16060 RETH_P2P_PORT=30304 \ + RETH_CONTAINER_NAME=morph-reth-shadow RETH_NODE_CONTAINER_NAME=morph-node-shadow \ + COMPOSE_PROJECT_NAME=morph-reth-shadow \ + docker compose -f docker-compose.reth.yml --env-file .env up -d node + + # 3. Stop and remove only the shadow stack (do NOT run plain `make stop-reth-node`, + # which targets the default `morph-node`/`morph-reth` container names): + make stop-reth-node rm-reth-node \ + RETH_CONTAINER_NAME=morph-reth-shadow RETH_NODE_CONTAINER_NAME=morph-node-shadow + ``` + +### Running as a validator (batch verification mode) + +There is no separate validator service anymore — every node self-verifies L1 batches. The mode is controlled by `DERIVATION_VERIFY_MODE` (`--derivation.verify-mode`) in the env file: + +- `local` (default): rebuild the blob from local L2 blocks and compare versioned hashes against L1. No beacon fetch on the happy path. +- `layer1`: pull the L1 beacon blob, decode it, and derive via the engine — equivalent to the former validator node. + +`L1_BEACON_CHAIN_RPC` is required in **both** modes — the node exits at startup without it, and it must point to an L1 **Beacon REST API** (`/eth/v1/beacon/...`), not an L1 execution JSON-RPC URL. + +Two ways to enable `layer1` mode: + +- **Validator commands** (reth and geth): + - **Reth (Docker)**: `make run-reth-validator` / `make run-hoodi-reth-validator` (stop/remove: `make stop-reth-validator` / `make rm-reth-validator`). + - **Reth (Binary)**: `make run-reth-validator-binary` / `make run-hoodi-reth-validator-binary`. + - **Geth (Docker / Binary)**: `make run-validator` / `make run-hoodi-validator` (or `-binary`; stop/remove: `make stop-validator` / `make rm-validator`). +- **Env var**: set `DERIVATION_VERIFY_MODE=layer1` in `.env` / `.env_hoodi`, then run `make run-reth-node` (or `make run-node`). + +> `L1_SEQUENCER_CONTRACT` and `CONSENSUS_SWITCH_HEIGHT` are hardcoded per-network defaults in the binary and must not be set as operator config. ## Snapshot Information -The table below provides the node snapshot data and corresponding download URLs. Ensure `DERIVATION_START_HEIGHT`, `L1_MSG_START_HEIGHT`, and `L2_BASE_HEIGHT` in `.env`/`.env_hoodi` match the selected snapshot. +The table below provides the node snapshot data and corresponding download URLs. Ensure the snapshot name and heights in `.env`/`.env_hoodi` match the selected snapshot. -> **geth vs reth snapshots:** rows whose name contains `reth` (e.g. `snapshot-archive-reth-*`) -> are for the **reth** execution client and must be used with the `*-reth-*` make targets; -> the other rows are **geth** snapshots. The two are not interchangeable. Set -> `MAINNET_SNAPSHOT_NAME`/`HOODI_SNAPSHOT_NAME` for geth and -> `MAINNET_RETH_SNAPSHOT_NAME`/`HOODI_RETH_SNAPSHOT_NAME` for reth in the env files. +> **geth vs reth snapshots:** rows whose name contains `reth` (e.g. `snapshot-archive-reth-*`) are for the **reth** execution client and must be used with the `*-reth-*` make targets; the other rows are **geth** snapshots. The two are not interchangeable. Set `MAINNET_SNAPSHOT_NAME`/`HOODI_SNAPSHOT_NAME` for geth and `MAINNET_RETH_SNAPSHOT_NAME`/`HOODI_RETH_SNAPSHOT_NAME` for reth in the env files. > -> Because the two clients use different snapshots, the height variables are also split: -> the geth path uses `DERIVATION_START_HEIGHT`/`L1_MSG_START_HEIGHT`/`L2_BASE_HEIGHT`, and -> the reth path uses `RETH_DERIVATION_START_HEIGHT`/`RETH_L1_MSG_START_HEIGHT`/`RETH_L2_BASE_HEIGHT`. -> Ensure each set matches the height row of its selected snapshot. +> Because the two clients use different snapshots, the height variables are also split: the geth path uses `DERIVATION_START_HEIGHT`/`L1_MSG_START_HEIGHT`/`L2_BASE_HEIGHT`, and the reth path uses `RETH_DERIVATION_START_HEIGHT`/`RETH_L1_MSG_START_HEIGHT`/`RETH_L2_BASE_HEIGHT`. Ensure each set matches the height row of its selected snapshot. -**For mainnet** (reth is currently in an internal testing phase and is not yet recommended for production use): +**For mainnet**: | Snapshot Name | Derivation Start Height | L1 Msg Start Height | L2 Base Height | |:--------------------------------------------------------------------------------------|:------------------------|:--------------------|:---------------| @@ -232,7 +318,7 @@ The table below provides the node snapshot data and corresponding download URLs. | [snapshot-20261017-1](https://snapshot.morph.network/mainnet/snapshot-20261017-1.tar.gz) | 26208397 | 26205946 | 28394410 | | [snapshot-archive-reth-20261017-1](https://snapshot.morph.network/mainnet/snapshot-archive-reth-20261017-1.tar.gz) | 26208397 | 26205946 | 28394410 | -**For hoodi testnet** (reth is currently in an internal testing phase and is not yet recommended for production use): +**For hoodi testnet**: | Snapshot Name | Derivation Start Height | L1 Msg Start Height | L2 Base Height | |:------------------------------------------------------------------------------------|:------------------------|:--------------------|:---------------| @@ -248,27 +334,18 @@ The table below provides the node snapshot data and corresponding download URLs. ## Verifying Snapshot Integrity -Each snapshot has a SHA-256 checksum file at the same URL with a `.sha256` -suffix. Compute the hash and compare it against the `.sha256` file — use -whichever command is available on your system: +The `Makefile` download and `quickstart-*` targets automatically fetch the `.sha256` checksum file alongside each snapshot and verify it before extraction (set `SKIP_SHA256_CHECK=1` to bypass). For manual downloads, compute the hash and compare it against the `.sha256` file: ```bash +sha256sum snapshot.tar.gz +# or shasum -a 256 snapshot.tar.gz # or openssl dgst -sha256 snapshot.tar.gz ``` ## Documentation -For detailed information on Morph and its ecosystem, refer to the official documentation: - -- [Morph Documentation](https://morphl2.io) - -By following these steps, you can set up and run a Morph node efficiently using Docker. For any questions or support, please refer to the official Morph community channels. - - - - - - +For detailed information on Morph and its ecosystem, refer to the official documentation: +- [Morph Documentation](https://docs.morph.network/) diff --git a/go-ethereum b/go-ethereum index 5744b8f..1c528b3 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 5744b8f66ec4070a535ed12200db48028df29d93 +Subproject commit 1c528b351da0c205eae0ea5e16f5053c2dd67eca diff --git a/hoodi/data.zip b/hoodi/data.zip index 7acd0e6..742808f 100644 Binary files a/hoodi/data.zip and b/hoodi/data.zip differ diff --git a/hoodi/geth-data/genesis.json b/hoodi/geth-data/genesis.json index c7827a8..302e448 100644 --- a/hoodi/geth-data/genesis.json +++ b/hoodi/geth-data/genesis.json @@ -21,9 +21,10 @@ "viridianTime": 1761544800, "emeraldTime": 1766988000, "jadeForkTime": 1774418400, + "celadonTime": 1793167200, "morph": { "useZktrie": false, - "maxTxPayloadBytesPerBlock": 122880, + "maxTxPayloadBytesPerBlock": 737280, "feeVaultAddress": "0x29107cb79ef8f69fe1587f77e283d47e84c5202f" }, "scroll": {} diff --git a/mainnet/data.zip b/mainnet/data.zip index 5ed17dc..e31ae2d 100644 Binary files a/mainnet/data.zip and b/mainnet/data.zip differ diff --git a/mainnet/geth-data/genesis.json b/mainnet/geth-data/genesis.json index 247f17d..2ae14aa 100644 --- a/mainnet/geth-data/genesis.json +++ b/mainnet/geth-data/genesis.json @@ -20,11 +20,12 @@ "viridianTime": 1762149600, "emeraldTime": 1767765600, "jadeForkTime": 1775628000, + "celadonTime": 1793772000, "terminalTotalDifficulty": 0, "morph": { "useZktrie": false, "maxTxPerBlock": 100, - "maxTxPayloadBytesPerBlock": 122880, + "maxTxPayloadBytesPerBlock": 737280, "feeVaultAddress": "0x530000000000000000000000000000000000000a" } }, diff --git a/morph b/morph index 5edbc69..c6f1e14 160000 --- a/morph +++ b/morph @@ -1 +1 @@ -Subproject commit 5edbc693d4edc72597b444a9b75424661fd536cf +Subproject commit c6f1e14f242b006996223d9b957a37493b995eab diff --git a/morph-node/.env b/morph-node/.env index 6032a50..86e004a 100644 --- a/morph-node/.env +++ b/morph-node/.env @@ -2,35 +2,76 @@ MORPH_HOME=../mainnet MORPH_FLAG=morph JWT_SECRET_FILE=${MORPH_HOME}/jwt-secret.txt GETH_ENTRYPOINT_FILE=./entrypoint-geth.sh -MAINNET_SNAPSHOT_NAME=snapshot-20260701-1 +MAINNET_SNAPSHOT_NAME=snapshot-20261117-1 -## Reth execution client (alternative to geth). Reth uses a SEPARATE snapshot +## Reth execution client (morph-reth). Reth uses a SEPARATE snapshot ## (reth-data/ tree) and a separate data directory (${RETH_HOME}/reth-data), -## but shares the same network home dir and node-data with the geth flow. +## but shares the same network home dir and node-data by default. Set a +## distinct RETH_HOME (plus port/container overrides below) to run side by side +## with geth during migration. RETH_HOME=${MORPH_HOME} RETH_CHAIN=mainnet RETH_ENTRYPOINT_FILE=./entrypoint-reth.sh -MAINNET_RETH_SNAPSHOT_NAME=snapshot-archive-reth-20260902-1 +MAINNET_RETH_SNAPSHOT_NAME=snapshot-archive-reth-20261117-1 # Reth uses a SEPARATE snapshot from geth, so it needs its own heights. These must # match MAINNET_RETH_SNAPSHOT_NAME above (see the README snapshot table). The reth # compose/binary paths use these instead of the shared DERIVATION_*/L1_MSG_*/L2_BASE_* # below (which track the geth snapshot). -RETH_DERIVATION_START_HEIGHT=25885664 -RETH_L1_MSG_START_HEIGHT=25880870 -RETH_L2_BASE_HEIGHT=26137782 +RETH_DERIVATION_START_HEIGHT=26430867 +RETH_L1_MSG_START_HEIGHT=26425693 +RETH_L2_BASE_HEIGHT=29942295 + +# Exposed HTTP/WS RPC namespaces for morph-reth. +# Note: in morph-reth v1.5.0 the morph_ namespace is registered unconditionally and +# "morph" is not accepted in --http.api/--ws.api. Starting with the next release +# containing morph-reth PR #241, append ",morph" here to keep morph_ RPC methods enabled. +RETH_HTTP_API=web3,debug,eth,txpool,net,trace +RETH_WS_API=web3,debug,eth,txpool,net,trace +RETH_LOG_FILTER=info + +# Optional historical proof index for prover-facing nodes (requires a post-Jade +# paired snapshot; runs `morph-reth proofs init` idempotently before startup). +# The first init can take a long time on mainnet (resumable, progress logged as +# "Processed entries"); binary mode then waits for the engine RPC without a +# timeout unless RETH_READY_TIMEOUT is set. +RETH_PROOFS_HISTORY=false +RETH_PROOFS_WINDOW= +RETH_PROOF_PERMITS= + +# Extra CLI flags passed verbatim to `morph-reth node` (e.g. `--full`, `--txpool.*`). +# NOTE: Do NOT use `--minimal` or `--prune.bodies.*`; Morph's reference index requires +# canonical block bodies from Jade onward and morph-reth refuses to start otherwise. +RETH_EXTRA_FLAGS= + +# Host port bindings and container names for docker-compose.reth.yml. +# Override these (along with RETH_HOME) when running reth alongside geth. +RETH_RPC_PORT=8545 +RETH_WS_PORT=8546 +RETH_METRICS_PORT=6060 +RETH_P2P_PORT=30303 +RETH_CONTAINER_NAME=morph-reth +RETH_NODE_CONTAINER_NAME=morph-node +# Optional UID:GID for the Docker containers (`reth`/`node` in docker-compose.reth.yml, +# and `MORPH_UID`/`MORPH_GID` for `geth`/`node` in docker-compose.yml). Makefile sets +# these automatically from `id -u`/`id -g`; direct `docker compose` falls back to 0:0. +# RETH_UID=1000 +# RETH_GID=1000 +# MORPH_UID=1000 +# MORPH_GID=1000 ## Environment variables for the node L1_CHAIN_ID=1 L1_ETH_RPC=https://eth.drpc.org -# Required in both verify modes: the node exits at startup without it. Only fetched -# at runtime on the layer1 path (local skips the blob fetch on the happy path). -L1_BEACON_CHAIN_RPC=https://rpc.ankr.com/eth +# Required in both verify modes: the node exits at startup without it. Must be an +# L1 Beacon REST API endpoint (/eth/v1/beacon/...), NOT an execution JSON-RPC URL. +# Replace the public default with a dedicated endpoint for production / layer1 mode. +L1_BEACON_CHAIN_RPC=https://ethereum-beacon-api.publicnode.com L1MESSAGEQUEUE_CONTRACT=0x3931ade842f5bb8763164bdd81e5361dce6cc1ef ROLLUP_CONTRACT=0x759894ced0e6af42c26668076ffa84d02e3cef60 # Heights match MAINNET_SNAPSHOT_NAME above (see the README snapshot table). -DERIVATION_START_HEIGHT=25440822 -L1_MSG_START_HEIGHT=25439950 -L2_BASE_HEIGHT=24216219 +DERIVATION_START_HEIGHT=26430867 +L1_MSG_START_HEIGHT=26425693 +L2_BASE_HEIGHT=29942295 ## Extra flags for node NODE_EXTRA_FLAGS=--mainnet @@ -40,8 +81,9 @@ NODE_EXTRA_FLAGS=--mainnet ## hashes against L1 (no beacon fetch on the happy path). ## layer1: pull the L1 beacon blob, decode it, and derive via the engine — ## equivalent to the former validator node (needs L1_BEACON_CHAIN_RPC). -## Leave empty for the binary default (local). `make run-validator` / -## `run-validator-binary` set layer1 for you; or set it here and use `make run-node`. +## Leave empty for the binary default (local). `make run-reth-validator` / +## `make run-validator` (and `-binary` variants) set layer1 for you; or set it +## here and use `make run-reth-node` / `make run-node`. DERIVATION_VERIFY_MODE= ## NOTE: do NOT set L1_SEQUENCER_CONTRACT or CONSENSUS_SWITCH_HEIGHT here. These diff --git a/morph-node/.env_hoodi b/morph-node/.env_hoodi index e874bef..ef2d235 100644 --- a/morph-node/.env_hoodi +++ b/morph-node/.env_hoodi @@ -2,35 +2,77 @@ MORPH_HOME=../hoodi MORPH_FLAG=morph-hoodi JWT_SECRET_FILE=${MORPH_HOME}/jwt-secret.txt GETH_ENTRYPOINT_FILE=./entrypoint-geth.sh -HOODI_SNAPSHOT_NAME=snapshot-20260630-1 +HOODI_SNAPSHOT_NAME=snapshot-20261115-1 -## Reth execution client (alternative to geth). Reth uses a SEPARATE snapshot +## Reth execution client (morph-reth). Reth uses a SEPARATE snapshot ## (reth-data/ tree) and a separate data directory (${RETH_HOME}/reth-data), -## but shares the same network home dir and node-data with the geth flow. +## but shares the same network home dir and node-data by default. Set a +## distinct RETH_HOME (plus port/container overrides below) to run side by side +## with geth during migration. RETH_HOME=${MORPH_HOME} RETH_CHAIN=hoodi RETH_ENTRYPOINT_FILE=./entrypoint-reth.sh -HOODI_RETH_SNAPSHOT_NAME=snapshot-archive-reth-20260901-1 +HOODI_RETH_SNAPSHOT_NAME=snapshot-archive-reth-20261115-1 # Reth uses a SEPARATE snapshot from geth, so it needs its own heights. These must # match HOODI_RETH_SNAPSHOT_NAME above (see the README snapshot table). The reth # compose/binary paths use these instead of the shared DERIVATION_*/L1_MSG_*/L2_BASE_* # below (which track the geth snapshot). -RETH_DERIVATION_START_HEIGHT=3533250 -RETH_L1_MSG_START_HEIGHT=3529538 -RETH_L2_BASE_HEIGHT=8346700 +RETH_DERIVATION_START_HEIGHT=4017123 +RETH_L1_MSG_START_HEIGHT=3931800 +RETH_L2_BASE_HEIGHT=11729740 + +# Exposed HTTP/WS RPC namespaces for morph-reth. +# Note: in morph-reth v1.5.0 the morph_ namespace is registered unconditionally and +# "morph" is not accepted in --http.api/--ws.api. Starting with the next release +# containing morph-reth PR #241, append ",morph" here to keep morph_ RPC methods enabled. +RETH_HTTP_API=web3,debug,eth,txpool,net,trace +RETH_WS_API=web3,debug,eth,txpool,net,trace +RETH_LOG_FILTER=info + +# Optional historical proof index for prover-facing nodes (requires a post-Jade +# paired snapshot; runs `morph-reth proofs init` idempotently before startup). +# The first init can take a long time on mainnet (resumable, progress logged as +# "Processed entries"); binary mode then waits for the engine RPC without a +# timeout unless RETH_READY_TIMEOUT is set. +RETH_PROOFS_HISTORY=false +RETH_PROOFS_WINDOW= +RETH_PROOF_PERMITS= + +# Extra CLI flags passed verbatim to `morph-reth node` (e.g. `--full`, `--txpool.*`). +# NOTE: Do NOT use `--minimal` or `--prune.bodies.*`; Morph's reference index requires +# canonical block bodies from Jade onward and morph-reth refuses to start otherwise. +RETH_EXTRA_FLAGS= + +# Host port bindings and container names for docker-compose.reth.yml. +# Override these (along with RETH_HOME) when running reth alongside geth. +RETH_RPC_PORT=8545 +RETH_WS_PORT=8546 +RETH_METRICS_PORT=6060 +RETH_P2P_PORT=30303 +RETH_CONTAINER_NAME=morph-reth +RETH_NODE_CONTAINER_NAME=morph-node +# Optional UID:GID for the Docker containers (`reth`/`node` in docker-compose.reth.yml, +# and `MORPH_UID`/`MORPH_GID` for `geth`/`node` in docker-compose.yml). Makefile sets +# these automatically from `id -u`/`id -g`; direct `docker compose` falls back to 0:0. +# RETH_UID=1000 +# RETH_GID=1000 +# MORPH_UID=1000 +# MORPH_GID=1000 ## Environment variables for the node L1_CHAIN_ID=560048 -L1_ETH_RPC=${your_layer1_execution_client_rpc_url} -# Required in both verify modes: the node exits at startup without it. Only fetched -# at runtime on the layer1 path (local skips the blob fetch on the happy path). -L1_BEACON_CHAIN_RPC=${your_layer1_beacon_client_rpc_url} +# Public Hoodi defaults for quickstart; replace with your own dedicated L1 EL/CL +# endpoints for production or sustained validator operation. +L1_ETH_RPC=https://ethereum-hoodi-rpc.publicnode.com +# Required in both verify modes: the node exits at startup without it. Must be an +# L1 Beacon REST API endpoint (/eth/v1/beacon/...), NOT an execution JSON-RPC URL. +L1_BEACON_CHAIN_RPC=https://ethereum-hoodi-beacon-api.publicnode.com L1MESSAGEQUEUE_CONTRACT=0xd7f39d837f4790b215ba67e0ab63665912648dbe ROLLUP_CONTRACT=0x57e0e6dde89dc52c01fe785774271504b1e04664 # Heights match HOODI_SNAPSHOT_NAME above (see the README snapshot table). -DERIVATION_START_HEIGHT=3122685 -L1_MSG_START_HEIGHT=3106743 -L2_BASE_HEIGHT=6543334 +DERIVATION_START_HEIGHT=4017123 +L1_MSG_START_HEIGHT=3931800 +L2_BASE_HEIGHT=11729740 ## Extra flags for morphnode. --hoodi selects the Hoodi network so the node picks ## up the built-in Hoodi L1 sequencer contract address; without it the node @@ -42,8 +84,9 @@ NODE_EXTRA_FLAGS=--hoodi ## hashes against L1 (no beacon fetch on the happy path). ## layer1: pull the L1 beacon blob, decode it, and derive via the engine — ## equivalent to the former validator node (needs L1_BEACON_CHAIN_RPC). -## Leave empty for the binary default (local). `make run-hoodi-validator` / -## `run-hoodi-validator-binary` set layer1 for you; or set it here and use `make run-hoodi-node`. +## Leave empty for the binary default (local). `make run-hoodi-reth-validator` / +## `make run-hoodi-validator` (and `-binary` variants) set layer1 for you; or set it +## here and use `make run-hoodi-reth-node` / `make run-hoodi-node`. DERIVATION_VERIFY_MODE= ## NOTE: do NOT set L1_SEQUENCER_CONTRACT or CONSENSUS_SWITCH_HEIGHT here. These diff --git a/morph-node/Makefile b/morph-node/Makefile index 417b79f..5f2a6a0 100644 --- a/morph-node/Makefile +++ b/morph-node/Makefile @@ -1,59 +1,113 @@ include .env -# Capture mainnet JWT path before .env_hoodi overwrites MORPH_HOME (:= forces immediate expansion) +# Capture mainnet paths, container names, and snapshot names before .env_hoodi overwrites them (:= forces immediate expansion) +MORPH_HOME_MAINNET := $(MORPH_HOME) +RETH_HOME_MAINNET := $(RETH_HOME) JWT_SECRET_FILE_MAINNET := $(JWT_SECRET_FILE) -# Capture mainnet reth snapshot name for the same reason. +MAINNET_SNAPSHOT_NAME := $(MAINNET_SNAPSHOT_NAME) MAINNET_RETH_SNAPSHOT_NAME := $(MAINNET_RETH_SNAPSHOT_NAME) +RETH_CONTAINER_NAME_MAINNET := $(RETH_CONTAINER_NAME) +RETH_NODE_CONTAINER_NAME_MAINNET := $(RETH_NODE_CONTAINER_NAME) include .env_hoodi +MORPH_HOME_HOODI := $(MORPH_HOME) +RETH_HOME_HOODI := $(RETH_HOME) JWT_SECRET_FILE_HOODI := $(JWT_SECRET_FILE) +RETH_CONTAINER_NAME_HOODI := $(RETH_CONTAINER_NAME) +RETH_NODE_CONTAINER_NAME_HOODI := $(RETH_NODE_CONTAINER_NAME) -# morph-reth version to build/run. Keep this in sync with the image tag in -# docker-compose.reth.yml (v$(RETH_VERSION)). Override on the command line, e.g. -# `make build-reth RETH_VERSION=1.4.0`. `?=` lets an env var take precedence. +# Prefer Docker Compose v2 (`docker compose`) and fall back to legacy `docker-compose`. +COMPOSE ?= $(shell docker compose version >/dev/null 2>&1 && echo "docker compose" || echo "docker-compose") + +# morph-reth version to build/download/run. Keep this in sync with the image tag in +# docker-compose.reth.yml (v$(RETH_VERSION)) and the morph-reth git submodule. +# Override on the command line, e.g. `make build-reth RETH_VERSION=1.6.0`. RETH_VERSION ?= 1.5.0 +# Cargo build profile for `make build-reth` (matches morph-reth Dockerfile & GitHub Releases). +RETH_BUILD_PROFILE ?= profiling + +# Set SKIP_SHA256_CHECK=1 to bypass snapshot checksum verification if needed. +SKIP_SHA256_CHECK ?= 0 + +.PHONY: generate-jwt generate-jwt-hoodi \ + run-node run-hoodi-node stop-node rm-node \ + run-reth-node run-hoodi-reth-node stop-reth-node rm-reth-node \ + stop-hoodi-reth-node rm-hoodi-reth-node \ + run-validator run-hoodi-validator stop-validator rm-validator \ + run-reth-validator run-hoodi-reth-validator stop-reth-validator rm-reth-validator \ + stop-hoodi-reth-validator rm-hoodi-reth-validator \ + submodule-init set-versions \ + build-geth build-morphnode build-reth download-reth-binary build build-reth-all \ + run-node-binary run-hoodi-node-binary \ + run-validator-binary run-hoodi-validator-binary \ + run-reth-node-binary run-hoodi-reth-node-binary \ + run-reth-validator-binary run-hoodi-reth-validator-binary \ + stop-binary \ + clean-mainnet-binary clean-hoodi-binary clean-mainnet-reth clean-hoodi-reth \ + quickstart-hoodi-node quickstart-hoodi-node-binary \ + quickstart-mainnet-node quickstart-mainnet-node-binary \ + quickstart-hoodi-reth-node quickstart-hoodi-reth-node-binary \ + quickstart-mainnet-reth-node quickstart-mainnet-reth-node-binary \ + download-and-decompress-mainnet-snapshot download-and-decompress-hoodi-snapshot \ + download-and-decompress-mainnet-reth-snapshot download-and-decompress-hoodi-reth-snapshot \ + download-and-decompress-mainnet-mpt-snapshot download-and-decompress-hoodi-mpt-snapshot generate-jwt: - @[ -f $(JWT_SECRET_FILE_MAINNET) ] || (echo "Generating $(JWT_SECRET_FILE_MAINNET)..." && openssl rand -hex 32 > $(JWT_SECRET_FILE_MAINNET) && echo "$(JWT_SECRET_FILE_MAINNET) created.") + @mkdir -p "$$(dirname "$(JWT_SECRET_FILE_MAINNET)")" + @[ -f "$(JWT_SECRET_FILE_MAINNET)" ] || (echo "Generating $(JWT_SECRET_FILE_MAINNET)..." && openssl rand -hex 32 > "$(JWT_SECRET_FILE_MAINNET)" && echo "$(JWT_SECRET_FILE_MAINNET) created.") generate-jwt-hoodi: - @[ -f $(JWT_SECRET_FILE_HOODI) ] || (echo "Generating $(JWT_SECRET_FILE_HOODI)..." && openssl rand -hex 32 > $(JWT_SECRET_FILE_HOODI) && echo "$(JWT_SECRET_FILE_HOODI) created.") + @mkdir -p "$$(dirname "$(JWT_SECRET_FILE_HOODI)")" + @[ -f "$(JWT_SECRET_FILE_HOODI)" ] || (echo "Generating $(JWT_SECRET_FILE_HOODI)..." && openssl rand -hex 32 > "$(JWT_SECRET_FILE_HOODI)" && echo "$(JWT_SECRET_FILE_HOODI) created.") -## node management +## node management (geth) run-node: generate-jwt @echo "You are about to run a Mainnet node." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - docker-compose --env-file .env up node & + @mkdir -p "$(MORPH_HOME_MAINNET)/geth-data" "$(MORPH_HOME_MAINNET)/node-data/data" + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) $(COMPOSE) --env-file .env up -d node run-hoodi-node: generate-jwt-hoodi @echo "You are about to run a Hoodi node." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - docker-compose --env-file .env_hoodi up node & + @mkdir -p "$(MORPH_HOME_HOODI)/geth-data" "$(MORPH_HOME_HOODI)/node-data/data" + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) $(COMPOSE) --env-file .env_hoodi up -d node stop-node: - docker stop morph-node morph-geth + @docker stop morph-node 2>/dev/null || true + docker stop morph-geth rm-node: docker rm morph-node morph-geth -## reth node management (reth is an alternative execution client to geth; it uses -## a SEPARATE snapshot — see the README snapshot table — and its own reth-data dir). +## reth node management (morph-reth uses a SEPARATE snapshot — see the README +## snapshot table — and its own reth-data dir). run-reth-node: generate-jwt @echo "You are about to run a Mainnet node with the reth execution client." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - docker-compose -f docker-compose.reth.yml --env-file .env up node & + @mkdir -p "$(RETH_HOME_MAINNET)/reth-data/logs" "$(RETH_HOME_MAINNET)/node-data/data" + RETH_UID=$$(id -u) RETH_GID=$$(id -g) $(COMPOSE) -f docker-compose.reth.yml --env-file .env up -d node run-hoodi-reth-node: generate-jwt-hoodi @echo "You are about to run a Hoodi node with the reth execution client." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - docker-compose -f docker-compose.reth.yml --env-file .env_hoodi up node & + @mkdir -p "$(RETH_HOME_HOODI)/reth-data/logs" "$(RETH_HOME_HOODI)/node-data/data" + RETH_UID=$$(id -u) RETH_GID=$$(id -g) $(COMPOSE) -f docker-compose.reth.yml --env-file .env_hoodi up -d node stop-reth-node: - docker stop morph-node morph-reth + @docker stop $(RETH_NODE_CONTAINER_NAME_MAINNET) 2>/dev/null || true + docker stop $(RETH_CONTAINER_NAME_MAINNET) rm-reth-node: - docker rm morph-node morph-reth + docker rm $(RETH_NODE_CONTAINER_NAME_MAINNET) $(RETH_CONTAINER_NAME_MAINNET) + +stop-hoodi-reth-node: + @docker stop $(RETH_NODE_CONTAINER_NAME_HOODI) 2>/dev/null || true + docker stop $(RETH_CONTAINER_NAME_HOODI) + +rm-hoodi-reth-node: + docker rm $(RETH_NODE_CONTAINER_NAME_HOODI) $(RETH_CONTAINER_NAME_HOODI) ## Validator commands, kept for backward compatibility. A "validator" is now just ## the single node run in layer1 batch-verification mode (--derivation.verify-mode=layer1: @@ -63,41 +117,70 @@ rm-reth-node: run-validator: generate-jwt @echo "You are about to run a Mainnet node in validator mode (--derivation.verify-mode=layer1)." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - DERIVATION_VERIFY_MODE=layer1 docker-compose --env-file .env up node & + @mkdir -p "$(MORPH_HOME_MAINNET)/geth-data" "$(MORPH_HOME_MAINNET)/node-data/data" + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) DERIVATION_VERIFY_MODE=layer1 $(COMPOSE) --env-file .env up -d node run-hoodi-validator: generate-jwt-hoodi @echo "You are about to run a Hoodi node in validator mode (--derivation.verify-mode=layer1)." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } - DERIVATION_VERIFY_MODE=layer1 docker-compose --env-file .env_hoodi up node & + @mkdir -p "$(MORPH_HOME_HOODI)/geth-data" "$(MORPH_HOME_HOODI)/node-data/data" + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) DERIVATION_VERIFY_MODE=layer1 $(COMPOSE) --env-file .env_hoodi up -d node -## Backward-compat aliases: the validator is now the same container as the node. stop-validator: stop-node rm-validator: rm-node -## build from source (requires Go) +## Validator commands for reth (--derivation.verify-mode=layer1 + morph-reth). +run-reth-validator: generate-jwt + @echo "You are about to run a Mainnet reth node in validator mode (--derivation.verify-mode=layer1)." + @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } + @mkdir -p "$(RETH_HOME_MAINNET)/reth-data/logs" "$(RETH_HOME_MAINNET)/node-data/data" + RETH_UID=$$(id -u) RETH_GID=$$(id -g) DERIVATION_VERIFY_MODE=layer1 $(COMPOSE) -f docker-compose.reth.yml --env-file .env up -d node + +run-hoodi-reth-validator: generate-jwt-hoodi + @echo "You are about to run a Hoodi reth node in validator mode (--derivation.verify-mode=layer1)." + @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } + @mkdir -p "$(RETH_HOME_HOODI)/reth-data/logs" "$(RETH_HOME_HOODI)/node-data/data" + RETH_UID=$$(id -u) RETH_GID=$$(id -g) DERIVATION_VERIFY_MODE=layer1 $(COMPOSE) -f docker-compose.reth.yml --env-file .env_hoodi up -d node + +stop-reth-validator: stop-reth-node + +rm-reth-validator: rm-reth-node + +stop-hoodi-reth-validator: stop-hoodi-reth-node + +rm-hoodi-reth-validator: rm-hoodi-reth-node + +## build from source (requires Go / Rust) submodule-init: @echo "Initializing git submodules..." cd .. && git submodule update --init --recursive @echo "Submodules ready." -# Update submodule versions and docker-compose.yml image tags in one shot. -# Usage: make set-versions GETH_VERSION=2.2.1 NODE_VERSION=0.5.3 [RETH_VERSION=1.4.0] -# RETH_VERSION also rewrites the morph-reth image tag in docker-compose.reth.yml so -# the Docker and binary reth paths stay on the same version (defaults to $(RETH_VERSION)). +# Update submodule versions, docker-compose image tags, Makefile RETH_VERSION, and README in one shot. +# Usage: make set-versions GETH_VERSION=2.2.8 NODE_VERSION=0.6.5 RETH_VERSION=1.5.0 set-versions: + @if [ -z "$(GETH_VERSION)" ] || [ -z "$(NODE_VERSION)" ] || [ -z "$(RETH_VERSION)" ] || [ "$(origin RETH_VERSION)" = "file" ]; then \ + echo "Usage: make set-versions GETH_VERSION= NODE_VERSION= RETH_VERSION="; \ + exit 1; \ + fi + cd .. && git submodule update --init go-ethereum morph morph-reth cd ../go-ethereum && git fetch --tags && git checkout morph-v$(GETH_VERSION) cd ../morph && git fetch --tags && git checkout v$(NODE_VERSION) - sed -i'' 's|go-ethereum:[0-9.]*|go-ethereum:$(GETH_VERSION)|g' docker-compose.yml - sed -i'' 's|morph-l2/node:[0-9.]*|morph-l2/node:$(NODE_VERSION)|g' docker-compose.yml - sed -i'' 's|morph-reth:v[0-9.]*|morph-reth:v$(RETH_VERSION)|g' docker-compose.reth.yml - cd .. && git add go-ethereum morph - @echo "Done. Commit with: git commit -m 'chore: bump geth=$(GETH_VERSION) node=$(NODE_VERSION) reth=$(RETH_VERSION)'" - -build-geth: submodule-init - @if [ -f ./bin/geth ]; then \ - echo "geth binary already exists at ./bin/geth, skipping build."; \ + cd ../morph-reth && git fetch --tags && git checkout v$(RETH_VERSION) + sed 's|go-ethereum:[0-9A-Za-z._-]*|go-ethereum:$(GETH_VERSION)|g; s|morph-l2/node:[0-9A-Za-z._-]*|morph-l2/node:$(NODE_VERSION)|g' docker-compose.yml > docker-compose.yml.tmp && mv docker-compose.yml.tmp docker-compose.yml + sed 's|morph-reth:v[0-9A-Za-z._-]*|morph-reth:v$(RETH_VERSION)|g; s|morph-l2/node:[0-9A-Za-z._-]*|morph-l2/node:$(NODE_VERSION)|g' docker-compose.reth.yml > docker-compose.reth.yml.tmp && mv docker-compose.reth.yml.tmp docker-compose.reth.yml + sed 's|^RETH_VERSION ?= .*|RETH_VERSION ?= $(RETH_VERSION)|' Makefile > Makefile.tmp && mv Makefile.tmp Makefile + sed 's|(default `[^`]*`, kept in sync with the image in|(default `$(RETH_VERSION)`, kept in sync with the image in|' ../README.md > ../README.md.tmp && mv ../README.md.tmp ../README.md + cd .. && git add go-ethereum morph morph-reth morph-node/docker-compose.yml morph-node/docker-compose.reth.yml morph-node/Makefile README.md + @echo "Done. Commit with: git commit -m 'chore: bump node=$(NODE_VERSION) geth=$(GETH_VERSION) reth=$(RETH_VERSION)'" + +build-geth: + @if [ -f ./bin/geth ] && [ "$${FORCE_BUILD:-0}" != "1" ]; then \ + echo "geth binary already exists at ./bin/geth, skipping build (set FORCE_BUILD=1 to rebuild)."; \ else \ + echo "Initializing go-ethereum submodule..."; \ + (cd .. && git submodule update --init --recursive go-ethereum) || { echo "Error: failed to init go-ethereum submodule."; exit 1; }; \ echo "Building geth from source..."; \ (cd ../go-ethereum && make geth) || { echo "Error: geth build failed."; exit 1; }; \ mkdir -p ./bin; \ @@ -105,10 +188,12 @@ build-geth: submodule-init echo "geth binary copied to morph-node/bin/geth"; \ fi -build-morphnode: submodule-init - @if [ -f ./bin/morphnode ]; then \ - echo "morphnode binary already exists at ./bin/morphnode, skipping build."; \ +build-morphnode: + @if [ -f ./bin/morphnode ] && [ "$${FORCE_BUILD:-0}" != "1" ]; then \ + echo "morphnode binary already exists at ./bin/morphnode, skipping build (set FORCE_BUILD=1 to rebuild)."; \ else \ + echo "Initializing morph submodule..."; \ + (cd .. && git submodule update --init --recursive morph) || { echo "Error: failed to init morph submodule."; exit 1; }; \ echo "Building morphnode from source..."; \ (cd ../morph/node && make morphnode) || { echo "Error: morphnode build failed."; exit 1; }; \ mkdir -p ./bin; \ @@ -116,24 +201,74 @@ build-morphnode: submodule-init echo "morphnode binary copied to morph-node/bin/morphnode"; \ fi -## Build morph-reth from source (requires the Rust toolchain / cargo). morph-reth -## lives in its own repo (https://github.com/morph-l2/morph-reth), not a submodule, -## so we clone it under ../morph-reth on first build. +## Build morph-reth from the pinned git submodule (requires Rust >= 1.95, libclang-dev, pkg-config). build-reth: - @if [ -f ./bin/morph-reth ]; then \ - echo "morph-reth binary already exists at ./bin/morph-reth, skipping build."; \ + @if [ -x ./bin/morph-reth ] && [ "$${FORCE_BUILD:-0}" != "1" ] && ./bin/morph-reth --version 2>/dev/null | head -n1 | grep -qE "Morph-Reth Version: $(RETH_VERSION)([^0-9.]|$$)"; then \ + echo "morph-reth v$(RETH_VERSION) already exists at ./bin/morph-reth, skipping build (set FORCE_BUILD=1 to rebuild)."; \ + else \ + echo "Building morph-reth v$(RETH_VERSION) (profile: $(RETH_BUILD_PROFILE)) from source..."; \ + (cd .. && git submodule update --init morph-reth) || { echo "Error: failed to init morph-reth submodule."; exit 1; }; \ + (cd ../morph-reth && \ + TARGET_SHA=$$(git rev-list -n 1 "v$(RETH_VERSION)" 2>/dev/null || true); \ + CUR_SHA=$$(git rev-parse HEAD); \ + if [ -z "$$TARGET_SHA" ] || [ "$$CUR_SHA" != "$$TARGET_SHA" ]; then \ + echo "Checking out v$(RETH_VERSION)..."; \ + git fetch --tags && git checkout "v$(RETH_VERSION)"; \ + fi) || { echo "Error: failed to checkout morph-reth v$(RETH_VERSION)."; exit 1; }; \ + (cd ../morph-reth && cargo build --profile "$(RETH_BUILD_PROFILE)" --locked --bin morph-reth) || { echo "Error: morph-reth build failed."; exit 1; }; \ + mkdir -p ./bin; \ + cp "../morph-reth/target/$(RETH_BUILD_PROFILE)/morph-reth" ./bin/morph-reth || { echo "Error: failed to copy morph-reth binary to morph-node/bin/morph-reth."; exit 1; }; \ + chmod +x ./bin/morph-reth; \ + echo "morph-reth v$(RETH_VERSION) binary copied to morph-node/bin/morph-reth"; \ + fi + +## Download pre-built morph-reth binary from GitHub Releases (Linux x86_64 / aarch64) with SHA-256 verification. +download-reth-binary: + @if [ -x ./bin/morph-reth ] && [ "$${FORCE_BUILD:-0}" != "1" ] && ./bin/morph-reth --version 2>/dev/null | head -n1 | grep -qE "Morph-Reth Version: $(RETH_VERSION)([^0-9.]|$$)"; then \ + echo "morph-reth v$(RETH_VERSION) already exists at ./bin/morph-reth, skipping download (set FORCE_BUILD=1 to re-download)."; \ else \ - echo "Building morph-reth v$(RETH_VERSION) from source..."; \ - if [ ! -d ../morph-reth ]; then \ - echo "Cloning morph-reth..."; \ - git clone https://github.com/morph-l2/morph-reth.git ../morph-reth || { echo "Error: failed to clone morph-reth."; exit 1; }; \ + OS=$$(uname -s); \ + if [ "$$OS" != "Linux" ]; then \ + echo "Error: pre-built morph-reth binaries are only published for Linux (got $$OS). Use 'make build-reth' instead."; \ + exit 1; \ + fi; \ + RAW_ARCH=$$(uname -m); \ + case "$$RAW_ARCH" in \ + x86_64|amd64) ARCH="x86_64-linux" ;; \ + aarch64|arm64) ARCH="aarch64-linux" ;; \ + *) echo "Error: unsupported architecture $$RAW_ARCH. Use 'make build-reth' instead."; exit 1 ;; \ + esac; \ + ARCHIVE="morph-reth-$(RETH_VERSION)-$${ARCH}.tar.gz"; \ + BASE_URL="https://github.com/morph-l2/morph-reth/releases/download/v$(RETH_VERSION)"; \ + TMP_DIR=$$(mktemp -d); \ + trap 'rm -rf "$$TMP_DIR"' EXIT; \ + echo "Downloading $$ARCHIVE from $$BASE_URL..."; \ + if command -v curl >/dev/null 2>&1; then \ + curl -fsSL "$$BASE_URL/$$ARCHIVE" -o "$$TMP_DIR/$$ARCHIVE" || { echo "Error: failed to download $$ARCHIVE."; exit 1; }; \ + curl -fsSL "$$BASE_URL/$$ARCHIVE.sha256" -o "$$TMP_DIR/$$ARCHIVE.sha256" || { echo "Error: failed to download $$ARCHIVE.sha256."; exit 1; }; \ + elif command -v wget >/dev/null 2>&1; then \ + wget -O "$$TMP_DIR/$$ARCHIVE" "$$BASE_URL/$$ARCHIVE" || { echo "Error: failed to download $$ARCHIVE."; exit 1; }; \ + wget -O "$$TMP_DIR/$$ARCHIVE.sha256" "$$BASE_URL/$$ARCHIVE.sha256" || { echo "Error: failed to download $$ARCHIVE.sha256."; exit 1; }; \ + else \ + echo "Error: curl or wget is required."; exit 1; \ + fi; \ + EXPECTED=$$(awk '{print $$1}' "$$TMP_DIR/$$ARCHIVE.sha256"); \ + if command -v sha256sum >/dev/null 2>&1; then \ + ACTUAL=$$(sha256sum "$$TMP_DIR/$$ARCHIVE" | awk '{print $$1}'); \ + elif command -v shasum >/dev/null 2>&1; then \ + ACTUAL=$$(shasum -a 256 "$$TMP_DIR/$$ARCHIVE" | awk '{print $$1}'); \ + else \ + ACTUAL=$$(openssl dgst -sha256 "$$TMP_DIR/$$ARCHIVE" | awk '{print $$NF}'); \ fi; \ - echo "Checking out v$(RETH_VERSION) (pinned to match docker-compose.reth.yml)..."; \ - (cd ../morph-reth && git fetch --tags && git checkout v$(RETH_VERSION)) || { echo "Error: failed to checkout morph-reth v$(RETH_VERSION)."; exit 1; }; \ - (cd ../morph-reth && cargo build --release) || { echo "Error: morph-reth build failed."; exit 1; }; \ + if [ "$$EXPECTED" != "$$ACTUAL" ]; then \ + echo "Error: SHA-256 mismatch for $$ARCHIVE (expected $$EXPECTED, got $$ACTUAL)."; \ + exit 1; \ + fi; \ + echo "SHA-256 verified ($$ACTUAL). Extracting..."; \ mkdir -p ./bin; \ - cp ../morph-reth/target/release/morph-reth ./bin/morph-reth || { echo "Error: failed to copy morph-reth binary to morph-node/bin/morph-reth."; exit 1; }; \ - echo "morph-reth binary copied to morph-node/bin/morph-reth"; \ + tar -xzf "$$TMP_DIR/$$ARCHIVE" -C ./bin morph-reth || { echo "Error: failed to extract morph-reth."; exit 1; }; \ + chmod +x ./bin/morph-reth; \ + echo "morph-reth v$(RETH_VERSION) installed to morph-node/bin/morph-reth"; \ fi build: build-geth build-morphnode @@ -143,7 +278,7 @@ build: build-geth build-morphnode build-reth-all: build-reth build-morphnode @echo "All reth binaries built successfully." -## binary mode +## binary mode (geth) run-node-binary: generate-jwt @echo "You are about to run a Mainnet node (binary mode)." @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } @@ -179,101 +314,230 @@ run-hoodi-reth-node-binary: generate-jwt-hoodi @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } sh ./run-binary-reth.sh .env_hoodi +run-reth-validator-binary: generate-jwt + @echo "You are about to run a Mainnet reth node in validator mode (--derivation.verify-mode=layer1, binary)." + @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } + MORPH_NODE_DERIVATION_VERIFY_MODE=layer1 sh ./run-binary-reth.sh .env + +run-hoodi-reth-validator-binary: generate-jwt-hoodi + @echo "You are about to run a Hoodi reth node in validator mode (--derivation.verify-mode=layer1, binary)." + @{ [ -t 0 ] || { echo "Error: interactive confirmation required (run in a TTY)."; exit 1; }; printf "Continue? [Y/n] "; read confirm; if [ "$$confirm" = "n" ] || [ "$$confirm" = "N" ]; then exit 1; fi; } + MORPH_NODE_DERIVATION_VERIFY_MODE=layer1 sh ./run-binary-reth.sh .env_hoodi + +## Graceful binary shutdown: stop morphnode first, then the execution client, waiting for DB flush. stop-binary: - @if [ -f .geth.pid ]; then kill $$(cat .geth.pid) 2>/dev/null; rm -f .geth.pid; echo "geth stopped."; fi - @if [ -f .reth.pid ]; then kill $$(cat .reth.pid) 2>/dev/null; rm -f .reth.pid; echo "reth stopped."; fi - @if [ -f .node.pid ]; then kill $$(cat .node.pid) 2>/dev/null; rm -f .node.pid; echo "morphnode stopped."; fi + @stop_pid() { \ + pidfile="$$1"; name="$$2"; timeout="$$3"; \ + if [ -f "$$pidfile" ]; then \ + pid=$$(cat "$$pidfile"); \ + if kill -0 "$$pid" 2>/dev/null; then \ + echo "Stopping $$name (PID $$pid)..."; \ + kill -TERM "$$pid" 2>/dev/null || true; \ + elapsed=0; \ + while kill -0 "$$pid" 2>/dev/null && [ "$$elapsed" -lt "$$timeout" ]; do \ + sleep 1; \ + elapsed=$$((elapsed + 1)); \ + done; \ + if kill -0 "$$pid" 2>/dev/null; then \ + echo "Warning: $$name (PID $$pid) still running after $${timeout}s."; \ + else \ + echo "$$name stopped."; \ + fi; \ + else \ + echo "$$name was not running."; \ + fi; \ + rm -f "$$pidfile"; \ + fi; \ + }; \ + stop_pid .node.pid "morphnode" 60; \ + stop_pid .reth.pid "morph-reth" 120; \ + stop_pid .geth.pid "geth" 120 clean-mainnet-binary: - @echo "Cleaning mainnet snapshot data (keeping config)..." - rm -rf ../mainnet/geth-data/geth - rm -rf ../mainnet/node-data/data/* - @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > ../mainnet/node-data/data/priv_validator_state.json + @echo "Cleaning mainnet geth snapshot data at $(MORPH_HOME_MAINNET) (keeping config)..." + rm -rf "$(MORPH_HOME_MAINNET)/geth-data/geth" \ + "$(MORPH_HOME_MAINNET)/geth-data/geth.log" + rm -rf "$(MORPH_HOME_MAINNET)/node-data/data/"* \ + "$(MORPH_HOME_MAINNET)/node-data/node-data" \ + "$(MORPH_HOME_MAINNET)/node-data/node.log" + mkdir -p "$(MORPH_HOME_MAINNET)/node-data/data" + @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(MORPH_HOME_MAINNET)/node-data/data/priv_validator_state.json" @echo "Mainnet snapshot data cleaned." clean-hoodi-binary: - @echo "Cleaning hoodi snapshot data (keeping config)..." - rm -rf ../hoodi/geth-data/geth - rm -rf ../hoodi/node-data/data/* - @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > ../hoodi/node-data/data/priv_validator_state.json + @echo "Cleaning hoodi geth snapshot data at $(MORPH_HOME_HOODI) (keeping config)..." + rm -rf "$(MORPH_HOME_HOODI)/geth-data/geth" \ + "$(MORPH_HOME_HOODI)/geth-data/geth.log" + rm -rf "$(MORPH_HOME_HOODI)/node-data/data/"* \ + "$(MORPH_HOME_HOODI)/node-data/node-data" \ + "$(MORPH_HOME_HOODI)/node-data/node.log" + mkdir -p "$(MORPH_HOME_HOODI)/node-data/data" + @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(MORPH_HOME_HOODI)/node-data/data/priv_validator_state.json" @echo "Hoodi snapshot data cleaned." clean-mainnet-reth: - @echo "Cleaning mainnet reth snapshot data (keeping config)..." - rm -rf ../mainnet/reth-data/db ../mainnet/reth-data/static_files ../mainnet/reth-data/rocksdb ../mainnet/reth-data/morph - rm -rf ../mainnet/node-data/data/* - @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > ../mainnet/node-data/data/priv_validator_state.json + @echo "Cleaning mainnet reth snapshot data at $(RETH_HOME_MAINNET) (keeping config and static-nodes.json)..." + rm -rf "$(RETH_HOME_MAINNET)/reth-data/db" \ + "$(RETH_HOME_MAINNET)/reth-data/static_files" \ + "$(RETH_HOME_MAINNET)/reth-data/rocksdb" \ + "$(RETH_HOME_MAINNET)/reth-data/morph" \ + "$(RETH_HOME_MAINNET)/reth-data/historical-proofs" \ + "$(RETH_HOME_MAINNET)/reth-data/exex" \ + "$(RETH_HOME_MAINNET)/reth-data/blobstore" \ + "$(RETH_HOME_MAINNET)/reth-data/txpool-transactions-backup.rlp" \ + "$(RETH_HOME_MAINNET)/reth-data/known-peers.json" \ + "$(RETH_HOME_MAINNET)/reth-data/invalid_block_hooks" \ + "$(RETH_HOME_MAINNET)/reth-data/reth.toml" \ + "$(RETH_HOME_MAINNET)/reth-data/logs" \ + "$(RETH_HOME_MAINNET)/reth-data/"reth.log* + rm -rf "$(RETH_HOME_MAINNET)/node-data/data/"* \ + "$(RETH_HOME_MAINNET)/node-data/node-data" \ + "$(RETH_HOME_MAINNET)/node-data/node.log" + mkdir -p "$(RETH_HOME_MAINNET)/node-data/data" + @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(RETH_HOME_MAINNET)/node-data/data/priv_validator_state.json" @echo "Mainnet reth snapshot data cleaned." clean-hoodi-reth: - @echo "Cleaning hoodi reth snapshot data (keeping config)..." - rm -rf ../hoodi/reth-data/db ../hoodi/reth-data/static_files ../hoodi/reth-data/rocksdb ../hoodi/reth-data/morph - rm -rf ../hoodi/node-data/data/* - @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > ../hoodi/node-data/data/priv_validator_state.json + @echo "Cleaning hoodi reth snapshot data at $(RETH_HOME_HOODI) (keeping config and static-nodes.json)..." + rm -rf "$(RETH_HOME_HOODI)/reth-data/db" \ + "$(RETH_HOME_HOODI)/reth-data/static_files" \ + "$(RETH_HOME_HOODI)/reth-data/rocksdb" \ + "$(RETH_HOME_HOODI)/reth-data/morph" \ + "$(RETH_HOME_HOODI)/reth-data/historical-proofs" \ + "$(RETH_HOME_HOODI)/reth-data/exex" \ + "$(RETH_HOME_HOODI)/reth-data/blobstore" \ + "$(RETH_HOME_HOODI)/reth-data/txpool-transactions-backup.rlp" \ + "$(RETH_HOME_HOODI)/reth-data/known-peers.json" \ + "$(RETH_HOME_HOODI)/reth-data/invalid_block_hooks" \ + "$(RETH_HOME_HOODI)/reth-data/reth.toml" \ + "$(RETH_HOME_HOODI)/reth-data/logs" \ + "$(RETH_HOME_HOODI)/reth-data/"reth.log* + rm -rf "$(RETH_HOME_HOODI)/node-data/data/"* \ + "$(RETH_HOME_HOODI)/node-data/node-data" \ + "$(RETH_HOME_HOODI)/node-data/node.log" + mkdir -p "$(RETH_HOME_HOODI)/node-data/data" + @printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(RETH_HOME_HOODI)/node-data/data/priv_validator_state.json" @echo "Hoodi reth snapshot data cleaned." -# Helper: download, extract, and move snapshot data into MORPH_HOME -# $(1) = snapshot name, $(2) = download URL base, $(3) = MORPH_HOME +# Helper: download tarball with resume and verify SHA-256 checksum against $(2)/$(1).tar.gz.sha256. +# $(1) = snapshot name, $(2) = download URL base, $(3) = target directory +define fetch-and-verify-snapshot + mkdir -p "$(3)"; \ + if [ ! -f "$(3)/$(1).tar.gz" ] || [ "$(SKIP_SHA256_CHECK)" != "1" ]; then \ + echo "Downloading $(1).tar.gz from $(2)..."; \ + wget -c -O "$(3)/$(1).tar.gz" "$(2)/$(1).tar.gz" || { echo "Error: download failed."; exit 1; }; \ + else \ + echo "Found existing $(3)/$(1).tar.gz, skipping download."; \ + fi; \ + if [ "$(SKIP_SHA256_CHECK)" != "1" ]; then \ + echo "Verifying SHA-256 checksum for $(1).tar.gz..."; \ + wget -q -O "$(3)/$(1).tar.gz.sha256" "$(2)/$(1).tar.gz.sha256" || { echo "Error: failed to download $(1).tar.gz.sha256 (set SKIP_SHA256_CHECK=1 to bypass)."; exit 1; }; \ + EXPECTED=$$(awk '{print $$1}' "$(3)/$(1).tar.gz.sha256"); \ + if command -v sha256sum >/dev/null 2>&1; then \ + ACTUAL=$$(sha256sum "$(3)/$(1).tar.gz" | awk '{print $$1}'); \ + elif command -v shasum >/dev/null 2>&1; then \ + ACTUAL=$$(shasum -a 256 "$(3)/$(1).tar.gz" | awk '{print $$1}'); \ + else \ + ACTUAL=$$(openssl dgst -sha256 "$(3)/$(1).tar.gz" | awk '{print $$NF}'); \ + fi; \ + rm -f "$(3)/$(1).tar.gz.sha256"; \ + if [ "$$EXPECTED" != "$$ACTUAL" ]; then \ + echo "Error: SHA-256 mismatch for $(3)/$(1).tar.gz (expected $$EXPECTED, got $$ACTUAL)."; \ + echo "Remove the corrupted tarball and retry."; \ + exit 1; \ + fi; \ + echo "SHA-256 verified ($$ACTUAL)."; \ + fi +endef + +# Helper: extract tarball (uses pigz when available for faster multi-core decompression). +# $(1) = tarball path, $(2) = destination directory +define extract-tar-gz + if command -v pigz >/dev/null 2>&1; then \ + pigz -dc "$(1)" | tar -xf - -C "$(2)" || { echo "Error: extraction failed."; exit 1; }; \ + else \ + tar -xzf "$(1)" -C "$(2)" || { echo "Error: extraction failed."; exit 1; }; \ + fi +endef + +# Helper: download, extract, and move geth snapshot data into MORPH_HOME. +# Cleans existing Tendermint DB members before moving so switching snapshots or +# clients never fails halfway with "Directory not empty". +# $(1) = snapshot name, $(2) = download URL base, $(3) = MORPH_HOME, $(4) = network (mainnet|hoodi) define setup-snapshot-data @if [ -d "$(3)/geth-data/geth/chaindata" ]; then \ echo "Snapshot data already in place at $(3), skipping setup."; \ else \ echo "Setting up snapshot data for $(3)..."; \ if [ ! -d "$(3)/$(1)" ]; then \ - if [ ! -f "$(3)/$(1).tar.gz" ]; then \ - echo "Downloading $(1).tar.gz from $(2)..."; \ - wget -O $(3)/$(1).tar.gz $(2)/$(1).tar.gz || { echo "Error: download failed."; exit 1; }; \ - else \ - echo "Found existing $(3)/$(1).tar.gz, skipping download."; \ - fi; \ + $(call fetch-and-verify-snapshot,$(1),$(2),$(3)); \ echo "Extracting $(1).tar.gz..."; \ - tar -xzf $(3)/$(1).tar.gz -C $(3) || { echo "Error: extraction failed."; exit 1; }; \ - rm -f $(3)/$(1).tar.gz; \ + $(call extract-tar-gz,$(3)/$(1).tar.gz,$(3)); \ + rm -f "$(3)/$(1).tar.gz"; \ else \ echo "Found existing $(3)/$(1)/ directory, skipping download."; \ fi; \ - mkdir -p $(3)/geth-data $(3)/node-data/data; \ + [ -d "$(3)/$(1)/geth/chaindata" ] || { echo "Error: expected $(3)/$(1)/geth/chaindata — is $(1) a geth snapshot?"; exit 1; }; \ + [ -d "$(3)/$(1)/data" ] || { echo "Error: expected $(3)/$(1)/data in snapshot $(1)."; exit 1; }; \ + mkdir -p "$(3)/geth-data" "$(3)/node-data/data" "$(3)/node-data/config"; \ + [ -f "$(3)/node-data/config/config.toml" ] || cp "../$(4)/node-data/config/config.toml" "$(3)/node-data/config/config.toml"; \ + [ -f "$(3)/node-data/config/genesis.json" ] || cp "../$(4)/node-data/config/genesis.json" "$(3)/node-data/config/genesis.json"; \ + [ -f "$(3)/geth-data/static-nodes.json" ] || cp "../$(4)/geth-data/static-nodes.json" "$(3)/geth-data/static-nodes.json"; \ echo "Moving geth data to $(3)/geth-data/..."; \ - mv $(3)/$(1)/geth $(3)/geth-data/ || { echo "Error: failed to move geth data (may already exist)."; exit 1; }; \ - echo "Moving node data to $(3)/node-data/data/..."; \ - mv $(3)/$(1)/data/* $(3)/node-data/data/ || { echo "Error: failed to move node data."; exit 1; }; \ - rm -rf $(3)/$(1); \ - [ -f "$(3)/node-data/data/priv_validator_state.json" ] || printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > $(3)/node-data/data/priv_validator_state.json; \ + rm -rf "$(3)/geth-data/geth"; \ + mv "$(3)/$(1)/geth" "$(3)/geth-data/" || { echo "Error: failed to move geth data."; exit 1; }; \ + echo "Replacing node data in $(3)/node-data/data/..."; \ + rm -rf "$(3)/node-data/data/"* "$(3)/node-data/node-data"; \ + for item in "$(3)/$(1)/data/"*; do \ + [ -e "$$item" ] || continue; \ + mv "$$item" "$(3)/node-data/data/" || { echo "Error: failed to move $$item."; exit 1; }; \ + done; \ + rm -rf "$(3)/$(1)"; \ + [ -f "$(3)/node-data/data/priv_validator_state.json" ] || printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(3)/node-data/data/priv_validator_state.json"; \ echo "Snapshot data ready at $(3)."; \ fi endef # Helper: download, extract, and move a RETH snapshot into RETH_HOME. Reth snapshots # pack a different layout than geth: /reth-data/{db,static_files,rocksdb,morph} -# plus /data/* for the node. static-nodes.json is NOT in the snapshot, so we -# copy it from geth-data/ (already tracked in the repo) into reth-data/ for --trusted-peers. -# $(1) = snapshot name, $(2) = download URL base, $(3) = RETH_HOME +# plus /data/* for the node. Cleans existing node-data/data, node-data/node-data, +# and stale reth-data members before moving so migrating from geth or switching snapshots is safe. +# $(1) = snapshot name, $(2) = download URL base, $(3) = RETH_HOME, $(4) = network (mainnet|hoodi) define setup-snapshot-data-reth @if [ -d "$(3)/reth-data/db" ]; then \ echo "Reth snapshot data already in place at $(3), skipping setup."; \ else \ echo "Setting up reth snapshot data for $(3)..."; \ if [ ! -d "$(3)/$(1)" ]; then \ - if [ ! -f "$(3)/$(1).tar.gz" ]; then \ - echo "Downloading $(1).tar.gz from $(2)..."; \ - wget -O $(3)/$(1).tar.gz $(2)/$(1).tar.gz || { echo "Error: download failed."; exit 1; }; \ - else \ - echo "Found existing $(3)/$(1).tar.gz, skipping download."; \ - fi; \ + $(call fetch-and-verify-snapshot,$(1),$(2),$(3)); \ echo "Extracting $(1).tar.gz..."; \ - tar -xzf $(3)/$(1).tar.gz -C $(3) || { echo "Error: extraction failed."; exit 1; }; \ - rm -f $(3)/$(1).tar.gz; \ + $(call extract-tar-gz,$(3)/$(1).tar.gz,$(3)); \ + rm -f "$(3)/$(1).tar.gz"; \ else \ echo "Found existing $(3)/$(1)/ directory, skipping download."; \ fi; \ - mkdir -p $(3)/reth-data $(3)/node-data/data; \ - echo "Moving reth data to $(3)/reth-data/..."; \ - mv $(3)/$(1)/reth-data/* $(3)/reth-data/ || { echo "Error: failed to move reth data (may already exist)."; exit 1; }; \ - echo "Moving node data to $(3)/node-data/data/..."; \ - mv $(3)/$(1)/data/* $(3)/node-data/data/ || { echo "Error: failed to move node data."; exit 1; }; \ - rm -rf $(3)/$(1); \ - [ -f "$(3)/reth-data/static-nodes.json" ] || cp $(3)/geth-data/static-nodes.json $(3)/reth-data/static-nodes.json 2>/dev/null || echo "Warning: no static-nodes.json found in $(3)/geth-data/; --trusted-peers will be empty."; \ - [ -f "$(3)/node-data/data/priv_validator_state.json" ] || printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > $(3)/node-data/data/priv_validator_state.json; \ + [ -d "$(3)/$(1)/reth-data/db" ] || { echo "Error: expected $(3)/$(1)/reth-data/db — is $(1) a reth snapshot?"; exit 1; }; \ + [ -d "$(3)/$(1)/data" ] || { echo "Error: expected $(3)/$(1)/data in snapshot $(1)."; exit 1; }; \ + mkdir -p "$(3)/reth-data/logs" "$(3)/node-data/data" "$(3)/node-data/config"; \ + [ -f "$(3)/node-data/config/config.toml" ] || cp "../$(4)/node-data/config/config.toml" "$(3)/node-data/config/config.toml"; \ + [ -f "$(3)/node-data/config/genesis.json" ] || cp "../$(4)/node-data/config/genesis.json" "$(3)/node-data/config/genesis.json"; \ + echo "Replacing reth data in $(3)/reth-data/..."; \ + rm -rf "$(3)/reth-data/historical-proofs" "$(3)/reth-data/reth.toml"; \ + for item in "$(3)/$(1)/reth-data/"*; do \ + [ -e "$$item" ] || continue; \ + base=$$(basename "$$item"); \ + rm -rf "$(3)/reth-data/$$base"; \ + mv "$$item" "$(3)/reth-data/" || { echo "Error: failed to move $$item."; exit 1; }; \ + done; \ + echo "Replacing node data in $(3)/node-data/data/..."; \ + rm -rf "$(3)/node-data/data/"* "$(3)/node-data/node-data"; \ + for item in "$(3)/$(1)/data/"*; do \ + [ -e "$$item" ] || continue; \ + mv "$$item" "$(3)/node-data/data/" || { echo "Error: failed to move $$item."; exit 1; }; \ + done; \ + rm -rf "$(3)/$(1)"; \ + [ -f "$(3)/reth-data/static-nodes.json" ] || cp "../$(4)/reth-data/static-nodes.json" "$(3)/reth-data/static-nodes.json" 2>/dev/null || echo "Warning: no static-nodes.json found in ../$(4)/reth-data/; --trusted-peers will be empty."; \ + [ -f "$(3)/node-data/data/priv_validator_state.json" ] || printf '{\n "height": "0",\n "round": 0,\n "step": 0\n}\n' > "$(3)/node-data/data/priv_validator_state.json"; \ echo "Reth snapshot data ready at $(3)."; \ fi endef @@ -282,47 +546,47 @@ endef quickstart-hoodi-node: generate-jwt-hoodi @echo "=== Quickstart: Hoodi Node (Docker) ===" - $(call setup-snapshot-data,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) - docker-compose --env-file .env_hoodi up node + $(call setup-snapshot-data,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(MORPH_HOME_HOODI),hoodi) + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) $(COMPOSE) --env-file .env_hoodi up quickstart-hoodi-node-binary: generate-jwt-hoodi build @echo "=== Quickstart: Hoodi Node (Binary) ===" - $(call setup-snapshot-data,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) + $(call setup-snapshot-data,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(MORPH_HOME_HOODI),hoodi) sh ./run-binary.sh .env_hoodi quickstart-mainnet-node: generate-jwt @echo "=== Quickstart: Mainnet Node (Docker) ===" - $(call setup-snapshot-data,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) - docker-compose --env-file .env up node + $(call setup-snapshot-data,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(MORPH_HOME_MAINNET),mainnet) + MORPH_UID=$$(id -u) MORPH_GID=$$(id -g) $(COMPOSE) --env-file .env up quickstart-mainnet-node-binary: generate-jwt build @echo "=== Quickstart: Mainnet Node (Binary) ===" - $(call setup-snapshot-data,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) + $(call setup-snapshot-data,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(MORPH_HOME_MAINNET),mainnet) sh ./run-binary.sh .env -## reth quickstart targets (use the reth snapshot + reth execution client) +## reth quickstart targets (use the reth snapshot + morph-reth execution client) quickstart-hoodi-reth-node: generate-jwt-hoodi @echo "=== Quickstart: Hoodi Node with reth (Docker) ===" - $(call setup-snapshot-data-reth,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) - docker-compose -f docker-compose.reth.yml --env-file .env_hoodi up node + $(call setup-snapshot-data-reth,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(RETH_HOME_HOODI),hoodi) + RETH_UID=$$(id -u) RETH_GID=$$(id -g) $(COMPOSE) -f docker-compose.reth.yml --env-file .env_hoodi up quickstart-hoodi-reth-node-binary: generate-jwt-hoodi build-reth-all @echo "=== Quickstart: Hoodi Node with reth (Binary) ===" - $(call setup-snapshot-data-reth,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) + $(call setup-snapshot-data-reth,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(RETH_HOME_HOODI),hoodi) sh ./run-binary-reth.sh .env_hoodi quickstart-mainnet-reth-node: generate-jwt @echo "=== Quickstart: Mainnet Node with reth (Docker) ===" - $(call setup-snapshot-data-reth,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) - docker-compose -f docker-compose.reth.yml --env-file .env up node + $(call setup-snapshot-data-reth,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(RETH_HOME_MAINNET),mainnet) + RETH_UID=$$(id -u) RETH_GID=$$(id -g) $(COMPOSE) -f docker-compose.reth.yml --env-file .env up quickstart-mainnet-reth-node-binary: generate-jwt build-reth-all @echo "=== Quickstart: Mainnet Node with reth (Binary) ===" - $(call setup-snapshot-data-reth,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) + $(call setup-snapshot-data-reth,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(RETH_HOME_MAINNET),mainnet) sh ./run-binary-reth.sh .env -# Common function for download and decompress +# Common function for download, SHA-256 verification, and decompression # $(1) = snapshot name, $(2) = download URL base, $(3) = target directory define download-and-decompress @echo "Checking for required tools (wget, tar)..."; \ @@ -335,43 +599,29 @@ define download-and-decompress exit 1; \ fi; \ echo "Tools are available."; \ - mkdir -p $(3); \ - echo "Downloading $(1).tar.gz from $(2)..."; \ - if wget -O $(3)/$(1).tar.gz $(2)/$(1).tar.gz; then \ - echo "$(1).tar.gz downloaded successfully."; \ - else \ - echo "Error downloading $(1).tar.gz."; \ - exit 1; \ - fi; \ + $(call fetch-and-verify-snapshot,$(1),$(2),$(3)); \ echo "Decompressing $(1).tar.gz..."; \ - if tar -xzvf $(3)/$(1).tar.gz -C $(3); then \ - echo "$(1).tar.gz decompressed successfully."; \ - else \ - echo "Error decompressing $(1).tar.gz."; \ - exit 1; \ - fi; \ - rm -rf $(3)/$(1).tar.gz; + $(call extract-tar-gz,$(3)/$(1).tar.gz,$(3)); \ + echo "$(1).tar.gz decompressed successfully."; \ + rm -f "$(3)/$(1).tar.gz"; endef # Targets download-and-decompress-mainnet-snapshot: - $(call download-and-decompress,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) + $(call download-and-decompress,$(MAINNET_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(MORPH_HOME_MAINNET)) download-and-decompress-hoodi-snapshot: - $(call download-and-decompress,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) + $(call download-and-decompress,$(HOODI_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(MORPH_HOME_HOODI)) ## reth snapshots (separate from the geth snapshots above) download-and-decompress-mainnet-reth-snapshot: - $(call download-and-decompress,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,../mainnet) + $(call download-and-decompress,$(MAINNET_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/mainnet,$(RETH_HOME_MAINNET)) download-and-decompress-hoodi-reth-snapshot: - $(call download-and-decompress,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,../hoodi) + $(call download-and-decompress,$(HOODI_RETH_SNAPSHOT_NAME),https://snapshot.morph.network/hoodi,$(RETH_HOME_HOODI)) # Backward-compatible aliases used in older PR/test plans download-and-decompress-mainnet-mpt-snapshot: download-and-decompress-mainnet-snapshot download-and-decompress-hoodi-mpt-snapshot: download-and-decompress-hoodi-snapshot - - - diff --git a/morph-node/docker-compose.reth.yml b/morph-node/docker-compose.reth.yml index b7a2e3a..0ce9978 100644 --- a/morph-node/docker-compose.reth.yml +++ b/morph-node/docker-compose.reth.yml @@ -1,25 +1,49 @@ services: reth: - container_name: morph-reth + container_name: ${RETH_CONTAINER_NAME:-morph-reth} image: ghcr.io/morph-l2/morph-reth:v1.5.0 + # The published morph-reth image drops privileges to USER morph-reth (~UID 999), + # which cannot write to host bind mounts owned by the host user or root on Linux. + # Makefile passes RETH_UID=$(id -u) RETH_GID=$(id -g) so the container runs as the + # host user; direct `docker compose` falls back to 0:0 (matching docker-compose.yml). + user: "${RETH_UID:-0}:${RETH_GID:-0}" restart: unless-stopped # give the process time to shut down cleanly on docker stop before it is SIGKILLed (default 10s) stop_grace_period: 2m + # MDBX + RocksDB + static_files + P2P easily exceed the legacy 1024 FD soft limit + ulimits: + nofile: + soft: 65535 + hard: 65535 + # Pure bash TCP probe (ubuntu:24.04 runtime image has no curl/wget/nc) + healthcheck: + test: ["CMD-SHELL", "bash -c 'exec 3<>/dev/tcp/127.0.0.1/8551'"] + interval: 15s + timeout: 5s + retries: 5 + start_period: 60s ports: - - "8545:8545" - - "8546:8546" + - "${RETH_RPC_PORT:-8545}:8545" + - "${RETH_WS_PORT:-8546}:8546" - "8551" - - "6060" - - "30303" + - "${RETH_METRICS_PORT:-6060}:6060" + - "${RETH_P2P_PORT:-30303}:30303" volumes: - "${RETH_HOME}/reth-data:/db" - - "${JWT_SECRET_FILE}:/jwt-secret.txt" - - "${RETH_ENTRYPOINT_FILE}:/entrypoint.sh" + - "${JWT_SECRET_FILE}:/jwt-secret.txt:ro" + - "${RETH_ENTRYPOINT_FILE}:/entrypoint.sh:ro" environment: # Chain spec: "mainnet" or "hoodi". - RETH_CHAIN=${RETH_CHAIN} - RETH_DATADIR=/db - - LOG_DIR=/db + - LOG_DIR=/db/logs + - RETH_LOG_FILTER=${RETH_LOG_FILTER:-info} + - RETH_HTTP_API=${RETH_HTTP_API:-web3,debug,eth,txpool,net,trace} + - RETH_WS_API=${RETH_WS_API:-web3,debug,eth,txpool,net,trace} + - RETH_PROOFS_HISTORY=${RETH_PROOFS_HISTORY:-false} + - RETH_PROOFS_WINDOW=${RETH_PROOFS_WINDOW:-} + - RETH_PROOF_PERMITS=${RETH_PROOF_PERMITS:-} + - RETH_EXTRA_FLAGS=${RETH_EXTRA_FLAGS:-} # static-nodes.json lives inside the reth-data volume (mounted at /db) and is # parsed into --trusted-peers by the entrypoint. If absent, --trusted-peers is # omitted rather than failing. @@ -34,11 +58,14 @@ services: # DERIVATION_VERIFY_MODE=layer1 (in .env/.env_hoodi) for the former validator # behavior. L1_BEACON_CHAIN_RPC is required in both modes. node: - container_name: morph-node + container_name: ${RETH_NODE_CONTAINER_NAME:-morph-node} depends_on: reth: condition: service_started image: ghcr.io/morph-l2/node:0.6.5 + # Run with the same host UID:GID as reth so node-data/ stays writable by the + # host user on Linux (for `make clean-*`, snapshot updates, and binary mode). + user: "${RETH_UID:-0}:${RETH_GID:-0}" restart: unless-stopped # give the process time to shut down cleanly on docker stop before it is SIGKILLed (default 10s) stop_grace_period: 1m @@ -48,8 +75,9 @@ services: - "26658" - "26660" environment: - - MORPH_NODE_L2_ETH_RPC=http://morph-reth:8545 - - MORPH_NODE_L2_ENGINE_RPC=http://morph-reth:8551 + # Use the compose service name `reth` so DNS works even when RETH_CONTAINER_NAME is overridden. + - MORPH_NODE_L2_ETH_RPC=http://reth:8545 + - MORPH_NODE_L2_ENGINE_RPC=http://reth:8551 - MORPH_NODE_L2_ENGINE_AUTH=/jwt-secret.txt - MORPH_NODE_L1_ETH_RPC=${L1_ETH_RPC} - MORPH_NODE_L1_ETH_BEACON_RPC=${L1_BEACON_CHAIN_RPC} @@ -65,8 +93,8 @@ services: - NODE_EXTRA_FLAGS=${NODE_EXTRA_FLAGS:-} volumes: - "${RETH_HOME}/node-data:/db" - - "${JWT_SECRET_FILE}:/jwt-secret.txt" - - "./entrypoint-node.sh:/entrypoint-node.sh" + - "${JWT_SECRET_FILE}:/jwt-secret.txt:ro" + - "./entrypoint-node.sh:/entrypoint-node.sh:ro" entrypoint: - "/bin/sh" - "/entrypoint-node.sh" diff --git a/morph-node/docker-compose.yml b/morph-node/docker-compose.yml index 61b486d..babaf5a 100644 --- a/morph-node/docker-compose.yml +++ b/morph-node/docker-compose.yml @@ -2,6 +2,10 @@ services: geth: container_name: morph-geth image: ghcr.io/morph-l2/go-ethereum:2.2.8 + # Makefile passes MORPH_UID=$(id -u) MORPH_GID=$(id -g) so host bind mounts stay + # owned by the host user on Linux (avoiding root-owned files when cleaning or + # switching to binary mode / reth); direct `docker compose` falls back to 0:0. + user: "${MORPH_UID:-0}:${MORPH_GID:-0}" restart: unless-stopped # give the process time to shut down cleanly on docker stop before it is SIGKILLed (default 10s) stop_grace_period: 2m @@ -13,8 +17,8 @@ services: - "30303" volumes: - "${MORPH_HOME}/geth-data:/db" - - "${JWT_SECRET_FILE}:/jwt-secret.txt" - - "${GETH_ENTRYPOINT_FILE}:/entrypoint.sh" + - "${JWT_SECRET_FILE}:/jwt-secret.txt:ro" + - "${GETH_ENTRYPOINT_FILE}:/entrypoint.sh:ro" environment: - MORPH_FLAG=${MORPH_FLAG} entrypoint: @@ -34,6 +38,7 @@ services: condition: service_started # morph main build with single-sequencer + --derivation.verify-mode support. image: ghcr.io/morph-l2/node:0.6.5 + user: "${MORPH_UID:-0}:${MORPH_GID:-0}" restart: unless-stopped # give the process time to shut down cleanly on docker stop before it is SIGKILLed (default 10s) stop_grace_period: 1m @@ -63,8 +68,8 @@ services: - NODE_EXTRA_FLAGS=${NODE_EXTRA_FLAGS:-} volumes: - "${MORPH_HOME}/node-data:/db" - - "${JWT_SECRET_FILE}:/jwt-secret.txt" - - "./entrypoint-node.sh:/entrypoint-node.sh" + - "${JWT_SECRET_FILE}:/jwt-secret.txt:ro" + - "./entrypoint-node.sh:/entrypoint-node.sh:ro" entrypoint: - "/bin/sh" - "/entrypoint-node.sh" diff --git a/morph-node/entrypoint-reth.sh b/morph-node/entrypoint-reth.sh index 3ce13cb..30ecf24 100755 --- a/morph-node/entrypoint-reth.sh +++ b/morph-node/entrypoint-reth.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -eu # Reth execution-client entrypoint. Mirrors entrypoint-geth.sh but launches # morph-reth instead of geth. The two clients use DIFFERENT snapshots (see the @@ -10,42 +11,101 @@ RETH_DATADIR=${RETH_DATADIR:-./db} JWT_PATH=${JWT_SECRET_PATH:-/jwt-secret.txt} # mainnet | hoodi (selects the built-in chain spec). RETH_CHAIN=${RETH_CHAIN:-mainnet} -# Directory reth writes its rotating log file into. -LOG_DIR=${LOG_DIR:-${RETH_DATADIR}} +# Directory reth writes its rotating log files into. +LOG_DIR=${LOG_DIR:-${RETH_DATADIR}/logs} +RETH_LOG_FILTER=${RETH_LOG_FILTER:-info} +# Exposed RPC namespaces. Note: morph-reth v1.5.0 exposes morph_ unconditionally +# and rejects "morph" in --http.api/--ws.api; once upgrading past v1.5.0 (PR #241), +# append ",morph" via RETH_HTTP_API / RETH_WS_API in .env/.env_hoodi. +RETH_HTTP_API=${RETH_HTTP_API:-web3,debug,eth,txpool,net,trace} +RETH_WS_API=${RETH_WS_API:-web3,debug,eth,txpool,net,trace} +# Optional historical proof index for prover-facing nodes. +RETH_PROOFS_HISTORY=${RETH_PROOFS_HISTORY:-false} +RETH_PROOFS_WINDOW=${RETH_PROOFS_WINDOW:-} +RETH_PROOF_PERMITS=${RETH_PROOF_PERMITS:-} +# Optional extra flags passed verbatim to `morph-reth node`. +RETH_EXTRA_FLAGS=${RETH_EXTRA_FLAGS:-} # static-nodes.json (JSON array of enode URLs). Its entries are joined with commas # and passed to --trusted-peers so reth dials the Morph boot nodes directly # (discovery is disabled below). STATIC_NODES_FILE=${STATIC_NODES_FILE:-} if [ ! -f "${JWT_PATH}" ]; then - echo "Error: jwt-secret.txt not found at ${JWT_PATH}." - echo "Please create it before starting the service." + echo "Error: jwt-secret.txt not found at ${JWT_PATH}." >&2 + echo "Please create it before starting the service." >&2 exit 1 fi mkdir -p "${LOG_DIR}" +# Optional historical proofs initialization (idempotent). Mainnet and Hoodi +# genesis blocks predate the Jade (ZK-trie -> MPT) fork, so proof history must +# only be anchored on a restored post-Jade paired snapshot, never an empty DB. +# +# The first `proofs init` copies the full state at the current tip into the proof +# DB and can take a long time on mainnet (progress/ETA logged as "Processed +# entries"). It commits in batches, resumes after an interruption as long as the +# chain tip has not moved, and exits promptly on SIGTERM/SIGINT. Run it in the +# background and forward stop signals: as PID 1 in Docker this shell would +# otherwise ignore SIGTERM until SIGKILL, and in binary mode a stop signal would +# kill only this shell and leave the init process running as an orphan. +if [ "${RETH_PROOFS_HISTORY}" = "true" ]; then + if [ ! -d "${RETH_DATADIR}/db" ]; then + echo "Error: RETH_PROOFS_HISTORY=true requires an existing post-Jade DB at ${RETH_DATADIR}/db." >&2 + echo "Restore a paired reth snapshot before enabling historical proofs." >&2 + exit 1 + fi + INIT_PID="" + STOP_SIGNAL="" + trap 'STOP_SIGNAL=TERM; [ -z "${INIT_PID}" ] || kill -TERM "${INIT_PID}" 2>/dev/null || true' TERM + trap 'STOP_SIGNAL=INT; [ -z "${INIT_PID}" ] || kill -INT "${INIT_PID}" 2>/dev/null || true' INT + echo "Running morph-reth proofs init (no-op if already initialized)..." + "${RETH_BIN}" proofs init \ + --chain "${RETH_CHAIN}" \ + --datadir "${RETH_DATADIR}" \ + --log.file.directory "${LOG_DIR}" & + INIT_PID=$! + # Forward a stop signal that arrived before INIT_PID was known. + [ -z "${STOP_SIGNAL}" ] || kill -"${STOP_SIGNAL}" "${INIT_PID}" 2>/dev/null || true + INIT_RC=0 + while kill -0 "${INIT_PID}" 2>/dev/null; do + # wait returns early (>128) when a trapped signal arrives; keep waiting for init to exit. + wait "${INIT_PID}" && INIT_RC=0 || INIT_RC=$? + done + trap - TERM INT + if [ -n "${STOP_SIGNAL}" ]; then + echo "morph-reth proofs init interrupted by SIG${STOP_SIGNAL}; it resumes on the next start." >&2 + if [ "${STOP_SIGNAL}" = "INT" ]; then exit 130; fi + exit 143 + fi + if [ "${INIT_RC}" -ne 0 ]; then + echo "Error: morph-reth proofs init failed (exit ${INIT_RC})." >&2 + exit "${INIT_RC}" + fi +fi + # Parse static-nodes.json (a JSON array of "enode://..." strings) into a single # comma-separated list for --trusted-peers. No jq dependency: strip everything # that isn't part of an enode URL, then squeeze the newlines into commas. TRUSTED_PEERS="" if [ -n "${STATIC_NODES_FILE}" ] && [ -f "${STATIC_NODES_FILE}" ]; then - TRUSTED_PEERS=$(grep -o 'enode://[^"]*' "${STATIC_NODES_FILE}" | paste -sd, -) + TRUSTED_PEERS=$(grep -o 'enode://[^"]*' "${STATIC_NODES_FILE}" 2>/dev/null | paste -sd, - || true) fi set -- "${RETH_BIN}" node \ --chain "${RETH_CHAIN}" \ --datadir "${RETH_DATADIR}" \ + --ipcdisable \ --http \ --http.addr 0.0.0.0 \ --http.port 8545 \ --http.corsdomain '*' \ - --http.api web3,eth,txpool,net,trace \ + --http.api "${RETH_HTTP_API}" \ --ws \ --ws.addr 0.0.0.0 \ --ws.port 8546 \ --ws.origins '*' \ - --ws.api web3,eth,txpool,net,trace \ + --ws.api "${RETH_WS_API}" \ --authrpc.addr 0.0.0.0 \ --authrpc.port 8551 \ --authrpc.jwtsecret "${JWT_PATH}" \ @@ -53,7 +113,17 @@ set -- "${RETH_BIN}" node \ --nat none \ --metrics 0.0.0.0:6060 \ --log.file.directory "${LOG_DIR}" \ - --log.file.filter info + --log.file.filter "${RETH_LOG_FILTER}" + +if [ "${RETH_PROOFS_HISTORY}" = "true" ]; then + set -- "$@" --proofs-history + if [ -n "${RETH_PROOFS_WINDOW}" ]; then + set -- "$@" --proofs-history.window "${RETH_PROOFS_WINDOW}" + fi + if [ -n "${RETH_PROOF_PERMITS}" ]; then + set -- "$@" --rpc.proof-permits "${RETH_PROOF_PERMITS}" + fi +fi # Only append --trusted-peers when we actually resolved some, so an empty/missing # static-nodes.json doesn't hand reth a bare flag with no value. @@ -61,4 +131,12 @@ if [ -n "${TRUSTED_PEERS}" ]; then set -- "$@" --trusted-peers "${TRUSTED_PEERS}" fi +# Append operator-provided extra flags without pathname globbing. +if [ -n "${RETH_EXTRA_FLAGS}" ]; then + set -f + # shellcheck disable=SC2086 + set -- "$@" ${RETH_EXTRA_FLAGS} + set +f +fi + exec "$@" diff --git a/morph-node/run-binary-reth.sh b/morph-node/run-binary-reth.sh index acfe191..c9a7a60 100755 --- a/morph-node/run-binary-reth.sh +++ b/morph-node/run-binary-reth.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -eu # Usage: run-binary-reth.sh [override-env-file] # env-file: .env | .env_hoodi @@ -6,90 +7,252 @@ # # Binary-mode launcher for the reth execution client + morphnode. Mirrors # run-binary.sh but starts morph-reth instead of geth. Reth uses a separate -# snapshot and data dir (${RETH_HOME}/reth-data); node-data is shared. +# snapshot and data dir (${RETH_HOME}/reth-data); node-data is shared by default. ENV_FILE=${1:-.env} OVERRIDE_ENV_FILE=${2:-} -# Source environment -set -a -. ./${ENV_FILE} +# Load env files (supports relative and absolute paths). +# Base env-file respects pre-existing caller environment variables (matching +# `docker compose --env-file` precedence); an explicit override-env-file layers on top. +load_env_file() { + file=$1 + override=$2 + case "${file}" in + /*|./*|../*) env_path="${file}" ;; + *) env_path="./${file}" ;; + esac + if [ ! -f "${env_path}" ]; then + echo "Error: env file not found: ${env_path}" >&2 + exit 1 + fi + if [ "${override}" = "1" ]; then + set -a + # shellcheck source=/dev/null + . "${env_path}" + set +a + return + fi + while IFS= read -r line || [ -n "${line}" ]; do + line=$(printf '%s' "${line}" | tr -d '\r') + trimmed=$(printf '%s' "${line}" | sed 's/^[[:space:]]*//') + case "${trimmed}" in + ""|\#*) continue ;; + esac + case "${trimmed}" in + *=*) + key=${trimmed%%=*} + val=${trimmed#*=} + case "${key}" in + *[!A-Za-z0-9_]*|[0-9]*|"") continue ;; + esac + if eval "[ \"\${${key}+set}\" = set ]"; then + continue + fi + case "${val}" in + \'*\') + val=${val#\'} + val=${val%\'} + eval "${key}=\${val}" + ;; + \"*\") + eval "${key}=${val}" + ;; + *) + set -f + eval "${key}=\"${val}\"" + set +f + ;; + esac + eval "export ${key}" + ;; + esac + done < "${env_path}" +} + +load_env_file "${ENV_FILE}" 0 if [ -n "${OVERRIDE_ENV_FILE}" ]; then - . ./${OVERRIDE_ENV_FILE} + load_env_file "${OVERRIDE_ENV_FILE}" 1 fi -set +a RETH_BINARY=${RETH_BINARY:-./bin/morph-reth} NODE_BINARY=${NODE_BINARY:-./bin/morphnode} +# Seconds to wait for the engine RPC (port 8551); 0 waits indefinitely. A crashed +# process is detected within a second either way. With RETH_PROOFS_HISTORY=true the +# first start runs `morph-reth proofs init` before the port opens, which can take far +# longer than a normal startup on mainnet, so the default there is no limit. +if [ "${RETH_PROOFS_HISTORY:-false}" = "true" ]; then + RETH_READY_TIMEOUT=${RETH_READY_TIMEOUT:-0} +else + RETH_READY_TIMEOUT=${RETH_READY_TIMEOUT:-120} +fi +case "${RETH_READY_TIMEOUT}" in + ''|*[!0-9]*) + echo "Error: RETH_READY_TIMEOUT must be a non-negative integer (got '${RETH_READY_TIMEOUT}')." >&2 + exit 1 + ;; +esac # Check binaries -if [ ! -f "${RETH_BINARY}" ]; then - echo "Error: morph-reth binary not found at ${RETH_BINARY}" - echo "Please build it (make build-reth) or place it in the bin/ directory." +if [ ! -x "${RETH_BINARY}" ]; then + echo "Error: morph-reth binary not found or not executable at ${RETH_BINARY}" >&2 + echo "Run 'make download-reth-binary' (Linux) or 'make build-reth' to obtain it." >&2 exit 1 fi -if [ ! -f "${NODE_BINARY}" ]; then - echo "Error: morphnode binary not found at ${NODE_BINARY}" - echo "Please download and place it in the bin/ directory." +if [ ! -x "${NODE_BINARY}" ]; then + echo "Error: morphnode binary not found or not executable at ${NODE_BINARY}" >&2 + echo "Run 'make build-morphnode' or place the binary in ./bin/." >&2 exit 1 fi -# Ensure data directories exist -mkdir -p "${RETH_HOME}/reth-data" +# Validate required node settings early +if [ -z "${L1_ETH_RPC:-}" ]; then + echo "Error: L1_ETH_RPC is empty in ${ENV_FILE}. Set a valid L1 execution RPC URL." >&2 + exit 1 +fi + +if [ -z "${L1_BEACON_CHAIN_RPC:-}" ]; then + echo "Error: L1_BEACON_CHAIN_RPC is empty in ${ENV_FILE}. Set a valid L1 Beacon REST API URL." >&2 + exit 1 +fi + +if [ -z "${RETH_DERIVATION_START_HEIGHT:-}" ] || [ -z "${RETH_L1_MSG_START_HEIGHT:-}" ] || [ -z "${RETH_L2_BASE_HEIGHT:-}" ]; then + echo "Error: RETH_DERIVATION_START_HEIGHT, RETH_L1_MSG_START_HEIGHT, and RETH_L2_BASE_HEIGHT must be set in ${ENV_FILE}." >&2 + exit 1 +fi + +# Ensure data and log directories exist +mkdir -p "${RETH_HOME}/reth-data/logs" mkdir -p "${RETH_HOME}/node-data" -# Cleanup on exit +case "${RETH_CHAIN:-mainnet}" in + mainnet) RETH_LOG_SUBDIR="2818/" ;; + hoodi) RETH_LOG_SUBDIR="2910/" ;; + *) RETH_LOG_SUBDIR="" ;; +esac + +# Portable TCP readiness check (does not require netcat on minimal hosts) +is_port_open() { + port=$1 + if command -v nc >/dev/null 2>&1; then + nc -z localhost "${port}" 2>/dev/null + return $? + elif command -v bash >/dev/null 2>&1; then + bash -c "exec 3<>/dev/tcp/127.0.0.1/${port}" 2>/dev/null + return $? + elif command -v curl >/dev/null 2>&1; then + curl -s --connect-timeout 1 "http://127.0.0.1:${port}" >/dev/null 2>&1 + rc=$? + # HTTP 401/403/405 still returns 0; exit code 7 means connection refused + [ "${rc}" -ne 7 ] && [ "${rc}" -ne 28 ] + return $? + elif command -v python3 >/dev/null 2>&1; then + python3 -c "import socket, sys; s = socket.create_connection(('127.0.0.1', int(sys.argv[1])), 1); s.close()" "${port}" 2>/dev/null + return $? + else + echo "Error: none of nc, bash, curl, or python3 is available to probe port ${port}." >&2 + return 1 + fi +} + +wait_for_pid_exit() { + pid=$1 + timeout=$2 + elapsed=0 + while kill -0 "${pid}" 2>/dev/null; do + if [ "${elapsed}" -ge "${timeout}" ]; then + echo "Warning: PID ${pid} did not exit within ${timeout}s." >&2 + return 1 + fi + sleep 1 + elapsed=$((elapsed + 1)) + done + return 0 +} + +CLEANED_UP=0 +# Graceful shutdown: stop morphnode first so Engine API calls cease, then stop +# morph-reth and wait for MDBX/static files to flush cleanly. cleanup() { + exit_code=${1:-0} + if [ "${CLEANED_UP}" -eq 1 ]; then + return + fi + CLEANED_UP=1 echo "" - echo "Stopping..." - [ -n "${RETH_PID:-}" ] && kill ${RETH_PID} 2>/dev/null - [ -n "${NODE_PID:-}" ] && kill ${NODE_PID} 2>/dev/null + echo "Stopping morphnode and morph-reth gracefully..." + if [ -n "${NODE_PID:-}" ] && kill -0 "${NODE_PID}" 2>/dev/null; then + kill -TERM "${NODE_PID}" 2>/dev/null || true + wait_for_pid_exit "${NODE_PID}" 60 || true + fi + if [ -n "${RETH_PID:-}" ] && kill -0 "${RETH_PID}" 2>/dev/null; then + kill -TERM "${RETH_PID}" 2>/dev/null || true + wait_for_pid_exit "${RETH_PID}" 120 || true + fi rm -f .reth.pid .node.pid - exit + exit "${exit_code}" } -trap cleanup INT TERM +trap 'cleanup 0' INT TERM # Validate entrypoint file case "${RETH_ENTRYPOINT_FILE}" in ./entrypoint-reth.sh) ;; *) - echo "Error: invalid RETH_ENTRYPOINT_FILE: ${RETH_ENTRYPOINT_FILE}" + echo "Error: invalid RETH_ENTRYPOINT_FILE: ${RETH_ENTRYPOINT_FILE}" >&2 exit 1 ;; esac # Start reth echo "Starting morph-reth..." -RETH_BINARY=${RETH_BINARY} \ -RETH_DATADIR=${RETH_HOME}/reth-data \ -LOG_DIR=${RETH_HOME}/reth-data \ -JWT_SECRET_PATH=${JWT_SECRET_FILE} \ -RETH_CHAIN=${RETH_CHAIN} \ -STATIC_NODES_FILE=${RETH_HOME}/reth-data/static-nodes.json \ -sh ${RETH_ENTRYPOINT_FILE} & +RETH_BINARY="${RETH_BINARY}" \ +RETH_DATADIR="${RETH_HOME}/reth-data" \ +LOG_DIR="${RETH_HOME}/reth-data/logs" \ +RETH_LOG_FILTER="${RETH_LOG_FILTER:-info}" \ +RETH_HTTP_API="${RETH_HTTP_API:-web3,debug,eth,txpool,net,trace}" \ +RETH_WS_API="${RETH_WS_API:-web3,debug,eth,txpool,net,trace}" \ +RETH_PROOFS_HISTORY="${RETH_PROOFS_HISTORY:-false}" \ +RETH_PROOFS_WINDOW="${RETH_PROOFS_WINDOW:-}" \ +RETH_PROOF_PERMITS="${RETH_PROOF_PERMITS:-}" \ +RETH_EXTRA_FLAGS="${RETH_EXTRA_FLAGS:-}" \ +JWT_SECRET_PATH="${JWT_SECRET_FILE}" \ +RETH_CHAIN="${RETH_CHAIN}" \ +STATIC_NODES_FILE="${RETH_HOME}/reth-data/static-nodes.json" \ +sh "${RETH_ENTRYPOINT_FILE}" & RETH_PID=$! echo "${RETH_PID}" > .reth.pid # Wait for reth engine RPC (port 8551) -echo "Waiting for reth to be ready..." -for i in $(seq 1 30); do - if nc -z localhost 8551 2>/dev/null; then +if [ "${RETH_READY_TIMEOUT}" -gt 0 ]; then + echo "Waiting for reth engine RPC (port 8551, timeout ${RETH_READY_TIMEOUT}s)..." +else + echo "Waiting for reth engine RPC (port 8551, no timeout)..." +fi +if [ "${RETH_PROOFS_HISTORY:-false}" = "true" ]; then + echo "RETH_PROOFS_HISTORY=true: 'morph-reth proofs init' runs before the port opens and can take a long time on first start (progress is logged as 'Processed entries')." +fi +elapsed=0 +while [ "${RETH_READY_TIMEOUT}" -eq 0 ] || [ "${elapsed}" -lt "${RETH_READY_TIMEOUT}" ]; do + if is_port_open 8551; then echo "Reth is ready." break fi - if ! kill -0 ${RETH_PID} 2>/dev/null; then - echo "Error: reth process exited unexpectedly." + if ! kill -0 "${RETH_PID}" 2>/dev/null; then + echo "Error: reth process exited unexpectedly. Check ${RETH_HOME}/reth-data/logs/${RETH_LOG_SUBDIR}reth.log." >&2 rm -f .reth.pid exit 1 fi sleep 1 + elapsed=$((elapsed + 1)) + if [ $((elapsed % 60)) -eq 0 ]; then + echo "Still waiting for reth engine RPC (${elapsed}s elapsed)..." + fi done -if ! nc -z localhost 8551 2>/dev/null; then - echo "Error: reth did not become ready within 30 seconds." - cleanup - exit 1 +if ! is_port_open 8551; then + echo "Error: reth did not become ready within ${RETH_READY_TIMEOUT} seconds." >&2 + cleanup 1 fi # Start morphnode. @@ -97,25 +260,54 @@ fi # prefers MORPH_NODE_* over the shared DERIVATION_*/L1_MSG_*/L2_BASE_* vars, so pass the # reth heights explicitly as MORPH_NODE_* to override the (geth) shared values. echo "Starting morphnode..." -NODE_BINARY=${NODE_BINARY} \ -NODE_HOME=${RETH_HOME}/node-data \ -JWT_SECRET_PATH=${JWT_SECRET_FILE} \ -MORPH_NODE_DERIVATION_START_HEIGHT=${RETH_DERIVATION_START_HEIGHT} \ -MORPH_NODE_DERIVATION_BASE_HEIGHT=${RETH_L2_BASE_HEIGHT} \ -MORPH_NODE_SYNC_START_HEIGHT=${RETH_L1_MSG_START_HEIGHT} \ +NODE_BINARY="${NODE_BINARY}" \ +NODE_HOME="${RETH_HOME}/node-data" \ +JWT_SECRET_PATH="${JWT_SECRET_FILE}" \ +MORPH_NODE_DERIVATION_START_HEIGHT="${RETH_DERIVATION_START_HEIGHT}" \ +MORPH_NODE_DERIVATION_BASE_HEIGHT="${RETH_L2_BASE_HEIGHT}" \ +MORPH_NODE_SYNC_START_HEIGHT="${RETH_L1_MSG_START_HEIGHT}" \ NODE_EXTRA_FLAGS="${NODE_EXTRA_FLAGS:-}" \ sh ./entrypoint-node.sh & NODE_PID=$! echo "${NODE_PID}" > .node.pid +# Catch immediate startup errors (bad config, missing RPC, permission errors) +sleep 2 +if ! kill -0 "${NODE_PID}" 2>/dev/null; then + echo "Error: morphnode exited immediately after startup. Check ${RETH_HOME}/node-data/node.log." >&2 + cleanup 1 +fi + echo "" echo "=========================================" echo " reth PID: ${RETH_PID}" echo " morphnode PID: ${NODE_PID}" -echo " reth log: ${RETH_HOME}/reth-data/reth.log" +echo " reth logs: ${RETH_HOME}/reth-data/logs/${RETH_LOG_SUBDIR}reth.log" echo " node log: ${RETH_HOME}/node-data/node.log" echo "=========================================" echo "Press Ctrl+C to stop both processes." echo "" -wait +while kill -0 "${RETH_PID}" 2>/dev/null && kill -0 "${NODE_PID}" 2>/dev/null; do + sleep 2 +done + +# Give `make stop-binary` a moment to clear PID files during a deliberate shutdown +sleep 1 +if ! kill -0 "${NODE_PID}" 2>/dev/null; then + if [ ! -f .node.pid ]; then + wait "${RETH_PID}" 2>/dev/null || true + exit 0 + fi + echo "Error: morphnode (PID ${NODE_PID}) exited unexpectedly. Check ${RETH_HOME}/node-data/node.log." >&2 + cleanup 1 +fi + +if ! kill -0 "${RETH_PID}" 2>/dev/null; then + if [ ! -f .reth.pid ]; then + wait "${NODE_PID}" 2>/dev/null || true + exit 0 + fi + echo "Error: morph-reth (PID ${RETH_PID}) exited unexpectedly. Check ${RETH_HOME}/reth-data/logs/${RETH_LOG_SUBDIR}reth.log." >&2 + cleanup 1 +fi diff --git a/morph-node/run-binary.sh b/morph-node/run-binary.sh index 40d402e..2ef6733 100755 --- a/morph-node/run-binary.sh +++ b/morph-node/run-binary.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -eu # Usage: run-binary.sh [override-env-file] # env-file: .env | .env_hoodi @@ -11,27 +12,94 @@ ENV_FILE=${1:-.env} OVERRIDE_ENV_FILE=${2:-} -# Source environment -set -a -. ./${ENV_FILE} +# Load env files (supports relative and absolute paths). +# Base env-file respects pre-existing caller environment variables (matching +# `docker compose --env-file` precedence); an explicit override-env-file layers on top. +load_env_file() { + file=$1 + override=$2 + case "${file}" in + /*|./*|../*) env_path="${file}" ;; + *) env_path="./${file}" ;; + esac + if [ ! -f "${env_path}" ]; then + echo "Error: env file not found: ${env_path}" >&2 + exit 1 + fi + if [ "${override}" = "1" ]; then + set -a + # shellcheck source=/dev/null + . "${env_path}" + set +a + return + fi + while IFS= read -r line || [ -n "${line}" ]; do + line=$(printf '%s' "${line}" | tr -d '\r') + trimmed=$(printf '%s' "${line}" | sed 's/^[[:space:]]*//') + case "${trimmed}" in + ""|\#*) continue ;; + esac + case "${trimmed}" in + *=*) + key=${trimmed%%=*} + val=${trimmed#*=} + case "${key}" in + *[!A-Za-z0-9_]*|[0-9]*|"") continue ;; + esac + if eval "[ \"\${${key}+set}\" = set ]"; then + continue + fi + case "${val}" in + \'*\') + val=${val#\'} + val=${val%\'} + eval "${key}=\${val}" + ;; + \"*\") + eval "${key}=${val}" + ;; + *) + set -f + eval "${key}=\"${val}\"" + set +f + ;; + esac + eval "export ${key}" + ;; + esac + done < "${env_path}" +} + +load_env_file "${ENV_FILE}" 0 if [ -n "${OVERRIDE_ENV_FILE}" ]; then - . ./${OVERRIDE_ENV_FILE} + load_env_file "${OVERRIDE_ENV_FILE}" 1 fi -set +a GETH_BINARY=${GETH_BINARY:-./bin/geth} NODE_BINARY=${NODE_BINARY:-./bin/morphnode} +GETH_READY_TIMEOUT=${GETH_READY_TIMEOUT:-120} # Check binaries -if [ ! -f "${GETH_BINARY}" ]; then - echo "Error: geth binary not found at ${GETH_BINARY}" - echo "Please download and place it in the bin/ directory." +if [ ! -x "${GETH_BINARY}" ]; then + echo "Error: geth binary not found or not executable at ${GETH_BINARY}" >&2 + echo "Run 'make build-geth' or place the binary in ./bin/." >&2 + exit 1 +fi + +if [ ! -x "${NODE_BINARY}" ]; then + echo "Error: morphnode binary not found or not executable at ${NODE_BINARY}" >&2 + echo "Run 'make build-morphnode' or place the binary in ./bin/." >&2 exit 1 fi -if [ ! -f "${NODE_BINARY}" ]; then - echo "Error: morphnode binary not found at ${NODE_BINARY}" - echo "Please download and place it in the bin/ directory." +# Validate required node settings early +if [ -z "${L1_ETH_RPC:-}" ]; then + echo "Error: L1_ETH_RPC is empty in ${ENV_FILE}. Set a valid L1 execution RPC URL." >&2 + exit 1 +fi + +if [ -z "${L1_BEACON_CHAIN_RPC:-}" ]; then + echo "Error: L1_BEACON_CHAIN_RPC is empty in ${ENV_FILE}. Set a valid L1 Beacon REST API URL." >&2 exit 1 fi @@ -39,67 +107,127 @@ fi mkdir -p "${MORPH_HOME}/geth-data" mkdir -p "${MORPH_HOME}/node-data" -# Cleanup on exit +# Portable TCP readiness check (does not require netcat on minimal hosts) +is_port_open() { + port=$1 + if command -v nc >/dev/null 2>&1; then + nc -z localhost "${port}" 2>/dev/null + return $? + elif command -v bash >/dev/null 2>&1; then + bash -c "exec 3<>/dev/tcp/127.0.0.1/${port}" 2>/dev/null + return $? + elif command -v curl >/dev/null 2>&1; then + curl -s --connect-timeout 1 "http://127.0.0.1:${port}" >/dev/null 2>&1 + rc=$? + # HTTP 401/403/405 still returns 0; exit code 7 means connection refused + [ "${rc}" -ne 7 ] && [ "${rc}" -ne 28 ] + return $? + elif command -v python3 >/dev/null 2>&1; then + python3 -c "import socket, sys; s = socket.create_connection(('127.0.0.1', int(sys.argv[1])), 1); s.close()" "${port}" 2>/dev/null + return $? + else + echo "Error: none of nc, bash, curl, or python3 is available to probe port ${port}." >&2 + return 1 + fi +} + +wait_for_pid_exit() { + pid=$1 + timeout=$2 + elapsed=0 + while kill -0 "${pid}" 2>/dev/null; do + if [ "${elapsed}" -ge "${timeout}" ]; then + echo "Warning: PID ${pid} did not exit within ${timeout}s." >&2 + return 1 + fi + sleep 1 + elapsed=$((elapsed + 1)) + done + return 0 +} + +CLEANED_UP=0 +# Graceful shutdown: stop morphnode first so Engine API calls cease, then stop +# geth and wait for DB/trie cache flush. cleanup() { + exit_code=${1:-0} + if [ "${CLEANED_UP}" -eq 1 ]; then + return + fi + CLEANED_UP=1 echo "" - echo "Stopping..." - [ -n "${GETH_PID:-}" ] && kill ${GETH_PID} 2>/dev/null - [ -n "${NODE_PID:-}" ] && kill ${NODE_PID} 2>/dev/null + echo "Stopping morphnode and geth gracefully..." + if [ -n "${NODE_PID:-}" ] && kill -0 "${NODE_PID}" 2>/dev/null; then + kill -TERM "${NODE_PID}" 2>/dev/null || true + wait_for_pid_exit "${NODE_PID}" 60 || true + fi + if [ -n "${GETH_PID:-}" ] && kill -0 "${GETH_PID}" 2>/dev/null; then + kill -TERM "${GETH_PID}" 2>/dev/null || true + wait_for_pid_exit "${GETH_PID}" 120 || true + fi rm -f .geth.pid .node.pid - exit + exit "${exit_code}" } -trap cleanup INT TERM +trap 'cleanup 0' INT TERM # Validate entrypoint file case "${GETH_ENTRYPOINT_FILE}" in ./entrypoint-geth.sh) ;; *) - echo "Error: invalid GETH_ENTRYPOINT_FILE: ${GETH_ENTRYPOINT_FILE}" + echo "Error: invalid GETH_ENTRYPOINT_FILE: ${GETH_ENTRYPOINT_FILE}" >&2 exit 1 ;; esac # Start geth echo "Starting geth..." -GETH_BINARY=${GETH_BINARY} \ -GETH_DATADIR=${MORPH_HOME}/geth-data \ -JWT_SECRET_PATH=${JWT_SECRET_FILE} \ -MORPH_FLAG=${MORPH_FLAG} \ -sh ${GETH_ENTRYPOINT_FILE} & +GETH_BINARY="${GETH_BINARY}" \ +GETH_DATADIR="${MORPH_HOME}/geth-data" \ +JWT_SECRET_PATH="${JWT_SECRET_FILE}" \ +MORPH_FLAG="${MORPH_FLAG}" \ +sh "${GETH_ENTRYPOINT_FILE}" & GETH_PID=$! echo "${GETH_PID}" > .geth.pid # Wait for geth engine RPC (port 8551) -echo "Waiting for geth to be ready..." -for i in $(seq 1 30); do - if nc -z localhost 8551 2>/dev/null; then +echo "Waiting for geth engine RPC (port 8551, timeout ${GETH_READY_TIMEOUT}s)..." +elapsed=0 +while [ "${elapsed}" -lt "${GETH_READY_TIMEOUT}" ]; do + if is_port_open 8551; then echo "Geth is ready." break fi - if ! kill -0 ${GETH_PID} 2>/dev/null; then - echo "Error: geth process exited unexpectedly." + if ! kill -0 "${GETH_PID}" 2>/dev/null; then + echo "Error: geth process exited unexpectedly. Check ${MORPH_HOME}/geth-data/geth.log." >&2 rm -f .geth.pid exit 1 fi sleep 1 + elapsed=$((elapsed + 1)) done -if ! nc -z localhost 8551 2>/dev/null; then - echo "Error: geth did not become ready within 30 seconds." - cleanup - exit 1 +if ! is_port_open 8551; then + echo "Error: geth did not become ready within ${GETH_READY_TIMEOUT} seconds." >&2 + cleanup 1 fi # Start morphnode echo "Starting morphnode..." -NODE_BINARY=${NODE_BINARY} \ -NODE_HOME=${MORPH_HOME}/node-data \ -JWT_SECRET_PATH=${JWT_SECRET_FILE} \ +NODE_BINARY="${NODE_BINARY}" \ +NODE_HOME="${MORPH_HOME}/node-data" \ +JWT_SECRET_PATH="${JWT_SECRET_FILE}" \ NODE_EXTRA_FLAGS="${NODE_EXTRA_FLAGS:-}" \ sh ./entrypoint-node.sh & NODE_PID=$! echo "${NODE_PID}" > .node.pid +# Catch immediate startup errors (bad config, missing RPC, permission errors) +sleep 2 +if ! kill -0 "${NODE_PID}" 2>/dev/null; then + echo "Error: morphnode exited immediately after startup. Check ${MORPH_HOME}/node-data/node.log." >&2 + cleanup 1 +fi + echo "" echo "=========================================" echo " geth PID: ${GETH_PID}" @@ -110,4 +238,26 @@ echo "=========================================" echo "Press Ctrl+C to stop both processes." echo "" -wait +while kill -0 "${GETH_PID}" 2>/dev/null && kill -0 "${NODE_PID}" 2>/dev/null; do + sleep 2 +done + +# Give `make stop-binary` a moment to clear PID files during a deliberate shutdown +sleep 1 +if ! kill -0 "${NODE_PID}" 2>/dev/null; then + if [ ! -f .node.pid ]; then + wait "${GETH_PID}" 2>/dev/null || true + exit 0 + fi + echo "Error: morphnode (PID ${NODE_PID}) exited unexpectedly. Check ${MORPH_HOME}/node-data/node.log." >&2 + cleanup 1 +fi + +if ! kill -0 "${GETH_PID}" 2>/dev/null; then + if [ ! -f .geth.pid ]; then + wait "${NODE_PID}" 2>/dev/null || true + exit 0 + fi + echo "Error: geth (PID ${GETH_PID}) exited unexpectedly. Check ${MORPH_HOME}/geth-data/geth.log." >&2 + cleanup 1 +fi diff --git a/morph-reth b/morph-reth new file mode 160000 index 0000000..c25b9a3 --- /dev/null +++ b/morph-reth @@ -0,0 +1 @@ +Subproject commit c25b9a37daaba8eb8d9e6705607e4d32dad46b13