index.ts


Overview

This file serves as the Pulumi deployment entrypoint for the **Ethereum coinstack** within the Unchained multi-blockchain infrastructure platform. It defines the Kubernetes deployment configuration and parameters for Ethereum node services—including the primary daemon node, beacon daemon, and indexer—by reading configuration files and environment settings, then invoking a shared deployment utility to provision these services.

In essence, it automates the deployment of Ethereum blockchain infrastructure components into Kubernetes by:

This file is specific to the Ethereum coinstack and reflects Ethereum’s multi-service architecture, including JSON-RPC, WebSocket RPC, authenticated RPC, and beacon node components.


Detailed Breakdown

Imports

import { readFileSync } from 'fs'
import { deployCoinstack } from '../../../../pulumi/src/coinstack'
import { Outputs, CoinServiceArgs, getConfig } from '../../../../pulumi/src'
import { defaultBlockbookServiceArgs } from '../../../packages/blockbook/src/constants'

Exported Async Function (Default Export)

export = async (): Promise<Outputs> => { ... }

This is the Pulumi entrypoint function executed during deployment. It returns a Promise resolving to `Outputs` which represent the result of the deployment (e.g., service endpoints, resource IDs).


Variables and Configuration Loading

const sampleEnv = readFileSync('../sample.env')
const { kubeconfig, config, namespace } = await getConfig()

Service Argument Mapping

The core logic converts the configured services in `config.statefulService?.services` into an array of `CoinServiceArgs` objects, each describing how to deploy a particular service.

const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
  switch (service.name) {
    case 'daemon':
      // ... configuration for Ethereum daemon node ...
    case 'daemon-beacon':
      // ... configuration for beacon node daemon ...
    case 'indexer':
      // ... configuration for indexer service ...
    default:
      throw new Error(`no support for coin service: ${service.name}`)
  }
})

Service: daemon

This configuration ensures the Ethereum daemon pod is properly instrumented for health checks and has access to required secrets and scripts.

Service: daemon-beacon

This represents the Ethereum beacon node service which handles consensus layer duties.

Service: indexer

This configures the indexer service for Ethereum blockchain data indexing and query APIs.


Deployment Call

After constructing the `coinServiceArgs` array, the function calls `deployCoinstack()` to perform the deployment.

return deployCoinstack({
  appName,
  coinServiceArgs,
  coinstack,
  coinstackType: 'node',
  config,
  kubeconfig,
  namespace,
  sampleEnv,
})

`deployCoinstack` ultimately provisions Kubernetes resources such as StatefulSets, Services, ConfigMaps, and IngressRoutes according to these parameters.


Important Implementation Details


Interaction with Other System Components


Usage Example

This file is not typically invoked directly by developers. Instead, it is used by the Pulumi CLI as the deployment entrypoint for the Ethereum coinstack.

From the project root, a typical deployment command might be:

pulumi up --cwd coinstacks/ethereum/pulumi

Pulumi will execute this module's exported async function, which reads configuration, maps services, and triggers Kubernetes resource creation.


Mermaid Diagram: Structure of index.ts

flowchart TD
  A[Start Deployment] --> B[Read sample.env & config files]
  B --> C[Retrieve kubeconfig, config, namespace]
  C --> D[Map config.statefulService.services]
  D --> E{Service Name}
  E -->|daemon| F[Configure daemon service args]
  E -->|daemon-beacon| G[Configure beacon service args]
  E -->|indexer| H[Configure indexer service args]
  E -->|unknown| I[Throw error]
  F --> J[Add ports, env, probes, volume mounts]
  G --> K[Add args, volume mounts, monitor container, probes]
  H --> L[Add defaultBlockbookServiceArgs, configMapData]
  J & K & L --> M[Aggregate coinServiceArgs array]
  M --> N[Call deployCoinstack() with args]
  N --> O[Provision Kubernetes resources]
  O --> P[Deployment complete]

Summary

The `index.ts` file is a Pulumi deployment script for the Ethereum coinstack in the Unchained platform. It reads configuration files and Kubernetes context, maps blockchain node services to detailed deployment arguments, and calls a shared deployment function that provisions these services into Kubernetes. The file specifically configures Ethereum’s daemon node, beacon node, and indexer with appropriate ports, environment variables, startup arguments, volume mounts, and health probes to ensure robust, scalable blockchain infrastructure deployments.

This modular, declarative approach facilitates consistent multi-blockchain deployments within a Kubernetes environment and integrates tightly with the broader Pulumi infrastructure-as-code system used throughout the Unchained project.