Node orchestration
Node orchestration manages the daemons that make up a Polar network. It keeps each Bitcoin, Lightning, Litd, and Tapd node as part of one network model, turns that model into a Docker Compose runtime, and keeps node data and dependent links aligned as nodes change.
Node roles and relationships
A network groups nodes by role rather than by one flat list. Bitcoin nodes provide the regtest chain and event feed. Lightning nodes use a selected Bitcoin node as their backend. Tapd nodes use an LND node as their backend, while Litd combines Lightning and Taproot Assets services in one integrated node.
The main relationships are:
| Node role | Main purpose | Dependency |
|---|---|---|
Bitcoin Core (bitcoind) | Provides the Bitcoin regtest chain, RPC access, and block and transaction events. | None within the node graph. |
Lightning (LND, c-lightning, eclair) | Provides Lightning nodes that connect to a Bitcoin backend and to other Lightning peers. | A compatible Bitcoin node. |
| Litd | Provides an integrated LND, Lit, and Taproot Assets node. | A compatible Bitcoin node; its LND and Taproot Assets parts share the Litd node. |
| Tapd | Provides a separate Taproot Assets node. | A compatible LND node. |
The selected backend is stored by node name. The generated runtime uses that name to connect services inside the Docker network, so a rename or backend change must update the related node links as well as the display name. References: src/…/index.ts• L23-37, src/…/types.ts• L23-28, src/…/types.ts• L85-128, src/…/composeFile.ts• L85-106, src/…/composeFile.ts• L175-218
Node creation and identity
Adding a node creates a stopped node record, assigns it to the correct network role, gives it a name and ports, and saves a new Compose description. The node keeps its network ID, implementation, selected version, Docker choice, status, and links to its backend. A new Bitcoin node is also peered with the prior Bitcoin node so the network remains on one chain.
Names are used as stable runtime identities. They form host names, container names, volume paths, and references from other nodes. New Lightning nodes use generated names such as alice; Bitcoin nodes use names such as backend1; a Tapd node is initially named from its LND backend. Litd is held in the Lightning collection because its primary role is an integrated Lightning node.
Nodes can use either a managed image and command or a user-defined local image and command. A managed choice uses the implementation and version to select the image metadata. A custom choice overrides the image and startup command for that node. References: src/…/network.ts• L190-225, src/…/network.ts• L304-340, src/…/network.ts• L343-379, src/…/network.ts• L411-443, src/…/network.ts• L360-456, src/…/index.ts• L39-59
Node configuration
Configuration is the link between the saved node model and the Docker runtime. Compose generation assigns each node a service, hostname, container name, persistent data volume, published ports, image, and startup command. Commands can contain node and backend values that are filled in when the Compose description is generated.
The system provides a default command for each implementation and version. A node-level command replaces that default, while an empty command restores the default. The configuration also accounts for version-specific options, such as features that older Tapd or Core Lightning versions do not support.
Backend changes update the saved relationship and regenerate the Compose description. A running Lightning node is stopped and started again so it uses the new Bitcoin backend. A Tapd backend can only change before the node has created its asset state; the system rejects a later change because it could make existing assets unusable. References: src/…/network.ts• L633-702, src/…/updateNodeCommand.ts• L24-31, src/…/network.ts• L717-739, src/…/composeFile.ts• L43-63, src/…/composeFile.ts• L65-218, src/…/setTapBackend.ts• L70-100
Version selection and compatibility
Node versions come from the Docker image catalog. The catalog supplies the latest version, supported versions, and compatibility rules. The selected version is stored on the node and controls the default image tag and command used for that node.
Compatibility protects the links between node roles:
- A Lightning or Litd version selects Bitcoin backends that meet its supported Bitcoin range.
- A Tapd version selects an LND backend at or above its required minimum version.
- A Tapd node cannot be added when no suitable LND backend exists.
- Removing a Bitcoin backend is blocked when a dependent Lightning node has no other compatible backend.
The version list is a catalog, not an in-place upgrade operation. The orchestration actions choose a version when a node is added and expose the catalog for inspection. Existing node records keep their stored version until another supported lifecycle operation replaces or recreates the node. The catalog can receive newer metadata from the remote nodes.json state, but that does not silently change existing nodes. References: src/…/index.ts• L109-124, src/…/network.ts• L80-94, src/…/network.ts• L170-188, src/…/network.ts• L382-408, src/…/repoService.ts• L47-91, src/…/listNodeVersions.ts• L21-89
Port allocation
Each node receives a group of host ports for its API and peer interfaces. Before a network or individual node starts, orchestration checks ports for collisions and moves only stopped nodes to the next available ports. Started nodes are excluded from this check because their ports are already in active use by the same node.
When a port changes, the node model and its Compose description are saved before Docker starts. A zero port means that an implementation does not support that interface. This keeps the host-facing API stable where possible while still allowing more than one network or node set to run on the same machine. References: src/…/network.ts• L742-770, src/…/network.ts• L784-839, src/…/network.ts• L925-988, src/…/network.ts• L735-765
Network and node startup
Network startup brings up the complete Compose project, then waits for each daemon to answer its service API. The network status moves through starting and started or error states, while each node receives its own readiness result.
The startup flow is:
flowchart TD
A[Start network] --> B{Required custom images available?}
B -- No --> X[Return missing-image error]
B -- Yes --> C[Find open host ports]
C --> D[Save changed ports and Compose file]
D --> E[Start Docker Compose project]
E --> F[Wait for Bitcoin nodes]
E --> G[Wait for Lightning and Litd nodes]
E --> H[Wait for Tapd nodes]
F --> I[Connect Bitcoin peers and prepare wallets]
I --> J[Mine one startup block]
G --> K[Connect Lightning peers and add listeners]
H --> L[Mark Tapd readiness]
J --> M[Network remains available]
K --> M
L --> M
Bitcoin readiness includes peer connection and default wallet setup. After Bitcoin nodes are ready, the system mines one block to help implementations that need chain activity during startup. After Lightning nodes are ready, it connects them to each other and starts event listeners. An individual node follows the same readiness checks but starts only its Compose service. References: src/…/network.ts• L735-781, src/…/network.ts• L834-863, src/…/network.ts• L864-954, src/…/dockerService.ts• L183-223
Stop and restart behavior
Stopping a network shuts down its Docker project and clears runtime-only state. It also turns off automatic mining, removes the simulation service when present, removes Lightning event listeners, and clears cached RPC data. Stopping a single node affects only that service and clears the shared RPC cache.
Restart is a stop-then-start operation for one node. The public node action accepts only a started or error node for restart. It stops the service, allows a short shutdown interval, starts it again, and returns the resulting node status. Network startup and shutdown use the same saved Compose description, so configuration changes must be saved before a restart can apply them. References: src/…/network.ts• L783-863, src/…/startNode.ts• L24-87, src/…/stopNode.ts• L24-87, src/…/restartNode.ts• L24-104
Node rename behavior
Renaming changes a node identity across the saved network model and its runtime data. The name must be unique within the network and may contain only letters, numbers, hyphens, and underscores. If the node is running, the whole network stops first so Docker services and data paths can be changed safely.
The rename flow updates the node data directory, the Compose description, the chart, cached service data, and persistent network state. It also updates dependent references where the name is used as a link: LND renames update Tapd links; Bitcoin renames update Lightning backend links and Bitcoin peer names. A node that was running is started again after the saved changes are complete. References: src/…/renameNode.ts• L22-30, src/…/renameNode.ts• L64-103, src/…/network.ts• L1122-1170, src/…/network.ts• L631-690, src/…/dockerService.ts• L255-290
Node removal behavior
Removal deletes the node from the network, its Docker service, its persistent node data, and the related in-memory service and chart state. A running node is stopped before its service is removed. The saved Compose description and network state are updated as part of the operation.
Removal has dependency guards:
- The last Bitcoin node cannot be removed.
- An LND node with a connected Tapd node cannot be removed.
- A Lightning node used by simulation activity cannot be removed.
- A Bitcoin node cannot be removed if its dependent Lightning nodes have no compatible replacement backend.
- Removing a Bitcoin node reconnects its neighboring Bitcoin peers. If the network is running, the whole network restarts to apply the new topology.
On Windows, Core Lightning uses a named Docker volume for data that is not stored in the normal host folder. Removal also deletes that named volume. References: src/…/network.ts• L475-631, src/…/network.ts• L966-996, src/…/dockerService.ts• L237-253, src/…/dockerService.ts• L628-650, src/…/removeNode.ts• L22-29
Orchestration interfaces
The network store is the central coordinator for node state, persistence, Compose regeneration, and Docker actions. The MCP layer exposes the same lifecycle as named operations for an external caller, with network ID and node name as the main lookup keys.
The node-focused operations are:
| Operation | Scope | Result |
|---|---|---|
add_node | One node | Adds a stopped node, then starts it if its network is already running. |
list_node_versions | Implementation or all implementations | Returns supported versions, latest versions, and compatibility rules. |
get_default_node_command | One implementation and version | Returns the default command before node-specific values are filled in. |
update_node_command | One node | Saves a custom command or resets the node to its default command. |
start_node / stop_node | One node | Starts or gracefully stops a service subject to its current status. |
restart_node | One node | Stops and starts a started or error node. |
rename_node | One node | Changes the identity and related runtime references. |
remove_node | One node | Stops and permanently removes the node and its data. |
set_lightning_backend / set_tap_backend | A dependency link | Changes a backend subject to compatibility and state guards. |
Network-wide start and stop operations remain useful when a topology change affects several services. See Network lifecycle for the larger network state flow and Network import and export for how node state moves between network instances. References: src/…/index.ts• L51-71, src/…/network.ts• L64-168, src/…/addNode.ts• L25-31, src/…/removeNode.ts• L22-29
Change checklist
When these files or sections are changed, remember to consider these:
- Update node creation rules, Compose service generation, and the node image catalog together when adding or removing an implementation.
- Keep compatibility data aligned with backend selection and backend-removal guards. A stale rule can permit a node that cannot start or block a valid topology change.
- Keep every name-bearing relationship aligned when changing rename behavior: container names, volume paths, backend names, peer names, Tapd LND links, chart nodes, and cached service records.
- Keep the port model and Compose port mappings aligned for every interface. A missing mapping can make a node appear ready while its host API is unreachable.
- Keep custom image handling separate from managed image handling. Custom images must remain available locally because network startup does not pull them.
- Preserve the stopped-before-remove and stopped-before-rename rules for persistent node data and Docker services.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A required custom Docker image is not present | Network startup stops before Docker Compose starts. | Check local images before starting and report the missing image. |
| A host port is already in use | Docker cannot publish the node interface. | Reassign ports for nodes that are not already started and save the new mapping. |
| No compatible Bitcoin backend exists for a Lightning or Litd node | The node cannot be created or its backend cannot be removed safely. | Apply implementation and version compatibility rules before the topology change. |
| No compatible unused LND backend exists for a Tapd node | Tapd cannot be added. | Require a suitable LND backend that is not already assigned to another Tapd node. |
| A Tapd backend is changed after asset state exists | Existing asset state could be lost or become unusable. | Reject the change when the Tapd admin macaroon is present. |
| The only Bitcoin node is removed | Lightning nodes lose their chain backend. | Reject removal of the last Bitcoin node. |
| A node name collides or contains unsupported characters | Runtime names and cross-node references become ambiguous or invalid. | Require unique names with the allowed character set. |
| A network starts before a dependent daemon is ready | Later services can fail health checks or miss peer setup. | Wait for service readiness, then connect peers and perform chain initialization. |
Key files
| File | Why to read it |
|---|---|
| src/…/network.ts | Central coordinator for node creation, configuration persistence, backend links, lifecycle state, rename, and removal. |
| src/…/network.ts | Defines node identity, compatibility checks, node records, port allocation, rename propagation, and network import adjustments. |
| src/…/types.ts | Defines the node roles, backend links, status values, and implementation-specific state shape. |
| src/…/dockerService.ts | Connects the saved network model to Docker Compose, node data directories, service lifecycle, and platform-specific volumes. |
| src/…/composeFile.ts | Shows how node records and backend links become Compose services and commands. |
| src/…/nodeTemplates.ts | Shows the runtime shape shared by Bitcoin, Lightning, Litd, and Tapd services. |
| src/…/constants.ts | Defines default node commands, Docker image names, supported platforms, and the built-in version catalog. |
| src/…/repoService.ts | Explains how image metadata and new versions enter the local catalog. |
| src/…/addNode.ts | Defines the external add-node contract and its version checks. |
| src/…/startNode.ts, src/…/stopNode.ts, src/…/restartNode.ts | Define the external single-node lifecycle contracts and allowed status transitions. |
| src/…/renameNode.ts, src/…/removeNode.ts | Define the external contracts and validation for destructive identity changes. |