Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native] use local_ip settings for p2p in native #1973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions javascript/packages/orchestrator/src/cmdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function genCumulusCollatorCmd(
dataPath = "/data",
relayDataPath = "/relay-data",
useWrapper = true,
local_ip = "0.0.0.0",
): Promise<string[]> {
const { name, chain, parachainId, key, validator, commandWithArgs } =
nodeSetup;
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function genCumulusCollatorCmd(
"--base-path",
dataPath,
"--listen-addr",
`/ip4/0.0.0.0/tcp/${nodeSetup.p2pPort ? nodeSetup.p2pPort : P2P_PORT}/ws`,
`/ip4/${local_ip}/tcp/${nodeSetup.p2pPort ? nodeSetup.p2pPort : P2P_PORT}/ws`,
"--prometheus-external",
"--rpc-cors all",
"--unsafe-rpc-external",
Expand Down Expand Up @@ -212,6 +213,18 @@ export async function genCumulusCollatorCmd(
}
}

if (local_ip != "0.0.0.0") {
// need to transform full_node --port flag to listen addr
const flagIndex = fullCmd.findIndex((arg) => arg === "--port");
if (flagIndex >= 0) {
const port_to_use = fullCmd[flagIndex + 1];
fullCmd.splice(flagIndex, 2);
fullCmd.push(
...["--listen-addr", `/ip4/${local_ip}/tcp/${port_to_use}/ws`],
);
}
}

const resolvedCmd = [fullCmd.join(" ")];
if (useWrapper) resolvedCmd.unshift("/cfg/zombie-wrapper.sh");
return resolvedCmd;
Expand All @@ -222,6 +235,7 @@ export async function genCmd(
cfgPath = "/cfg",
dataPath = "/data",
useWrapper = true,
local_ip = "0.0.0.0",
): Promise<string[]> {
const {
name,
Expand Down Expand Up @@ -301,7 +315,9 @@ export async function genCmd(
args[listenIndex + 1] = listenAddr;
} else {
// no --listen-add args
args.push(...["--listen-addr", `/ip4/0.0.0.0/tcp/${nodeSetup.p2pPort}/ws`]);
args.push(
...["--listen-addr", `/ip4/${local_ip}/tcp/${nodeSetup.p2pPort}/ws`],
);
}

// set our base path
Expand Down
2 changes: 2 additions & 0 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ export async function start(
local_ip: networkSpec.settings.local_ip,
};

console.log("DEBUG: spawnOpts", spawnOpts);

// Calculate chaos before start spawning the nodes
const chaosSpecs: any[] = [];
// network chaos is ONLY available in k8s for now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export async function genBootnodeDef(
export async function genNodeDef(
namespace: string,
nodeSetup: Node,
inCI: boolean = false,
opts: any = {},
): Promise<any> {
const inCI = opts.inCI || false;
const nodeResource = new NodeResource(namespace, nodeSetup);
return nodeResource.generateSpec(inCI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ export async function genBootnodeDef(
export async function genNodeDef(
namespace: string,
nodeSetup: Node,
opts: any = {},
): Promise<any> {
const client = getClient();
const nodeResource = new NodeResource(client, namespace, nodeSetup);
console.log("DEBUG opts", opts);
const nodeResource = new NodeResource(
client,
namespace,
nodeSetup,
opts.local_ip,
);

return nodeResource.generateSpec();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class NodeResource {
client: Client,
protected readonly namespace: string,
protected readonly nodeSetupConfig: Node,
protected readonly local_ip: string | undefined = undefined,
) {
const nodeRootPath = `${client.tmpDir}/${this.nodeSetupConfig.name}`;
this.configPath = `${nodeRootPath}/cfg`;
Expand Down Expand Up @@ -97,17 +98,25 @@ export class NodeResource {
}

protected generateCommand() {
console.log("DEBUG this", this);
if (this.nodeSetupConfig.zombieRole === ZombieRole.CumulusCollator) {
return genCumulusCollatorCmd(
this.nodeSetupConfig,
this.configPath,
this.dataPath,
this.relayDataPath,
false,
this.local_ip,
);
}

return genCmd(this.nodeSetupConfig, this.configPath, this.dataPath, false);
return genCmd(
this.nodeSetupConfig,
this.configPath,
this.dataPath,
false,
this.local_ip,
);
}

protected getZombieRoleLabel(): ZombieRoleLabel {
Expand Down
6 changes: 5 additions & 1 deletion javascript/packages/orchestrator/src/spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ export const spawnNode = async (
if (opts.jaegerUrl) node.jaegerUrl = opts.jaegerUrl;

debug(`creating node: ${node.name}`);
console.log("DEBUG opts", opts);
const podDef = await (node.name === "bootnode"
? genBootnodeDef(namespace, node)
: genNodeDef(namespace, node, opts.inCI));
: genNodeDef(namespace, node, {
inCI: opts.inCI,
local_ip: opts.local_ip,
}));

const finalFilesToCopyToNode = [...filesToCopy];

Expand Down
Loading