|
| 1 | +# Dynamic Local Test Environment |
| 2 | + |
| 3 | +This document outlines the setup and operation of the dynamic local test environment for Partner Chains. This environment is designed for flexibility, allowing developers to easily configure and launch a large-scale network of Partner Chains nodes with automated setup and registration. |
| 4 | + |
| 5 | +Unlike the previous static `local-environment`, which used a fixed number of validators with pre-generated keys, this dynamic environment automates the entire lifecycle, including key generation, funding, and on-chain registration. |
| 6 | + |
| 7 | +## Key Features |
| 8 | + |
| 9 | +- **Dynamic Configuration**: Easily set the number of "permissioned" and "registered" validator nodes to launch. |
| 10 | +- **Automated Lifecycle Management**: Handles the entire process of key generation, Cardano address funding, and SPO registration for all validators. |
| 11 | +- **Dynamic Node Discovery**: Nodes use dynamic node-keys, PeerIDs, and public addresses for automatic peer discovery within the Substrate network. |
| 12 | +- **Comprehensive Stack**: Includes all necessary components for a fully functional test environment: Cardano node, DB-Sync, Ogmios, and the Partner Chains nodes. |
| 13 | + |
| 14 | +## System Requirements |
| 15 | + |
| 16 | +Running the local environment requires a machine with adequate resources. |
| 17 | + |
| 18 | +## Configuration |
| 19 | + |
| 20 | +### Node Count |
| 21 | + |
| 22 | +At the top of the `setup.sh` script, you can configure the size of the network: |
| 23 | + |
| 24 | +```sh |
| 25 | +NUM_PERMISSIONED_NODES_TO_PROCESS=10 |
| 26 | +NUM_REGISTERED_NODES_TO_PROCESS=10 |
| 27 | +``` |
| 28 | + |
| 29 | +- `NUM_PERMISSIONED_NODES_TO_PROCESS`: Defines the number of initial, permissioned nodes. |
| 30 | +- `NUM_REGISTERED_NODES_TO_PROCESS`: Defines the number of additional "registered" nodes that will be spun up and registered as SPOs. |
| 31 | + |
| 32 | +### Custom Node Image |
| 33 | + |
| 34 | +To use a custom Partner Chains node image, simply update the `PARTNER_CHAINS_NODE_IMAGE` variable at the top of the `setup.sh` script. |
| 35 | + |
| 36 | +## Automated Setup Process Explained |
| 37 | + |
| 38 | +The automation is handled by a series of scripts that execute in a specific order. |
| 39 | + |
| 40 | +### 1. `setup.sh` |
| 41 | + |
| 42 | +This is the main orchestration script. When you run `bash setup.sh`, it performs the following steps: |
| 43 | + |
| 44 | +1. **System Checks**: Detects the OS and prompts for configuration choices (ports, resource limits, etc.) in interactive mode. |
| 45 | +2. **Configuration Generation**: |
| 46 | + - Creates a `.env` file with all the environment variables for Docker Compose. |
| 47 | + - Generates individual entrypoint scripts for each Partner Chains node inside `configurations/partner-chains-nodes/`. These entrypoints include a staggered start delay (`sleep`) to prevent all nodes from starting at once. |
| 48 | +3. **Docker Compose Manifest Generation**: |
| 49 | + - Constructs the main `docker-compose.yml` file by adding service definitions for each Partner Chains node and appending the core Cardano stack (`cardano-node-1`, `postgres`, etc.) from the `modules/` directory. |
| 50 | + |
| 51 | +A key feature of the generated configurations is the use of dynamic discovery flags for the Substrate node: |
| 52 | + |
| 53 | +```bash |
| 54 | +/usr/local/bin/partner-chains-node \\ |
| 55 | + # ... other flags |
| 56 | + --node-key="$(openssl rand -hex 32)" \\ |
| 57 | + --listen-addr=/ip4/0.0.0.0/tcp/30333 \\ |
| 58 | + --public-addr="/dns4/partner-chains-node-[...]/tcp/30333/p2p/\$PEER_ID" & |
| 59 | +``` |
| 60 | + |
| 61 | +- A unique `--node-key` is generated for each node on startup, from which a `PEER_ID` is derived. The node then advertises its public, DNS-based address for discovery. |
| 62 | + |
| 63 | +### 2. `cardano/entrypoint.sh` (inside `cardano-node-1`) |
| 64 | + |
| 65 | +This script bootstraps the Cardano side of the environment. |
| 66 | + |
| 67 | +1. **Starts Cardano Node**: It waits for configuration files from the setup container, then starts the `cardano-node`. |
| 68 | +2. **SPO Registration**: It runs a loop that watches the `/shared/spo-certs/` directory. When a new validator's `.cert` file appears, it submits it to the Cardano network, officially registering the validator as an SPO. |
| 69 | + |
| 70 | +### 3. `partner-chains-setup/entrypoint.sh` (inside `partner-chains-setup`) |
| 71 | + |
| 72 | +This is the core script for automating the validator lifecycle. |
| 73 | + |
| 74 | +1. **Setup**: It waits for the Cardano node and Ogmios, then generates the dynamic Cardano genesis files. |
| 75 | +2. **Key Generation**: It programmatically generates all necessary keys (payment, stake, cold, VRF, keystore) for every configured validator. |
| 76 | +3. **Funding**: It builds and submits Cardano transactions to fund the payment addresses of all validators from a genesis UTXO. |
| 77 | +4. **Certificate Generation**: For each validator, it generates the necessary stake address and stake pool registration certificates, placing the final certificate in `/shared/spo-certs/` to be picked up by the Cardano node. |
| 78 | +5. **Ready Signal**: Once complete, it creates a `partner-chains-setup.ready` file, signaling the Partner Chains nodes that they can start. |
| 79 | + |
| 80 | +## Usage |
| 81 | + |
| 82 | +### 1. Initialise the Environment |
| 83 | + |
| 84 | +Run `setup.sh` to enter the setup wizard for initialising the environment (`.env` file) and `docker-compose.yml`. |
| 85 | + |
| 86 | +```bash |
| 87 | +chmod +x setup.sh |
| 88 | +bash setup.sh |
| 89 | +``` |
| 90 | + |
| 91 | +Alternatively, run in non-interactive mode to accept default settings: |
| 92 | +```bash |
| 93 | +bash setup.sh --non-interactive |
| 94 | +``` |
| 95 | + |
| 96 | +### 2. Start the Environment |
| 97 | + |
| 98 | +Once initialized, deploy the local environment with: |
| 99 | + |
| 100 | +```bash |
| 101 | +docker compose up -d |
| 102 | +``` |
| 103 | + |
| 104 | +### 3. Monitor the Environment |
| 105 | + |
| 106 | +We recommend using a visual Docker UI tool such as [lazydocker](https://github.com/jesseduffield/lazydocker) or Docker Desktop for following the live logs and container performance. |
| 107 | + |
| 108 | +You can also monitor logs directly from the command line: |
| 109 | +- **Cardano SPO registrations**: `docker logs cardano-node-1 -f | grep -E "DEBUG|LOG|WARN"` |
| 110 | +- **Full stack setup progress**: `docker logs partner-chains-setup -f` |
| 111 | +- **Partner Chains node startup**: `docker logs partner-chains-node-permissioned-1 -f` (or any other node). |
| 112 | + |
| 113 | +### 4. Stop the Environment |
| 114 | + |
| 115 | +To tear down the environment and remove all data, it is mandatory to also wipe all volumes. |
| 116 | + |
| 117 | +```bash |
| 118 | +docker compose down --volumes |
| 119 | +``` |
| 120 | + |
| 121 | +## Advanced Usage & Customization |
| 122 | + |
| 123 | +The `setup.sh` script provides several flags for more advanced configurations. The help dialogue will always show the latest available features. |
| 124 | + |
| 125 | +```bash |
| 126 | +$ bash setup.sh --help |
| 127 | +Usage: ./setup.sh [OPTION]... |
| 128 | +Initialize and configure the Docker environment. |
| 129 | + -n, --non-interactive Run with no interactive prompts and accept sensible default configuration settings. |
| 130 | + -d, --deployment-option Specify one of the custom deployment options (1, 2, 3, or 4). |
| 131 | + -p, --postgres-password Set a specific password for PostgreSQL (overrides automatic generation). |
| 132 | + -i, --node-image Specify a custom Partner Chains Node image. |
| 133 | + -t, --tests Include tests container. |
| 134 | + -h, --help Display this help dialogue and exit. |
| 135 | +``` |
0 commit comments