Skip to content

Commit

Permalink
feat: allow to use a custom chain-spec generator for plain/raw mode (#…
Browse files Browse the repository at this point in the history
…1453)

* feat: allow to use a custom chain-spec generator for plain/raw mode

* lint/fmt

* fmt

* fix paras

* fix logic for build raw
  • Loading branch information
pepoviola authored Oct 27, 2023
1 parent 037e399 commit a7a287f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
6 changes: 3 additions & 3 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ export async function generateNetworkSpec(
.chain_spec_command
? config.relaychain.chain_spec_command
: DEFAULT_CHAIN_SPEC_COMMAND.replace(
"{{chainName}}",
networkSpec.relaychain.chain,
).replace("{{DEFAULT_COMMAND}}", networkSpec.relaychain.defaultCommand);
"{{DEFAULT_COMMAND}}",
networkSpec.relaychain.defaultCommand,
);
}

const relayChainBootnodes: string[] = [];
Expand Down
3 changes: 2 additions & 1 deletion javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ export async function start(
namespace,
networkSpec.relaychain.defaultImage,
chainName,
networkSpec.relaychain.defaultCommand,
networkSpec.relaychain.chainSpecCommand ||
networkSpec.relaychain.defaultCommand,
chainSpecFullPath,
);
} else {
Expand Down
7 changes: 6 additions & 1 deletion javascript/packages/orchestrator/src/paras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "fs";
import chainSpecFns, { isRawSpec } from "./chainSpec";
import { getUniqueName } from "./configGenerator";
import {
DEFAULT_CHAIN_SPEC_COMMAND,
DEFAULT_COLLATOR_IMAGE,
GENESIS_STATE_FILENAME,
GENESIS_WASM_FILENAME,
Expand Down Expand Up @@ -163,7 +164,11 @@ export async function generateParachainFiles(
`${parachain.chain ? parachain.chain + "-" : ""}${
parachain.name
}-${relayChainName}`,
parachain.collators[0].command!,
// TODO: does paras need to support external chain generation cmd?
DEFAULT_CHAIN_SPEC_COMMAND.replace(
"{{DEFAULT_COMMAND}}",
parachain.collators[0].command!,
),
chainSpecFullPath,
);
} else {
Expand Down
12 changes: 7 additions & 5 deletions javascript/packages/orchestrator/src/providers/k8s/chainSpec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { promises as fsPromises, writeFileSync } from "fs";
import {
DEFAULT_CHAIN_SPEC,
DEFAULT_CHAIN_SPEC_COMMAND,
DEFAULT_CHAIN_SPEC_RAW,
NODE_CONTAINER_WAIT_LOG,
} from "../../constants";
Expand Down Expand Up @@ -31,7 +30,10 @@ export async function setupChainSpec(
"/" +
DEFAULT_CHAIN_SPEC.replace(/{{chainName}}/gi, chainName);

const fullCommand = `${chainSpecCommand} > ${plainChainSpecOutputFilePath}`;
const fullCommand = `${chainSpecCommand.replace(
/{{chainName}}/gi,
chainName,
)} > ${plainChainSpecOutputFilePath}`;
const node = await createTempNodeDef(
"temp",
defaultImage,
Expand Down Expand Up @@ -63,7 +65,7 @@ export async function getChainSpecRaw(
namespace: string,
image: string,
chainName: string,
chainCommand: string,
chainSpecCommand: string,
chainFullPath: string,
): Promise<any> {
const client = getClient() as KubeClient;
Expand All @@ -77,10 +79,10 @@ export async function getChainSpecRaw(
client.remoteDir +
"/" +
DEFAULT_CHAIN_SPEC_RAW.replace(/{{chainName}}/, chainName);
const chainSpecCommandRaw = DEFAULT_CHAIN_SPEC_COMMAND.replace(
const chainSpecCommandRaw = chainSpecCommand.replace(
/{{chainName}}/gi,
remoteChainSpecFullPath,
).replace("{{DEFAULT_COMMAND}}", chainCommand);
);

const fullCommand = `${chainSpecCommandRaw} --raw > ${remoteChainSpecRawFullPath}`;
const node = await createTempNodeDef("temp", image, chainName, fullCommand);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { sleep } from "@zombienet/utils";
import { promises as fsPromises } from "fs";
import { readAndParseChainSpec } from "../../chainSpec";
import {
DEFAULT_CHAIN_SPEC,
DEFAULT_CHAIN_SPEC_COMMAND,
DEFAULT_CHAIN_SPEC_RAW,
} from "../../constants";
import { DEFAULT_CHAIN_SPEC, DEFAULT_CHAIN_SPEC_RAW } from "../../constants";
import { getClient } from "../client";
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition";

Expand Down Expand Up @@ -33,7 +29,10 @@ export async function setupChainSpec(
"/" +
DEFAULT_CHAIN_SPEC.replace(/{{chainName}}/gi, chainName);
// set output of command
const fullCommand = `${chainSpecCommand} > ${plainChainSpecOutputFilePath}`;
const fullCommand = `${chainSpecCommand.replace(
/{{chainName}}/gi,
chainName,
)} > ${plainChainSpecOutputFilePath}`;
const node = await createTempNodeDef(
"temp",
defaultImage,
Expand All @@ -52,7 +51,7 @@ export async function getChainSpecRaw(
namespace: string,
image: string,
chainName: string,
chainCommand: string,
chainSpecCommand: string,
chainFullPath: string,
): Promise<any> {
const client = getClient();
Expand All @@ -65,10 +64,10 @@ export async function getChainSpecRaw(
client.tmpDir +
"/" +
DEFAULT_CHAIN_SPEC_RAW.replace(/{{chainName}}/, chainName);
const chainSpecCommandRaw = DEFAULT_CHAIN_SPEC_COMMAND.replace(
const chainSpecCommandRaw = chainSpecCommand.replace(
/{{chainName}}/gi,
remoteChainSpecFullPath,
).replace("{{DEFAULT_COMMAND}}", chainCommand);
);

const fullCommand = `${chainSpecCommandRaw} --raw > ${remoteChainSpecRawFullPath}`;
const node = await createTempNodeDef("temp", image, chainName, fullCommand);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { sleep } from "@zombienet/utils";
import {
DEFAULT_CHAIN_SPEC,
DEFAULT_CHAIN_SPEC_COMMAND,
DEFAULT_CHAIN_SPEC_RAW,
} from "../../constants";
import { DEFAULT_CHAIN_SPEC, DEFAULT_CHAIN_SPEC_RAW } from "../../constants";
import { getClient } from "../client";
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition";
const debug = require("debug")("zombie::podman::chain-spec");
Expand Down Expand Up @@ -31,7 +27,10 @@ export async function setupChainSpec(
"/" +
DEFAULT_CHAIN_SPEC.replace(/{{chainName}}/gi, chainName);
// set output of command
const fullCommand = `${chainSpecCommand} > ${plainChainSpecOutputFilePath}`;
const fullCommand = `${chainSpecCommand.replace(
/{{chainName}}/gi,
chainName,
)} > ${plainChainSpecOutputFilePath}`;
const node = await createTempNodeDef(
"temp",
defaultImage,
Expand All @@ -55,7 +54,7 @@ export async function getChainSpecRaw(
namespace: string,
image: string,
chainName: string,
chainCommand: string,
chainSpecCommand: string,
chainFullPath: string,
): Promise<any> {
const plainPath = chainFullPath.replace(".json", "-plain.json");
Expand All @@ -69,10 +68,10 @@ export async function getChainSpecRaw(
client.remoteDir +
"/" +
DEFAULT_CHAIN_SPEC_RAW.replace(/{{chainName}}/, chainName);
const chainSpecCommandRaw = DEFAULT_CHAIN_SPEC_COMMAND.replace(
const chainSpecCommandRaw = chainSpecCommand.replace(
/{{chainName}}/gi,
remoteChainSpecFullPath,
).replace("{{DEFAULT_COMMAND}}", chainCommand);
);

const fullCommand = `${chainSpecCommandRaw} --raw > ${remoteChainSpecRawFullPath}`;
const node = await createTempNodeDef("temp", image, chainName, fullCommand);
Expand Down
4 changes: 3 additions & 1 deletion javascript/packages/utils/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ function getReplacementInText(content: string): string[] {
// eslint-disable-next-line no-useless-escape
const replacementRegex = /{{([A-Za-z-_\.]+)}}/gim;
for (const match of content.matchAll(replacementRegex)) {
replacements.push(match[1]);
// chainName is allowed since we want to use it
// to replace it in runtime for custom chain spec generator cmd
if (match[1] !== "chainName") replacements.push(match[1]);
}

return replacements;
Expand Down

0 comments on commit a7a287f

Please sign in to comment.