diff --git a/javascript/packages/orchestrator/src/configGenerator.ts b/javascript/packages/orchestrator/src/configGenerator.ts index fc8720562..a7b478f45 100644 --- a/javascript/packages/orchestrator/src/configGenerator.ts +++ b/javascript/packages/orchestrator/src/configGenerator.ts @@ -16,7 +16,6 @@ import { DEFAULT_COLLATOR_IMAGE, DEFAULT_COMMAND, DEFAULT_CUMULUS_COLLATOR_BIN, - DEFAULT_GENESIS_GENERATE_SUBCOMMAND, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IMAGE, DEFAULT_KEYSTORE_KEY_TYPES, @@ -357,9 +356,10 @@ export async function generateNetworkSpec( computedStatePath = genesisStatePath; } } else { + // NOTE: the subcommand to execute will be set later based on `substrateCliArgsVersion`. computedStateCommand = parachain.genesis_state_generator ? parachain.genesis_state_generator - : `${collatorBinary} ${DEFAULT_GENESIS_GENERATE_SUBCOMMAND}`; + : `${collatorBinary} {{GENESIS_GENERATE_SUBCOMMAND}}`; // TODO: we should remove this conditional ones // https://github.com/paritytech/polkadot-sdk/pull/2375 and diff --git a/javascript/packages/orchestrator/src/constants.ts b/javascript/packages/orchestrator/src/constants.ts index 27a4827f8..5c68f8ff6 100644 --- a/javascript/packages/orchestrator/src/constants.ts +++ b/javascript/packages/orchestrator/src/constants.ts @@ -41,6 +41,7 @@ const DEFAULT_CHAIN_SPEC_RAW = "{{chainName}}-raw.json"; const DEFAULT_CHAIN_SPEC_COMMAND = "{{DEFAULT_COMMAND}} build-spec --chain {{chainName}} --disable-default-bootnode"; const DEFAULT_GENESIS_GENERATE_SUBCOMMAND = "export-genesis-state"; +const DEFAULT_GENESIS_HEAD_GENERATE_SUBCOMMAND = "export-genesis-head"; const DEFAULT_WASM_GENERATE_SUBCOMMAND = "export-genesis-wasm"; const DEFAULT_ADDER_COLLATOR_BIN = "adder-collator"; const UNDYING_COLLATOR_BIN = "undying-collator"; @@ -146,6 +147,7 @@ export { DEFAULT_CUMULUS_COLLATOR_BIN, DEFAULT_DATA_DIR, DEFAULT_GENESIS_GENERATE_SUBCOMMAND, + DEFAULT_GENESIS_HEAD_GENERATE_SUBCOMMAND, DEFAULT_GLOBAL_TIMEOUT, DEFAULT_IMAGE, DEFAULT_INDIVIDUAL_TEST_TIMEOUT, diff --git a/javascript/packages/orchestrator/src/paras.ts b/javascript/packages/orchestrator/src/paras.ts index 764f607b8..efeb4a8ea 100644 --- a/javascript/packages/orchestrator/src/paras.ts +++ b/javascript/packages/orchestrator/src/paras.ts @@ -4,6 +4,8 @@ import chainSpecFns, { isRawSpec } from "./chainSpec"; import { getUniqueName } from "./configGenerator"; import { DEFAULT_COLLATOR_IMAGE, + DEFAULT_GENESIS_GENERATE_SUBCOMMAND, + DEFAULT_GENESIS_HEAD_GENERATE_SUBCOMMAND, GENESIS_STATE_FILENAME, GENESIS_WASM_FILENAME, K8S_WAIT_UNTIL_SCRIPT_SUFIX, @@ -225,10 +227,14 @@ export async function generateParachainFiles( const commands = []; if (parachain.genesisStateGenerator) { - let genesisStateGenerator = parachain.genesisStateGenerator.replace( - "{{CLIENT_REMOTE_DIR}}", - client.remoteDir as string, - ); + const subcommand = + parachain.collators[0].substrateCliArgsVersion! >= 3 + ? DEFAULT_GENESIS_HEAD_GENERATE_SUBCOMMAND + : DEFAULT_GENESIS_GENERATE_SUBCOMMAND; + let genesisStateGenerator = parachain.genesisStateGenerator + .replace("{{CLIENT_REMOTE_DIR}}", client.remoteDir as string) + .replace("{{GENESIS_GENERATE_SUBCOMMAND}}", subcommand); + // cumulus if (parachain.cumulusBased) { const chainSpecPathInNode = @@ -242,7 +248,7 @@ export async function generateParachainFiles( ); } - if (client.providerName === "native" && !parachain.cumulusBased) { + if (client.providerName === "native" && parachain.cumulusBased) { // Inject a tmp base-path to prevent the use of a pre-existing un-purged data directory. This should only // be injected for `cumulus` base parachains. // See https://github.com/paritytech/zombienet/issues/1519 diff --git a/javascript/packages/orchestrator/src/providers/k8s/index.ts b/javascript/packages/orchestrator/src/providers/k8s/index.ts index 237144014..1ef5b0cbf 100644 --- a/javascript/packages/orchestrator/src/providers/k8s/index.ts +++ b/javascript/packages/orchestrator/src/providers/k8s/index.ts @@ -6,7 +6,7 @@ import { genChaosDef, } from "./dynResourceDefinition"; import { KubeClient, initClient } from "./kubeClient"; -import { getCliArgsVersion } from "./substrateCliArgsHelper"; +import { getCliArgsHelp } from "./substrateCliArgsHelper"; export const provider = { KubeClient, @@ -16,6 +16,6 @@ export const provider = { setupChainSpec, getChainSpecRaw, replaceNetworkRef, - getCliArgsVersion, + getCliArgsHelp, genChaosDef, }; diff --git a/javascript/packages/orchestrator/src/providers/k8s/substrateCliArgsHelper.ts b/javascript/packages/orchestrator/src/providers/k8s/substrateCliArgsHelper.ts index e6bfd7d2c..a6ec910d7 100644 --- a/javascript/packages/orchestrator/src/providers/k8s/substrateCliArgsHelper.ts +++ b/javascript/packages/orchestrator/src/providers/k8s/substrateCliArgsHelper.ts @@ -1,19 +1,18 @@ -import { SubstrateCliArgsVersion } from "../../sharedTypes"; import { getClient } from "../client"; import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition"; import { KubeClient } from "./kubeClient"; -export const getCliArgsVersion = async ( +export const getCliArgsHelp = async ( image: string, command: string, -): Promise => { +): Promise => { const client = getClient() as KubeClient; - // use echo to not finish the pod with error status. + // Use echo to not finish the pod with error status. const fullCmd = `${command} --help || echo ""`; const node = await createTempNodeDef( "temp", image, - "", // don't used + "", // Don't used fullCmd, false, ); @@ -23,11 +22,5 @@ export const getCliArgsVersion = async ( await client.spawnFromDef(podDef); const logs = await client.getNodeLogs(podName); - if (logs.includes("--ws-port ")) { - return SubstrateCliArgsVersion.V0; - } else if (!logs.includes("--insecure-validator-i-know-what-i-do")) { - return SubstrateCliArgsVersion.V1; - } else { - return SubstrateCliArgsVersion.V2; - } + return logs; }; diff --git a/javascript/packages/orchestrator/src/providers/native/index.ts b/javascript/packages/orchestrator/src/providers/native/index.ts index a215f17b7..316298418 100644 --- a/javascript/packages/orchestrator/src/providers/native/index.ts +++ b/javascript/packages/orchestrator/src/providers/native/index.ts @@ -5,7 +5,7 @@ import { replaceNetworkRef, } from "./dynResourceDefinition"; import { NativeClient, initClient } from "./nativeClient"; -import { getCliArgsVersion } from "./substrateCliArgsHelper"; +import { getCliArgsHelp } from "./substrateCliArgsHelper"; export const provider = { NativeClient, @@ -15,5 +15,5 @@ export const provider = { setupChainSpec, getChainSpecRaw, replaceNetworkRef, - getCliArgsVersion, + getCliArgsHelp, }; diff --git a/javascript/packages/orchestrator/src/providers/native/substrateCliArgsHelper.ts b/javascript/packages/orchestrator/src/providers/native/substrateCliArgsHelper.ts index 7ac24afb7..ab8b01372 100644 --- a/javascript/packages/orchestrator/src/providers/native/substrateCliArgsHelper.ts +++ b/javascript/packages/orchestrator/src/providers/native/substrateCliArgsHelper.ts @@ -1,20 +1,13 @@ -import { SubstrateCliArgsVersion } from "../../sharedTypes"; import { getClient } from "../client"; -export const getCliArgsVersion = async ( +export const getCliArgsHelp = async ( image: string, command: string, -): Promise => { +): Promise => { const client = getClient(); const fullCmd = `${command} --help`; const logs = (await client.runCommand(["-c", fullCmd], { allowFail: true })) .stdout; - if (logs.includes("--ws-port ")) { - return SubstrateCliArgsVersion.V0; - } else if (!logs.includes("--insecure-validator-i-know-what-i-do")) { - return SubstrateCliArgsVersion.V1; - } else { - return SubstrateCliArgsVersion.V2; - } + return logs; }; diff --git a/javascript/packages/orchestrator/src/providers/podman/index.ts b/javascript/packages/orchestrator/src/providers/podman/index.ts index 4e7354187..a6e511a72 100644 --- a/javascript/packages/orchestrator/src/providers/podman/index.ts +++ b/javascript/packages/orchestrator/src/providers/podman/index.ts @@ -5,7 +5,7 @@ import { replaceNetworkRef, } from "./dynResourceDefinition"; import { PodmanClient, initClient } from "./podmanClient"; -import { getCliArgsVersion } from "./substrateCliArgsHelper"; +import { getCliArgsHelp } from "./substrateCliArgsHelper"; export const provider = { PodmanClient, @@ -15,5 +15,5 @@ export const provider = { setupChainSpec, getChainSpecRaw, replaceNetworkRef, - getCliArgsVersion, + getCliArgsHelp, }; diff --git a/javascript/packages/orchestrator/src/providers/podman/substrateCliArgsHelper.ts b/javascript/packages/orchestrator/src/providers/podman/substrateCliArgsHelper.ts index 9fcd6a0a5..412800414 100644 --- a/javascript/packages/orchestrator/src/providers/podman/substrateCliArgsHelper.ts +++ b/javascript/packages/orchestrator/src/providers/podman/substrateCliArgsHelper.ts @@ -1,11 +1,10 @@ -import { SubstrateCliArgsVersion } from "../../sharedTypes"; import { getClient } from "../client"; import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition"; -export const getCliArgsVersion = async ( +export const getCliArgsHelp = async ( image: string, command: string, -): Promise => { +): Promise => { const client = getClient(); const fullCmd = `${command} --help`; const node = await createTempNodeDef( @@ -19,12 +18,5 @@ export const getCliArgsVersion = async ( const podName = podDef.metadata.name; await client.spawnFromDef(podDef); const logs = await client.getNodeLogs(podName); - - if (logs.includes("--ws-port ")) { - return SubstrateCliArgsVersion.V0; - } else if (!logs.includes("--insecure-validator-i-know-what-i-do")) { - return SubstrateCliArgsVersion.V1; - } else { - return SubstrateCliArgsVersion.V2; - } + return logs; }; diff --git a/javascript/packages/orchestrator/src/sharedTypes.ts b/javascript/packages/orchestrator/src/sharedTypes.ts index e1ae4662d..9c4989c2f 100644 --- a/javascript/packages/orchestrator/src/sharedTypes.ts +++ b/javascript/packages/orchestrator/src/sharedTypes.ts @@ -5,6 +5,8 @@ export enum SubstrateCliArgsVersion { V1 = 1, // Includes the --insecure-validator-i-know-what-i-do flag. V2 = 2, + // Rename export-genesis-head to export-genesis-head in polkadot-parachain + V3 = 3, } // enums diff --git a/javascript/packages/orchestrator/src/substrateCliArgsHelper.ts b/javascript/packages/orchestrator/src/substrateCliArgsHelper.ts index e452d07da..988b87a96 100644 --- a/javascript/packages/orchestrator/src/substrateCliArgsHelper.ts +++ b/javascript/packages/orchestrator/src/substrateCliArgsHelper.ts @@ -2,12 +2,16 @@ import { series } from "@zombienet/utils"; import { getProvider } from "./providers"; import { Client } from "./providers/client"; import { ComputedNetwork } from "./configTypes"; +import { SubstrateCliArgsVersion } from "./sharedTypes"; +import { Scope } from "./network"; + +const debug = require("debug")("zombie::substrateCliArgsVersion"); export const setSubstrateCliArgsVersion = async ( network: ComputedNetwork, client: Client, ) => { - const { getCliArgsVersion } = getProvider(client.providerName); + const { getCliArgsHelp } = getProvider(client.providerName); // Calculate substrate cli version for each node // and set in the node to use later when we build the cmd. const imgCmdMap = new Map(); @@ -15,7 +19,11 @@ export const setSubstrateCliArgsVersion = async ( if (node.substrateCliArgsVersion) return memo; const uniq_image_cmd = `${node.image}_${node.command}`; if (!memo.has(uniq_image_cmd)) - memo.set(uniq_image_cmd, { image: node.image, command: node.command }); + memo.set(uniq_image_cmd, { + image: node.image, + command: node.command, + scope: Scope.RELAY, + }); return memo; }, imgCmdMap); @@ -27,6 +35,7 @@ export const setSubstrateCliArgsVersion = async ( memo.set(uniq_image_cmd, { image: collator.image, command: collator.command, + scope: Scope.PARA, }); } return memo; @@ -36,7 +45,8 @@ export const setSubstrateCliArgsVersion = async ( const promiseGenerators = []; for (const [, v] of imgCmdMap) { const getVersionPromise = async () => { - const version = await getCliArgsVersion(v.image, v.command); + const helpStdout = await getCliArgsHelp(v.image, v.command); + const version = await getCliArgsVersion(helpStdout, v.scope); v.version = version; return version; }; @@ -61,3 +71,37 @@ export const setSubstrateCliArgsVersion = async ( } } }; + +function getCliArgsVersion( + helpStdout: string, + scope: Scope, +): SubstrateCliArgsVersion { + // IFF stdout includes `ws-port` flag we are always in V0 + if (helpStdout.includes("--ws-port ")) { + debug(`returning cliArgsVersion ${SubstrateCliArgsVersion.V0}`); + return SubstrateCliArgsVersion.V0; + } + + // If not, we should check the scope + if (scope == Scope.RELAY) { + const version = !helpStdout.includes( + "--insecure-validator-i-know-what-i-do", + ) + ? SubstrateCliArgsVersion.V1 + : SubstrateCliArgsVersion.V2; + + debug(`returning cliArgsVersion ${version}`); + return version; + } else if (scope == Scope.PARA) { + const version = !helpStdout.includes("export-genesis-head") + ? SubstrateCliArgsVersion.V2 + : SubstrateCliArgsVersion.V3; + + debug(`returning cliArgsVersion ${version}`); + return version; + } else { + debug(`returning default cliArgsVersion`); + // For other scopes we just return the latest version. + return SubstrateCliArgsVersion.V3; + } +}