index.ts


Overview

This file serves as the Pulumi deployment entrypoint for the **Binance Smart Chain (bnbsmartchain)** coinstack within the Unchained platform. Its primary role is to orchestrate the deployment of blockchain services—including daemon nodes and indexers—onto Kubernetes by:

It encapsulates the service definitions and customization needed to run Binance Smart Chain node and indexer services with appropriate ports, environment variables, config maps, volume mounts, and Kubernetes health probes.


Detailed Explanation of the File Content

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 (Pulumi Entrypoint)

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

Variables and Configuration Loading

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

Mapping Stateful Services to Deployment Arguments

const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
  switch (service.name) {
    case 'daemon':
      return {
        ...service,
        ports: {
          'daemon-rpc': { port: 8545 },
          'daemon-ws': { port: 8546, pathPrefix: '/websocket', stripPathPrefix: true },
        },
        env: {
          SNAPSHOT: 'https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/geth-pbss-pebble-20231217.tar.lz4',
        },
        configMapData: { 'evm.sh': readFileSync('../../../scripts/evm.sh').toString() },
        volumeMounts: [{ name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' }],
        startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 },
        livenessProbe: { periodSeconds: 30, failureThreshold: 5, timeoutSeconds: 10 },
        readinessProbe: { periodSeconds: 30, failureThreshold: 10 },
      }
    case 'indexer':
      return {
        ...service,
        ...defaultBlockbookServiceArgs,
        configMapData: { 'indexer-config.json': readFileSync('../indexer/config.json').toString() },
      }
    default:
      throw new Error(`no support for coin service: ${service.name}`)
  }
})

Daemon service parameters:

Indexer service parameters:

Error Handling:


Deployment Invocation

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

Usage Example

This file is not directly invoked by users but executed by the Pulumi CLI during deployment.

Typical usage flow:

pulumi up -s <stack-name>

Pulumi runs this script, which:


Important Implementation Details and Algorithms


Interaction with Other System Components


Mermaid Diagram: Flowchart of the Deployment Workflow in index.ts

flowchart TD
  A[Start Deployment] --> B[Read sample.env file]
  B --> C[Call getConfig() to load kubeconfig, config, namespace]
  C --> D[Iterate over config.statefulService.services]
  D --> E{Service Name?}
  E -->|daemon| F[Construct Daemon Deployment Args
  (Ports, Env, ConfigMap, Probes, Volumes)]
  E -->|indexer| G[Construct Indexer Deployment Args
  (Default Blockbook Args, ConfigMap)]
  E -->|Other| H[Throw Error: Unsupported Service]
  F --> I[Collect all CoinServiceArgs]
  G --> I
  I --> J[Call deployCoinstack() with all args]
  J --> K[Provision Kubernetes resources]
  K --> L[Deploy StatefulSets, Services, ConfigMaps]
  L --> M[Daemon and Indexer Pods start with health probes]
  M --> N[Deployment complete with Outputs returned]

Summary

The **index.ts** file is the deployment script for the Binance Smart Chain coinstack in Unchained’s multi-blockchain infrastructure. Its key responsibilities are:

This script fits into the larger Pulumi-based infrastructure automation framework enabling consistent, scalable, and maintainable deployments of blockchain nodes and indexers across different chains.


If you require further detail on related modules or deployment workflows, please refer to the **Multi-Blockchain Coinstacks** documentation and the shared Pulumi libraries.