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

Update to not use --parachain-id flag #160

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ rococo-local.json
rococo-local-raw.json
configLocal.json
bin

# Ignore file for non-zero install
# ref: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
26 changes: 18 additions & 8 deletions config.js → examples/config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
// Collator flags
var flags = ["--force-authoring", "--", "--execution=wasm"];
const flags = ["--", "--execution=wasm"];

var config = {
const config = {
relaychain: {
bin: "./bin/polkadot",
chain: "rococo-local",
nodes: [
{
name: "alice",
wsPort: 9944,
rpcPort: 9844,
port: 30444,
},
{
name: "bob",
wsPort: 9955,
rpcPort: 9855,
port: 30555,
},
{
name: "charlie",
wsPort: 9966,
rpcPort: 9866,
port: 30666,
},
{
name: "dave",
wsPort: 9977,
rpcPort: 9877,
port: 30777,
},
],
Expand All @@ -43,26 +47,30 @@ var config = {
parachains: [
{
bin: "./bin/polkadot-collator",
id: "200",
id: 200,
protocolId: "para-first",
balance: "1000000000000000000000",
nodes: [
{
name: "alice",
wsPort: 9988,
rpcPort: 9888,
port: 31200,
name: "alice",
flags,
},
],
},
{
bin: "./bin/polkadot-collator",
id: "300",
id: 300,
protocolId: "para-second",
balance: "1000000000000000000000",
nodes: [
{
name: "alice",
wsPort: 9999,
rpcPort: 9899,
port: 31300,
name: "alice",
flags,
},
],
Expand All @@ -71,10 +79,12 @@ var config = {
simpleParachains: [
{
bin: "./bin/adder-collator",
id: "400",
port: "31400",
id: 400,
name: "alice",
balance: "1000000000000000000000",
// no `wsPort` for simpleParachains
// no `rpcPort` for simpleParachains
port: 31400,
},
],
hrmpChannels: [
Expand Down
19 changes: 12 additions & 7 deletions config.json → examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
{
"name": "alice",
"wsPort": 9944,
"rpcPort": 9844,
"port": 30444
},
{
"name": "bob",
"wsPort": 9955,
"rpcPort": 9855,
"port": 30555
},
{
"name": "charlie",
"wsPort": 9966,
"rpcPort": 9866,
"port": 30666
},
{
"name": "dave",
"wsPort": 9977,
"rpcPort": 9877,
"port": 30777
}
],
Expand All @@ -40,26 +44,27 @@
"parachains": [
{
"bin": "./bin/polkadot-collator",
"id": "200",
"id": 200,
"balance": "1000000000000000000000",
"nodes": [
{
"name": "alice",
"wsPort": 9988,
"rpcPort": 9888,
"port": 31200,
"name": "alice",
"flags": ["--", "--execution=wasm"]
}
]
},
{
"bin": "./bin/polkadot-collator",
"id": "300",
"id": 300,
"balance": "1000000000000000000000",
"nodes": [
{
"name": "alice",
"wsPort": 9999,
"port": 31300,
"name": "alice",
"flags": ["--", "--execution=wasm"]
}
]
Expand All @@ -68,10 +73,10 @@
"simpleParachains": [
{
"bin": "./bin/adder-collator",
"id": "400",
"port": "31400",
"id": 400,
"name": "alice",
"balance": "1000000000000000000000"
"balance": "1000000000000000000000",
"port": 31400
}
],
"hrmpChannels": [
Expand Down
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,44 @@
"scripts": {
"prepare": "tsc",
"build": "tsc",
"start": "yarn build && node dist/cli.js",
"start": "ts-node src/cli.ts",
"start:debug": "node --inspect-brk -r ts-node/register src/cli.ts",
"lint": "prettier -v && prettier --check .",
"lint:write": "prettier --write .",
"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'"
},
"files": [
"dist"
],
"bin": "dist/cli.js",
"dependencies": {
"@polkadot/api": "^6.10.3",
"@polkadot/keyring": "^8.0.5",
"@polkadot/types": "^6.10.3",
"@polkadot/util": "^8.0.5",
"@polkadot/util-crypto": "^8.0.5",
"@polkadot/api": "^6.12.1",
"@polkadot/keyring": "^8.1.2",
"@polkadot/types": "^6.12.1",
"@polkadot/util": "^8.1.2",
"@polkadot/util-crypto": "^8.1.2",
"@types/chai": "^4.2.22",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"chalk": "^4.1.2",
"ethers": "^5.4.7",
"filter-console": "^0.1.1",
"libp2p-crypto": "^0.20.0",
"mocha": "^9.1.2",
"peer-id": "^0.15.3",
"tcp-port-used": "^1.0.2",
"ts-node": "^10.3.0",
"web3": "^1.6.0",
"web3-core": "^1.6.0",
"web3-eth": "^1.6.0",
"yargs": "^15.4.1"
},
"files": [
"dist"
],
"bin": {
"polkadot-launch": "dist/cli.js"
"yargs": "^17.3.0"
},
"devDependencies": {
"@types/node": "^16.4.12",
"@types/tcp-port-used": "^1.0.0",
"@types/yargs": "^17.0.7",
"chai": "^4.3.4",
"mocha": "^9.1.2",
"prettier": "^2.4.1",
"typescript": "^4.1.5"
"tcp-port-used": "^1.0.2",
"ts-node": "^10.4.0",
"typescript": "^4.1.5",
"web3": "^1.6.0",
"web3-core": "^1.6.0",
"web3-eth": "^1.6.0"
}
}
88 changes: 71 additions & 17 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,72 @@
#!/usr/bin/env node

import { killAll } from "./spawn";
import { resolve, dirname } from "path";
import fs from "fs";
import { LaunchConfig } from "./types";
import path from "path";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

import { killAll } from "./spawn";
import { LaunchConfig, RunConfig } from "./types";
import { run } from "./runner";

// Special care is needed to handle paths to various files (binaries, spec, config, etc...)
// The user passes the path to `config.json`, and we use that as the starting point for any other
// relative path. So the `config.json` file is what we will be our starting point.
const { argv } = require("yargs");

const config_file = argv._[0] ? argv._[0] : null;
if (!config_file) {
console.error("Missing config file argument...");
process.exit();
}
let config_path = resolve(process.cwd(), config_file);
let config_dir = dirname(config_path);
if (!fs.existsSync(config_path)) {
console.error("Config file does not exist: ", config_path);
process.exit();
}
let config: LaunchConfig = require(config_path);
yargs(hideBin(process.argv))
.command(
"$0 [options] <config_file>",
"Launching Polkadot network locally",
() => {},
(argv) => {
const { verbose, config_file: configFile } = argv;
const configPath = resolve(process.cwd(), configFile as string);
const configDir = dirname(configPath);
if (!fs.existsSync(configPath)) {
console.error("Config file does not exist: ", configPath);
process.exit();
}

const launchConfig: LaunchConfig = require(configPath);

// runConfig initialization
const runConfig: RunConfig = {
verbose: (verbose as number) || 0,
out: (argv.out as string) || process.cwd(),
};

// folder creation. Creating the inner folder `./logs` also create the parent folder.
const folderPath = path.resolve(runConfig.out, "logs");
try {
createFolder(folderPath);
} catch (err) {
console.error(
`Cannot create output folder at ${runConfig.out}. Err: ${(
err as Error
).toString()}`
);
process.exit();
}

// Run the main process
run(configDir, launchConfig, runConfig);
}
)
.option("verbose", {
alias: "v",
describe: "Verbose logging",
count: true,
})
.option("out", {
alias: "o",
describe: "Folder that assets and logs output to",
normalize: true,
})
.option("help", {
alias: "h",
describe: "Show help",
help: true,
}).argv;

// Kill all processes when exiting.
process.on("exit", function () {
Expand All @@ -34,4 +78,14 @@ process.on("SIGINT", function () {
process.exit(2);
});

run(config_dir, config);
function createFolder(folderPath: string) {
if (fs.existsSync(folderPath)) {
// check if it is a directory
if (!fs.lstatSync(folderPath).isDirectory()) {
throw new Error(`\`${folderPath}\` exists but is not a folder.`);
}
} else {
// Create the output folder
fs.mkdirSync(folderPath, { recursive: true });
}
}
4 changes: 2 additions & 2 deletions src/parachain.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { bnToHex, stringToHex, hexStripPrefix } from "@polkadot/util";
import { encodeAddress } from "@polkadot/util-crypto";

export function parachainAccount(id: string) {
export function parachainAccount(id: number) {
let prefix = stringToHex("para");
let encoded_id = bnToHex(parseInt(id), { isLe: true });
let encoded_id = bnToHex(id, { isLe: true });
let address_bytes = (prefix + hexStripPrefix(encoded_id)).padEnd(64 + 2, "0");
let address = encodeAddress(address_bytes);

Expand Down
2 changes: 1 addition & 1 deletion src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const filterConsole = require("filter-console");
// Hide some warning messages that are coming from Polkadot JS API.
// TODO: Make configurable.
filterConsole([
`code: '1006' reason: 'connection failed'`,
`1006:: connection failed`,
`Unhandled promise rejections`,
`UnhandledPromiseRejectionWarning:`,
`Unknown types found`,
Expand Down
Loading