Skip to content

Commit

Permalink
Map rpc port to collator and validators (#149)
Browse files Browse the repository at this point in the history
* Updates polkadot dependency

* use rpc-port for collator

* rpc port optional for para

* lint

* try no prettier config

* run lint

Co-authored-by: Crystalin <alan@purestake.com>
  • Loading branch information
joelamouche and Crystalin authored Nov 10, 2021
1 parent c871412 commit b0eba03
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prepare": "tsc",
"build": "tsc",
"start": "yarn build && node dist/cli.js",
"lint": "prettier --check .",
"lint": "prettier -v && prettier --check .",
"lint:write": "prettier --write ."
},
"dependencies": {
Expand Down
24 changes: 18 additions & 6 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
startSimpleCollator,
getParachainIdFromSpec,
} from "./spawn";
import { connect, registerParachain, setBalance } from "./rpc";
import { connect, setBalance } from "./rpc";
import { checkConfig } from "./check";
import {
clearAuthorities,
Expand Down Expand Up @@ -90,11 +90,22 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {

// First we launch each of the validators for the relay chain.
for (const node of config.relaychain.nodes) {
const { name, wsPort, port, flags, basePath } = node;
console.log(`Starting ${name}...`);
const { name, wsPort, rpcPort, port, flags, basePath } = node;
console.log(
`Starting Relaychain Node ${name}... wsPort: ${wsPort} rpcPort: ${rpcPort} port: ${port}`
);
// We spawn a `child_process` starting a node, and then wait until we
// able to connect to it using PolkadotJS in order to know its running.
startNode(relay_chain_bin, name, wsPort, port, spec, flags, basePath);
startNode(
relay_chain_bin,
name,
wsPort,
rpcPort,
port,
spec,
flags,
basePath
);
}

// Connect to the first relay chain node to submit the extrinsic.
Expand All @@ -114,15 +125,16 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {
let account = parachainAccount(resolvedId);

for (const node of parachain.nodes) {
const { wsPort, port, flags, name, basePath } = node;
const { wsPort, port, flags, name, basePath, rpcPort } = node;
console.log(
`Starting a Collator for parachain ${resolvedId}: ${account}, Collator port : ${port} wsPort : ${wsPort}`
`Starting a Collator for parachain ${resolvedId}: ${account}, Collator port : ${port} wsPort : ${wsPort} rpcPort : ${rpcPort}`
);
const skipIdArg = !id;
await startCollator(
bin,
resolvedId,
wsPort,
rpcPort,
port,
name,
chain,
Expand Down
12 changes: 11 additions & 1 deletion src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function startNode(
bin: string,
name: string,
wsPort: number,
rpcPort: number | undefined,
port: number,
spec: string,
flags?: string[],
Expand All @@ -110,6 +111,9 @@ export function startNode(
"--port=" + port,
"--" + name.toLowerCase(),
];
if (rpcPort) {
args.push("--rpc-port=" + rpcPort);
}

if (basePath) {
args.push("--base-path=" + basePath);
Expand Down Expand Up @@ -181,6 +185,7 @@ export function startCollator(
bin: string,
id: string,
wsPort: number,
rpcPort: number | undefined,
port: number,
name?: string,
chain?: string,
Expand All @@ -191,7 +196,12 @@ export function startCollator(
) {
return new Promise<void>(function (resolve) {
// TODO: Make DB directory configurable rather than just `tmp`
let args = ["--ws-port=" + wsPort, "--port=" + port, "--collator"];
let args = ["--ws-port=" + wsPort, "--port=" + port];
if (rpcPort) {
args.push("--rpc-port=" + rpcPort);
console.log(`Added --rpc-port=" + ${rpcPort}`);
}
args.push("--collator");

if (basePath) {
args.push("--base-path=" + basePath);
Expand Down
3 changes: 2 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface LaunchConfig {
finalization: boolean;
}
export interface ParachainNodeConfig {
rpcPort: number;
rpcPort?: number;
wsPort: number;
port: number;
basePath?: string;
Expand Down Expand Up @@ -40,6 +40,7 @@ export interface RelayChainConfig {
name: string;
basePath?: string;
wsPort: number;
rpcPort?: number;
port: number;
flags?: string[];
}[];
Expand Down

0 comments on commit b0eba03

Please sign in to comment.