index.ts

Overview

This file is a Pulumi deployment entrypoint script designed to provision and configure the Polygon blockchain coinstack within the ShapeShift Unchained platform. It orchestrates the setup of multiple stateful services (daemon nodes, Heimdall, and indexer) by preparing configuration arguments and invoking a shared deployment utility to create Kubernetes resources.

Specifically, it:

This file is a key part of the multi-blockchain coinstacks architecture, enabling the Polygon blockchain node infrastructure to be declaratively deployed and managed in a Kubernetes environment.


Detailed Explanation

Exported Async Function (Default Export)

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

Purpose

The exported asynchronous function is the Pulumi program entrypoint. When run by Pulumi, it performs the following:

Steps Breakdown

  1. Constants Initialization

    const appName = 'unchained'
    const coinstack = 'polygon'
    

    These identify the application and blockchain stack being deployed.

  2. Read Sample Environment File

    const sampleEnv = readFileSync('../sample.env')
    

    Reads a sample environment variable file, which may be used during deployment or for reference.

  3. Retrieve Kubernetes and App Configuration

    const { kubeconfig, config, namespace } = await getConfig()
    

    Calls a shared utility getConfig() to asynchronously fetch:

    • kubeconfig: Kubernetes cluster access config.

    • config: The Polygon coinstack configuration, including network and services.

    • namespace: Kubernetes namespace to deploy resources.

  4. Destructure Relevant Config Fields

    const { network, statefulService } = config
    

    Extracts the blockchain network identifier and the list of stateful services to deploy.

  5. Map Services to Deployment Arguments

    const coinServiceArgs = statefulService?.services?.map((service): CoinServiceArgs => { ... })
    

    For each service defined in the configuration, the script creates a CoinServiceArgs object that specifies how to deploy the service. The mapping logic handles three specific service names:

    • daemon

    • heimdall

    • indexer

    If an unsupported service name is encountered, it throws an error.

  6. Service-Specific Configuration Details

    • Daemon Service

      • Adds environment variables:

        • NETWORK: The blockchain network name.

        • SNAPSHOT: URL to a Polygon snapshot shell script for node bootstrap.

      • Defines ports:

        • daemon-rpc on port 8545.

        • daemon-ws on port 8546 with WebSocket path prefix /websocket and path stripping enabled.

      • Mounts a shell script evm.sh from a ConfigMap for node lifecycle hooks.

      • Configures startup, liveness, and readiness probes with specified intervals and thresholds.

    • Heimdall Service

      • Sets the data directory to /root.

      • Defines ports:

        • heimdall-api on 1317 with /lcd prefix.

        • heimdall-rpc on 26657 with /rpc prefix.

      • Sets environment variables:

        • ETH_RPC_URL: internal URL pointing to the Ethereum RPC service within the cluster.

        • SNAPSHOT: Polygon snapshot URL.

      • Configures probes with healthy thresholds and timeouts.

    • Indexer Service

      • Reads indexer/config.json to get indexer-specific configuration.

      • Merges default Blockbook service arguments (defaultBlockbookServiceArgs).

      • Injects the JSON config as a ConfigMap named indexer-config.json.

      • (Commented code hints at optional remote endpoint configuration.)

  7. Deploy the Coinstack

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

    Calls the shared deployCoinstack function with all necessary parameters, which handles Kubernetes resource creation.


Important Implementations and Algorithms


Usage Example

This file itself is intended to be executed by the Pulumi CLI as part of infrastructure deployment. Example usage:

pulumi up --cwd path/to/polygon/pulumi

The Pulumi engine will:


Interactions with Other System Components


Mermaid Diagram: Flowchart of This File's Deployment Process

flowchart TD
    A[Start Pulumi Deployment] --> B[Read sample.env file]
    B --> C[Call getConfig() to fetch kubeconfig, config, namespace]
    C --> D[Extract network and statefulService from config]
    D --> E[Map each service in statefulService.services]
    E --> F{Service.name}
    F -->|daemon| G[Create daemon CoinServiceArgs]
    F -->|heimdall| H[Create heimdall CoinServiceArgs]
    F -->|indexer| I[Create indexer CoinServiceArgs]
    F -->|other| J[Throw Error: Unsupported service]
    G & H & I --> K[Collect all CoinServiceArgs]
    K --> L[Call deployCoinstack with all args]
    L --> M[Deploy Kubernetes StatefulSets, Services, ConfigMaps]
    M --> N[End Deployment with Outputs]

Summary


If you need to extend or customize Polygon deployment, modify the service mapping logic in this file or update corresponding configuration files like `sample.env` or `indexer/config.json`. This approach ensures maintainability and consistency with other blockchain coinstack deployments.