init.sh


Overview

[init.sh](/projects/291/68855) is a shell script designed to initialize and run the **Nitro** node software for the Arbitrum One blockchain (chain ID 42161). The script handles starting the Nitro node with specific configuration parameters, managing its lifecycle, and gracefully stopping the process upon receiving termination signals.

This script plays a critical role in the deployment and operation of the Nitro node, which is a key component for interacting with the Arbitrum blockchain network. It configures network endpoints, API exposure, logging, and operational flags needed for the node to function correctly within the environment.


Detailed Breakdown

Script Execution Environment

#!/bin/sh
set -e
[ "$DEBUG" = "true" ] && set -x

Functions


start()

Starts the Nitro node process with a specific set of command-line options.

Implementation
start() {
  /usr/local/bin/nitro \
  --chain.id 42161 \
  --chain.name arb1 \
  --parent-chain.connection.url $L1_RPC_ENDPOINT \
  --parent-chain.blob-client.beacon-url $L1_BEACON_ENDPOINT \
  --init.url 'https://snapshot.arbitrum.foundation/arb1/nitro-pruned.tar' \
  --init.download-path /data/tmp \
  --persistent.chain /data \
  --auth.jwtsecret /jwt.hex \
  --file-logging.enable='false' \
  --http.addr 0.0.0.0 \
  --http.port 8547 \
  --http.api eth,net,web3,debug,txpool,arb \
  --http.vhosts '*' \
  --http.corsdomain '*' \
  --ws.addr 0.0.0.0 \
  --ws.port 8548 \
  --ws.api eth,net,web3,debug,txpool,arb \
  --ws.origins '*' \
  --node.staker.enable='false' \
  --execution.tx-lookup-limit 0 &
  PID="$!"
}
Parameters
Behavior
Returns
Usage Example
start
# Nitro node starts running in background with configured settings

stop()

Gracefully stops the Nitro node process.

Implementation
stop() {
  echo "Catching signal and sending to PID: $PID" && kill $PID
  while $(kill -0 $PID 2>/dev/null); do sleep 1; done
}
Parameters
Behavior
Returns
Usage Example
stop
# Sends SIGTERM to Nitro node and waits for it to exit

Signal Handling

trap 'stop' TERM INT

Script Execution Flow

start
wait $PID

Important Implementation Details


Interaction with Other System Components


Visual Diagram

flowchart TD
    Start["start() function"]
    Nitro["/usr/local/bin/nitro executable"]
    EnvVars[L1_RPC_ENDPOINT, L1_BEACON_ENDPOINT]
    InitURL["Snapshot URL\n'https://snapshot.arbitrum.foundation/arb1/nitro-pruned.tar'"]
    Storage["Persistent Storage (/data, /data/tmp)"]
    APIs["HTTP & WebSocket APIs\n(eth, net, web3, debug, txpool, arb)"]
    Trap["trap 'stop' TERM INT"]
    StopFunc["stop() function"]

    Start --> Nitro
    Nitro -->|Uses| EnvVars
    Nitro -->|Downloads snapshot from| InitURL
    Nitro -->|Stores data in| Storage
    Nitro --> APIs
    Trap --> StopFunc
    StopFunc --> Nitro
    Nitro -->|Background process PID stored in| PID["PID variable"]
    Start -->|Stores PID| PID
    StopFunc -->|Sends SIGTERM to| PID

Summary


Usage Notes


End of Documentation for init.sh