Skip to content
Merged
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ npm i polkadot-launch -g
## Binary Files

To use polkadot-launch, you need to have binary files for a `polkadot` relay chain and a
`polkadot-collator`.
`polkadot-collator` in the bin folder.

You can generate these files by cloning the `rococo-v1` branch of these projects and building them
with the specific flags below:
You can generate these files by cloning the `rococo-v1` branch of these projects in the same root as the polkadot-launch repo
and building them with the specific flags below:

```bash
git clone https://github.com/paritytech/polkadot
cd polkadot
cargo build --release
cp ./target/release/polkadot ../polkadot-launch/bin/polkadot-relaychain
```

and
Expand All @@ -34,6 +35,7 @@ and
git clone https://github.com/paritytech/cumulus
cd cumulus
cargo build --release -p polkadot-collator
cp ./target/release/polkadot-collator ../polkadot-launch/bin/polkadot-collator
```

## Use
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"start": "yarn build && node dist/cli.js",
"lint": "prettier -v && prettier --check .",
"lint:write": "prettier --write .",
"para-test": "mocha -r ts-node/register 'test/tests/**/test-*.ts'"
"para-test": "mocha -r ts-node/register 'test/tests/**/test-*.ts'",
"para-test-no-ci": "mocha -r ts-node/register 'test/tests-no-ci/**/test-*.ts'"
},
"dependencies": {
"@polkadot/api": "^6.10.3",
Expand Down
21 changes: 6 additions & 15 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {

// Then launch each parachain
for (const parachain of config.parachains) {
const { id, resolvedId, balance, chain } = parachain;
const { id, resolvedId, balance } = parachain;

const bin = resolve(config_dir, parachain.bin);
if (!fs.existsSync(bin)) {
console.error("Parachain binary does not exist: ", bin);
Expand All @@ -137,13 +138,11 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {
`Starting a Collator for parachain ${resolvedId}: ${account}, Collator port : ${port} wsPort : ${wsPort} rpcPort : ${rpcPort}`
);
const skip_id_arg = !id;
await startCollator(bin, resolvedId, wsPort, rpcPort, port, {
await startCollator(bin, wsPort, rpcPort, port, {
name,
chain,
spec,
flags,
basePath,
skip_id_arg,
onlyOneParachainNode: config.parachains.length === 1,
});
}
Expand Down Expand Up @@ -186,7 +185,6 @@ export async function run(config_dir: string, rawConfig: LaunchConfig) {

interface GenesisParachain {
isSimple: boolean;
id?: string;
resolvedId: string;
chain?: string;
bin: string;
Expand All @@ -210,7 +208,7 @@ async function addParachainsToGenesis(
let paras = x.concat(y);

for (const parachain of paras) {
const { isSimple, id, resolvedId, chain } = parachain;
const { resolvedId, chain } = parachain;
const bin = resolve(config_dir, parachain.bin);
if (!fs.existsSync(bin)) {
console.error("Parachain binary does not exist: ", bin);
Expand All @@ -222,15 +220,8 @@ async function addParachainsToGenesis(
let genesisState: string;
let genesisWasm: string;
try {
if (isSimple) {
// adder-collator does not support `--parachain-id` for export-genesis-state (and it is
// not necessary for it anyway), so we don't pass it here.
genesisState = await exportGenesisState(bin);
genesisWasm = await exportGenesisWasm(bin);
} else {
genesisState = await exportGenesisState(bin, id, chain);
genesisWasm = await exportGenesisWasm(bin, chain);
}
genesisState = await exportGenesisState(bin, chain);
genesisWasm = await exportGenesisWasm(bin);
} catch (err) {
console.error(err);
process.exit(1);
Expand Down
28 changes: 3 additions & 25 deletions src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ export async function exportGenesisWasm(
chain?: string
): Promise<string> {
let args = ["export-genesis-wasm"];
if (chain) {
args.push("--chain=" + chain);
}

// wasm files are typically large and `exec` requires us to supply the maximum buffer size in
// advance. Hopefully, this generous limit will be enough.
Expand All @@ -162,13 +159,10 @@ export async function exportGenesisWasm(
/// Export the genesis state aka genesis head.
export async function exportGenesisState(
bin: string,
id?: string,
chain?: string
): Promise<string> {
let args = ["export-genesis-state"];
if (id) {
args.push("--parachain-id=" + id);
}

if (chain) {
args.push("--chain=" + chain);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to remove chain selection from the parachain parameters? It will cause issues when you export the genesis state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to a comment, it was't supported by cumulus anymore

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a misunderstanding. The only thing that got removed was the parachain-id paritytech/cumulus#739
No need to remove the option to select a chain. It is very needed, in polkadot-collator we have several chains, the same stands for the polkadot binary.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. How was this resolved, perhaps I'm missing something @joelamouche ?

Copy link
Copy Markdown
Contributor Author

@joelamouche joelamouche Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghzlatarev I left the --chain command. So if you specify the chain in the chain field of the parachain in hte config, it should work

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelamouche I don't see it in startCollator or exportGenesisWasm , is it not needed there ?
Right now if I start a westmint-local network I get some default Local Testnet

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right Im adding it back

}
Expand All @@ -186,7 +180,6 @@ export async function exportGenesisState(
// Start a collator node for a parachain.
export function startCollator(
bin: string,
id: string,
wsPort: number,
rpcPort: number | undefined,
port: number,
Expand All @@ -195,15 +188,7 @@ 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];
const {
basePath,
name,
skip_id_arg,
onlyOneParachainNode,
chain,
flags,
spec,
} = options;
const { basePath, name, onlyOneParachainNode, flags, spec } = options;

if (rpcPort) {
args.push("--rpc-port=" + rpcPort);
Expand All @@ -221,18 +206,11 @@ export function startCollator(
args.push(`--${name.toLowerCase()}`);
console.log(`Added --${name.toLowerCase()}`);
}
if (!skip_id_arg) {
args.push("--parachain-id=" + id);
console.log(`Added --parachain-id=${id}`);
}

if (onlyOneParachainNode) {
args.push("--force-authoring");
console.log(`Added --force-authoring`);
}
if (chain) {
args.push("--chain=" + chain);
console.log(`Added --chain=${chain}`);
}

let flags_collator = null;
let flags_parachain = null;
Expand Down
1 change: 1 addition & 0 deletions src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function addGenesisParachain(
paras.push(new_para);

let data = JSON.stringify(chainSpec, null, 2);

fs.writeFileSync(spec, data);
console.log(` ✓ Added Genesis Parachain ${para_id}`);
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
export interface CollatorOptions {
name?: string;
chain?: string;
spec?: string;
flags?: string[];
basePath?: string;
skip_id_arg?: boolean;
onlyOneParachainNode?: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions test/test-utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const DISPLAY_LOG = process.env.PARACHAIN_LOG || false;
export const PARACHAIN_LOG = process.env.PARACHAIN_LOG || "info";

export const BINARY_PATH =
process.env.BINARY_PATH || `../bin/polkadot-collator-mac`;
process.env.BINARY_PATH || `../bin/polkadot-collator`;
export const RELAY_BINARY_PATH =
process.env.RELAY_BINARY_PATH || `../bin/polkadot-relaychain-mac`;
process.env.RELAY_BINARY_PATH || `../bin/polkadot-relaychain`;
export const SPAWNING_TIME = 20000;
export const ETHAPI_CMD = process.env.ETHAPI_CMD || "";

Expand Down
3 changes: 0 additions & 3 deletions test/test-utils/para-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { killAll, run } from "../../src"; //"polkadot-launch";
import {
BINARY_PATH,
RELAY_BINARY_PATH,
DISPLAY_LOG,
SPAWNING_TIME,
RELAY_CHAIN_NODE_NAMES,
} from "./constants";
const debug = require("debug")("test:para-node");
Expand Down Expand Up @@ -156,7 +154,6 @@ export async function startParachainNodes(options: ParachainOptions): Promise<{
bin: BINARY_PATH,
id: (1000 * (i + 1)).toString(),
balance: "1000000000000000000000",
// chain: options.chain, this is not supported by cumulus
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riusricardo this is the comment I was referring to. I'm going to put it back though, for collators that do need it

nodes: [
{
port: ports[i * 2 + numberOfParachains + 1].p2pPort,
Expand Down
34 changes: 34 additions & 0 deletions test/tests-no-ci/test-balance-genesis-2-parachains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Keyring from "@polkadot/keyring";
import { expect } from "chai";

import { describeParachain } from "../test-utils/setup-para-tests";

describeParachain(
"Balance genesis",
{ chain: "rococo-local", numberOfParachains: 2 },
(context) => {
it("should be accessible through web3", async function () {
const keyring = new Keyring({ type: "sr25519" });
const aliceRelay = keyring.addFromUri("//Alice");

//check parachain id
expect(
(
(await context._polkadotApiRelaychains[0].query.paras.parachains()) as any
)[0].toString()
).to.eq("1000");
expect(
(
(await context._polkadotApiRelaychains[0].query.paras.parachains()) as any
)[1].toString()
).to.eq("2000");
expect(
(
await context.polkadotApiParaone.query.system.account(
aliceRelay.addressRaw
)
).data.free.toHuman()
).to.eq("1,152,921,504,606,846,976");
});
}
);
8 changes: 8 additions & 0 deletions test/tests/test-balance-genesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ describeParachain("Balance genesis", { chain: "rococo-local" }, (context) => {
it("should be accessible through web3", async function () {
const keyring = new Keyring({ type: "sr25519" });
const aliceRelay = keyring.addFromUri("//Alice");

//check parachain id
expect(
(
(await context._polkadotApiRelaychains[0].query.paras.parachains()) as any
)[0].toString()
).to.eq("1000");
// check genesis balance
expect(
(
await context.polkadotApiParaone.query.system.account(
Expand Down