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:
Reads environment and configuration files.
Retrieves Kubernetes context and coinstack configuration.
Maps configured Polygon services to detailed deployment arguments (
CoinServiceArgs), including ports, environment variables, configuration files, volume mounts, and health probes.Calls the
deployCoinstackfunction to deploy these services as Kubernetes StatefulSets, Services, and ConfigMaps.Supports Polygon-specific service customization, including snapshot URLs, RPC/WebSocket endpoints, and specialized services like Heimdall for consensus.
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:
Loads necessary environment data and configuration.
Prepares deployment arguments for each Polygon blockchain service in the coinstack.
Invokes
deployCoinstackto deploy the configured services into Kubernetes.Returns an
Outputsobject representing the deployed infrastructure outputs.
Steps Breakdown
Constants Initialization
const appName = 'unchained' const coinstack = 'polygon'These identify the application and blockchain stack being deployed.
Read Sample Environment File
const sampleEnv = readFileSync('../sample.env')Reads a sample environment variable file, which may be used during deployment or for reference.
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.
Destructure Relevant Config Fields
const { network, statefulService } = configExtracts the blockchain network identifier and the list of stateful services to deploy.
Map Services to Deployment Arguments
const coinServiceArgs = statefulService?.services?.map((service): CoinServiceArgs => { ... })For each service defined in the configuration, the script creates a
CoinServiceArgsobject 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.
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-rpcon port 8545.daemon-wson port 8546 with WebSocket path prefix/websocketand path stripping enabled.
Mounts a shell script
evm.shfrom 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-apion 1317 with/lcdprefix.heimdall-rpcon 26657 with/rpcprefix.
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.jsonto 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.)
Deploy the Coinstack
return deployCoinstack({ appName, coinServiceArgs, coinstack, coinstackType: 'node', config, kubeconfig, namespace, sampleEnv, })Calls the shared
deployCoinstackfunction with all necessary parameters, which handles Kubernetes resource creation.
Important Implementations and Algorithms
Dynamic Service Argument Generation
The service arguments (
CoinServiceArgs) are dynamically constructed based on the service name, enabling flexible configuration per service type.Use of Kubernetes Probes
Startup, liveness, and readiness probes ensure Kubernetes can properly manage pod lifecycle and health. The thresholds and timeouts are tuned per service.
ConfigMap-Based Configuration Injection
Configuration files and scripts (e.g.,
evm.sh,indexer-config.json) are read from disk at deployment time and injected into pods via ConfigMaps and volume mounts for flexibility.Cluster-Local Networking
Environment variables like
ETH_RPC_URLuse Kubernetes internal DNS names to enable inter-service communication within the cluster.
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:
Run this script.
Deploy the Polygon coinstack services as defined.
Output deployment status and resource information.
Interactions with Other System Components
Pulumi Core Library (
pulumi/src/coinstack)Provides the
deployCoinstackfunction and shared types likeOutputsandCoinServiceArgs.Configuration Utilities (
pulumi/src)The
getConfig()function fetches Kubernetes and coinstack configuration.Polygon Coinstack
This script is specific to the Polygon coinstack, part of the multi-blockchain system.
Blockbook Indexer Constants
Uses default constants for Blockbook-based indexers via
defaultBlockbookServiceArgs.Kubernetes Cluster
The deployed services run as StatefulSets in Kubernetes, interacting via cluster networking.
Scripts and Config Files
Reads local files like
../sample.env,../../../scripts/evm.sh, and../indexer/config.jsonto configure services.
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
The index.ts file is a specialized Pulumi deployment script for the Polygon blockchain coinstack.
It dynamically configures and deploys multiple Polygon services — daemon, heimdall, and indexer — to Kubernetes.
It leverages shared utilities and configuration files to provide flexible, production-ready deployments.
Health checks, environment variables, ports, and volume mounts are carefully configured per service.
It integrates tightly with the overall multi-blockchain coinstacks architecture and Pulumi infrastructure-as-code workflows.
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.