init.sh


Overview

`init.sh` is a shell script designed to manage the lifecycle of an Ethereum-compatible blockchain daemon (`geth`) within a containerized environment. Its primary purpose is to:

This script is a critical component in the Daemon Node Management subsystem, enabling robust and controlled execution of the blockchain node within multi-blockchain coinstack deployments.


Detailed Explanation

Shell Environment Setup

#!/bin/sh
set -e

Dependency Installation

apk add bash curl jq

These dependencies ensure the environment is ready for any downstream scripts or commands requiring these utilities.


Function: start_coin_bg

start_coin_bg() {
  geth \
    --$NETWORK \
    --authrpc.jwtsecret /jwt.hex \
    --syncmode full \
    --datadir /data \
    --db.engine pebble \
    --http \
    --http.addr 0.0.0.0 \
    --http.port 8545 \
    --http.api eth,net,web3,debug,txpool,engine \
    --http.vhosts '*' \
    --http.corsdomain '*' \
    --ws \
    --ws.addr 0.0.0.0 \
    --ws.port 8546 \
    --ws.api eth,net,web3,debug,txpool,engine \
    --ws.origins '*' \
    --state.scheme path \
    --history.transactions 0 \
    --ipcdisable \
    --nat none &
  PID="$!"
}

Function: stop_coin

stop_coin() {
  echo "Catching signal and sending to PID: $PID"
  kill $PID
  while $(kill -0 $PID 2>/dev/null); do
    sleep 1
  done
}

Main Execution Flow

start_coin_bg

trap 'stop_coin' SIGTERM SIGINT

wait $PID

Usage Example

This script is generally invoked as the `ENTRYPOINT` or `CMD` in a container running an Ethereum-compatible node. Typical usage:

# Environment variable specifying network, e.g., mainnet, goerli
export NETWORK=mainnet

# Run the script (usually container startup)
./init.sh

Important Implementation Details


Integration with the System


Visual Diagram

flowchart TD
    A[Start Container] --> B[Install Dependencies (bash, curl, jq)]
    B --> C[Invoke start_coin_bg]
    C --> D[Launch geth daemon (background)]
    D --> E[Capture geth PID]
    E --> F[Wait on geth PID]
    F -->|SIGTERM or SIGINT Received| G[Invoke stop_coin]
    G --> H[Send SIGTERM to geth PID]
    H --> I[Poll geth process until exited]
    I --> J[Exit Script and Container]

Summary

`init.sh` encapsulates the lifecycle management logic for an Ethereum node container, ensuring:

This script is a reusable, robust foundation for running Ethereum nodes in containerized blockchain infrastructure, aligning with Kubernetes best practices and the broader multi-blockchain node management framework.