datahaven/test/cli/handlers/launch/index.ts
Gonza Montiel 6dae38f587
feat: 🚀 add storage-hub nodes to CLI (#287)
##  Add StorageHub nodes to CLI

This PR adds StorageHub node infrastructure to the CLI and fixes CLI
flag handling and improves the CLI logic a bit.

### Fix: CLI safeguards
- Prevents contract deployment and validator operations when `--ndc`
flag is used
- Skips Kurtosis service display in summary when `--nlk` flag is used

### Feat: Dockerized Storage Hub Nodes
- Adds 5 Docker containers: PostgreSQL, MSP, BSP, Indexer, and Fisherman
nodes
- New CLI flags: `--storagehub` `--no-storagehub` to control StorageHub
nodes launch
- Automatic provider funding and registration (Charleth for MSP and
Dorothy for BSP)
- Exposes nodes on ports 9945-9948 for local development

**TODO**
- [x] MSP & BSP associated pre-funded account.
- [x] Call `forceMspSignUp` and `forceBspSignUp` extrinsics

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-11-22 11:49:14 +01:00

173 lines
5.5 KiB
TypeScript

import type { Command } from "@commander-js/extra-typings";
import { logger } from "utils";
import { DEFAULT_SUBSTRATE_WS_PORT } from "utils/constants";
import { createParameterCollection } from "utils/parameters";
import { getBlockscoutUrl } from "../../../launcher/kurtosis";
import { LaunchedNetwork } from "../../../launcher/types/launchedNetwork";
import { checkBaseDependencies } from "../common/checks";
import { deployContracts } from "./contracts";
import { launchDataHavenSolochain } from "./datahaven";
import { launchKurtosis } from "./kurtosis";
import { setParametersFromCollection } from "./parameters";
import { launchRelayers } from "./relayer";
import { launchStorageHubComponents } from "./storagehub";
import { performSummaryOperations } from "./summary";
import { performValidatorOperations } from "./validator";
export const NETWORK_ID = "cli-launch";
export interface NetworkOptions {
networkId: string;
dhInternalPort?: number;
}
export const CLI_NETWORK_OPTIONS: NetworkOptions = {
networkId: NETWORK_ID,
dhInternalPort: DEFAULT_SUBSTRATE_WS_PORT
};
// Non-optional properties should have default values set by the CLI
export interface LaunchOptions {
all?: boolean;
datahaven?: boolean;
buildDatahaven?: boolean;
datahavenBuildExtraArgs: string;
datahavenImageTag: string;
launchKurtosis?: boolean;
kurtosisEnclaveName: string;
slotTime?: number;
kurtosisNetworkArgs?: string;
verified?: boolean;
blockscout?: boolean;
deployContracts?: boolean;
fundValidators?: boolean;
setupValidators?: boolean;
setParameters?: boolean;
relayer?: boolean;
relayerImageTag: string;
storagehub?: boolean;
cleanNetwork?: boolean;
}
// ===== Launch Handler Functions =====
const launchFunction = async (options: LaunchOptions, launchedNetwork: LaunchedNetwork) => {
logger.debug("Running with options:");
logger.debug(options);
const timeStart = performance.now();
await checkBaseDependencies();
// Create parameter collection to be used throughout the launch process
const parameterCollection = await createParameterCollection();
await launchDataHavenSolochain(options, launchedNetwork);
await launchKurtosis(options, launchedNetwork);
logger.trace("Checking if Blockscout is enabled...");
let blockscoutBackendUrl: string | undefined;
if (options.blockscout === true) {
blockscoutBackendUrl = await getBlockscoutUrl(options.kurtosisEnclaveName);
logger.trace("Blockscout backend URL:", blockscoutBackendUrl);
} else if (options.verified) {
logger.warn(
"⚠️ Contract verification (--verified) requested, but Blockscout is disabled (--no-blockscout). Verification will be skipped."
);
}
if (options.deployContracts) {
const contractsDeployed = await deployContracts({
rpcUrl: launchedNetwork.elRpcUrl,
verified: options.verified,
blockscoutBackendUrl,
deployContracts: options.deployContracts,
parameterCollection
});
await performValidatorOperations(options, launchedNetwork.elRpcUrl, contractsDeployed);
}
await setParametersFromCollection({
launchedNetwork,
collection: parameterCollection,
setParameters: options.setParameters
});
await launchRelayers(options, launchedNetwork);
await launchStorageHubComponents(options, launchedNetwork);
await performSummaryOperations(options, launchedNetwork);
const fullEnd = performance.now();
const fullMinutes = ((fullEnd - timeStart) / (1000 * 60)).toFixed(1);
logger.success(`Launch function completed successfully in ${fullMinutes} minutes`);
};
export const launch = async (options: LaunchOptions) => {
const run = new LaunchedNetwork();
await launchFunction(options, run);
};
export const launchPreActionHook = (
thisCmd: Command<[], LaunchOptions & { [key: string]: any }>
) => {
const {
all,
blockscout,
verified,
fundValidators,
setupValidators,
deployContracts,
datahaven,
buildDatahaven,
launchKurtosis,
relayer,
setParameters,
storagehub
} = thisCmd.opts();
// Check for conflicts with --all flag
if (
all &&
(datahaven === false ||
buildDatahaven === false ||
launchKurtosis === false ||
deployContracts === false ||
fundValidators === false ||
setupValidators === false ||
setParameters === false ||
relayer === false ||
storagehub === false)
) {
thisCmd.error(
"--all cannot be used with --no-datahaven, --no-build-datahaven, --no-launch-kurtosis, --no-deploy-contracts, --no-fund-validators, --no-setup-validators, --no-update-validator-set, --no-set-parameters, --no-relayer, or --no-storagehub"
);
}
// If --all is set, enable all components
if (all) {
thisCmd.setOptionValue("datahaven", true);
thisCmd.setOptionValue("buildDatahaven", true);
thisCmd.setOptionValue("launchKurtosis", true);
thisCmd.setOptionValue("deployContracts", true);
thisCmd.setOptionValue("fundValidators", true);
thisCmd.setOptionValue("setupValidators", true);
thisCmd.setOptionValue("setParameters", true);
thisCmd.setOptionValue("relayer", true);
thisCmd.setOptionValue("storagehub", true);
thisCmd.setOptionValue("cleanNetwork", true);
}
if (verified && !blockscout) {
thisCmd.error("--verified requires --blockscout to be set");
}
if (deployContracts === false && setupValidators) {
thisCmd.error("--setupValidators requires --deployContracts to be set");
}
if (deployContracts === false && fundValidators) {
thisCmd.error("--fundValidators requires --deployContracts to be set");
}
};