Skip to content

Commit

Permalink
fix(orchestrator): allow to use '--<dev-account>' flag in args (#1455)
Browse files Browse the repository at this point in the history
* fix(orchestrator): allow to use '--<dev-account>' flag in args

* fmt
  • Loading branch information
pepoviola authored Oct 27, 2023
1 parent ab253e5 commit 037e399
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DEFAULT_PORTS,
DEFAULT_PROMETHEUS_PREFIX,
DEFAULT_WASM_GENERATE_SUBCOMMAND,
DEV_ACCOUNTS,
GENESIS_STATE_FILENAME,
GENESIS_WASM_FILENAME,
UNDYING_COLLATOR_BIN,
Expand Down Expand Up @@ -516,8 +517,6 @@ async function getCollatorNodeFromConfig(
group?: string,
): Promise<Node> {
let args: string[] = [];
if (collatorConfig.args)
args = args.concat(sanitizeArgs(collatorConfig.args, { "listen-addr": 2 }));

const env = collatorConfig.env
? DEFAULT_ENV.concat(collatorConfig.env)
Expand Down Expand Up @@ -545,6 +544,15 @@ async function getCollatorNodeFromConfig(
? true
: false;

if (collatorConfig.args)
args = args.concat(
sanitizeArgs(
collatorConfig.args,
{ "listen-addr": 2 },
{ nodeName: collatorName, isValidator },
),
);

const node: Node = {
name: collatorName,
key: getSha256(collatorName),
Expand Down Expand Up @@ -596,9 +604,7 @@ async function getNodeFromConfig(
: networkSpec.relaychain.defaultCommand;
const image = node.image || networkSpec.relaychain.defaultImage;
let args: string[] = sanitizeArgs(networkSpec.relaychain.defaultArgs || []);
if (node.args) args = args.concat(sanitizeArgs(node.args));

const uniqueArgs = [...new Set(args)];
const env = node.env ? DEFAULT_ENV.concat(node.env) : DEFAULT_ENV;

let nodeOverrides: Override[] = [];
Expand Down Expand Up @@ -628,6 +634,9 @@ async function getNodeFromConfig(
const ports = await getPorts(provider, node);
const externalPorts = await getExternalPorts(provider, ports, node);

if (node.args)
args = args.concat(sanitizeArgs(node.args, {}, { nodeName, isValidator }));
const uniqueArgs = [...new Set(args)];
// build node Setup
const nodeSetup: Node = {
name: nodeName,
Expand Down Expand Up @@ -687,6 +696,10 @@ async function getNodeFromConfig(
function sanitizeArgs(
args: string[],
extraArgsToRemove: { [key: string]: number } = {},
context?: {
nodeName: string;
isValidator: boolean;
},
): string[] {
// Do NOT filter any argument to the internal full-node of the collator
const augmentedArgsToRemove = { ...ARGS_TO_REMOVE, ...extraArgsToRemove };
Expand All @@ -702,6 +715,17 @@ function sanitizeArgs(

const argParsed = arg === "-d" ? "d" : arg.replace(/--/g, "");
if (augmentedArgsToRemove[argParsed]) {
// Don't sanitize `--<dev_account>` flags
// IFF the node name is one of the dev accounts and is set to be a validator
// see: https://github.com/paritytech/zombienet/issues/1448
if (
context &&
argParsed === context.nodeName &&
context.isValidator &&
DEV_ACCOUNTS.includes(argParsed)
)
return true;

if (augmentedArgsToRemove[argParsed] === 2) removeNext = true;
return false;
} else {
Expand All @@ -713,6 +737,7 @@ function sanitizeArgs(
if (separatorIndex >= 0) {
filteredArgs.push(...args.slice(separatorIndex));
}

return filteredArgs;
}

Expand Down

0 comments on commit 037e399

Please sign in to comment.