@parity/ppn 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/secrets.env.example +42 -0
- package/config/versions.env +4 -2
- package/dist/cli.js +13 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/fetch.js +1 -1
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/secrets.d.ts +3 -0
- package/dist/commands/secrets.js +20 -0
- package/dist/commands/secrets.js.map +1 -0
- package/dist/commands/start.d.ts +48 -1
- package/dist/commands/start.js +247 -63
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/turn.js +3 -2
- package/dist/commands/turn.js.map +1 -1
- package/dist/lib/process-group.d.ts +63 -0
- package/dist/lib/process-group.js +121 -0
- package/dist/lib/process-group.js.map +1 -0
- package/dist/lib/secrets-example.d.ts +7 -0
- package/dist/lib/secrets-example.js +61 -0
- package/dist/lib/secrets-example.js.map +1 -0
- package/dist/lib/spawn-env.d.ts +22 -0
- package/dist/lib/spawn-env.js +71 -4
- package/dist/lib/spawn-env.js.map +1 -1
- package/package.json +4 -3
- package/scripts/dub/postgres.sh +4 -1
- package/scripts/dub/service.sh +6 -5
- package/scripts/ipfs-daemon.sh +3 -2
- package/scripts/require-free-ports.sh +32 -0
- package/scripts/turn.sh +4 -5
- package/zombienet-configs/local-dev.toml +5 -1
- package/scripts/kill-port.sh +0 -11
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// The network `ppn start` runs is one process group: zombie-cli is spawned as its leader, and
|
|
2
|
+
// everything zombienet starts (nodes, custom processes, their launchers) is in that group unless
|
|
3
|
+
// it makes a group of its own. The group is recorded beside the network's data, so `ppn kill`
|
|
4
|
+
// stops exactly it, and a later `ppn start` of the same workspace can stop one a dead `ppn`
|
|
5
|
+
// left behind. Nothing is matched by name or by port.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
/** Beside the network's data. */
|
|
10
|
+
export const GROUP_FILE = 'ppn-process-group.json';
|
|
11
|
+
/** The workspace's index of recorded groups, one file per network, so `ppn kill` finds them all. */
|
|
12
|
+
export const groupIndexDir = (workspace) => path.join(workspace, 'run');
|
|
13
|
+
export const groupIndexFile = (workspace, network) => path.join(groupIndexDir(workspace), `${network}.json`);
|
|
14
|
+
function psLines(args) {
|
|
15
|
+
const out = spawnSync('ps', args, { encoding: 'utf-8' });
|
|
16
|
+
return (out.stdout ?? '').split('\n').filter((line) => line.trim());
|
|
17
|
+
}
|
|
18
|
+
export const systemProcesses = {
|
|
19
|
+
members(pgid) {
|
|
20
|
+
// A zombie (state Z: exited, not yet reaped by its parent) is not a member to stop, and
|
|
21
|
+
// signalling a group of zombies only fails with EPERM on macOS.
|
|
22
|
+
return psLines(['-axo', 'pid=,pgid=,stat=,command=']).flatMap((line) => {
|
|
23
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
24
|
+
return m && Number(m[2]) === pgid && !m[3].startsWith('Z') ? [{ pid: Number(m[1]), command: m[4] }] : [];
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
startOf(pid) {
|
|
28
|
+
const [line] = psLines(['-o', 'lstart=', '-p', String(pid)]);
|
|
29
|
+
return line?.trim() || undefined;
|
|
30
|
+
},
|
|
31
|
+
signalGroup(pgid, signal) {
|
|
32
|
+
try {
|
|
33
|
+
process.kill(-pgid, signal);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err.code !== 'ESRCH')
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
sleep(ms) {
|
|
41
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Whether a recorded group is still this network's. `gone`: nothing is in it. `ours`: its leader
|
|
46
|
+
* is the recorded one (same start time), or, the leader having exited, a member runs this
|
|
47
|
+
* workspace's or this package's files (POSIX does not reuse a group id while the group lives).
|
|
48
|
+
* `foreign`: the id now belongs to something else, which is left alone.
|
|
49
|
+
*/
|
|
50
|
+
export function classifyGroup(record, procs, ours) {
|
|
51
|
+
const members = procs.members(record.pgid);
|
|
52
|
+
if (!members.length)
|
|
53
|
+
return 'gone';
|
|
54
|
+
if (members.some((m) => m.pid === record.pgid)) {
|
|
55
|
+
return procs.startOf(record.pgid) === record.leaderStart ? 'ours' : 'foreign';
|
|
56
|
+
}
|
|
57
|
+
return members.some((m) => ours(m.command)) ? 'ours' : 'foreign';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stop a group: SIGTERM to all of it (zombie-cli tears its nodes down, Postgres releases its
|
|
61
|
+
* shared memory), then SIGKILL to whatever is left after `graceMs`.
|
|
62
|
+
*/
|
|
63
|
+
export function stopGroup(pgid, procs, { graceMs = 15_000, pollMs = 250, first = 'SIGTERM' } = {}) {
|
|
64
|
+
const members = procs.members(pgid).length;
|
|
65
|
+
if (!members)
|
|
66
|
+
return { members: 0, forced: false };
|
|
67
|
+
procs.signalGroup(pgid, first);
|
|
68
|
+
for (let waited = 0; waited < graceMs; waited += pollMs) {
|
|
69
|
+
if (!procs.members(pgid).length)
|
|
70
|
+
return { members, forced: false };
|
|
71
|
+
procs.sleep(pollMs);
|
|
72
|
+
}
|
|
73
|
+
procs.signalGroup(pgid, 'SIGKILL');
|
|
74
|
+
for (let waited = 0; waited < 5_000 && procs.members(pgid).length; waited += pollMs)
|
|
75
|
+
procs.sleep(pollMs);
|
|
76
|
+
return { members, forced: true };
|
|
77
|
+
}
|
|
78
|
+
export function writeGroupRecord(record) {
|
|
79
|
+
const text = `${JSON.stringify(record, null, 2)}\n`;
|
|
80
|
+
if (record.dataDir)
|
|
81
|
+
fs.writeFileSync(path.join(record.dataDir, GROUP_FILE), text);
|
|
82
|
+
fs.mkdirSync(groupIndexDir(record.workspace), { recursive: true });
|
|
83
|
+
fs.writeFileSync(groupIndexFile(record.workspace, record.network), text);
|
|
84
|
+
}
|
|
85
|
+
export function removeGroupRecord(record) {
|
|
86
|
+
const index = groupIndexFile(record.workspace, record.network);
|
|
87
|
+
// Only the record of this group: a later start of the same network may have replaced it.
|
|
88
|
+
if (readRecord(index)?.pgid === record.pgid)
|
|
89
|
+
fs.rmSync(index, { force: true });
|
|
90
|
+
if (record.dataDir) {
|
|
91
|
+
const beside = path.join(record.dataDir, GROUP_FILE);
|
|
92
|
+
if (readRecord(beside)?.pgid === record.pgid)
|
|
93
|
+
fs.rmSync(beside, { force: true });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function readRecord(file) {
|
|
97
|
+
try {
|
|
98
|
+
const value = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
99
|
+
return value?.version === 1 && Number.isInteger(value.pgid) && value.pgid > 1 ? value : undefined;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Absent or unreadable: no record to act on.
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The groups this workspace has recorded. */
|
|
107
|
+
export function recordedGroups(workspace) {
|
|
108
|
+
const dir = groupIndexDir(workspace);
|
|
109
|
+
if (!fs.existsSync(dir))
|
|
110
|
+
return [];
|
|
111
|
+
return fs
|
|
112
|
+
.readdirSync(dir)
|
|
113
|
+
.filter((file) => file.endsWith('.json'))
|
|
114
|
+
.flatMap((file) => readRecord(path.join(dir, file)) ?? []);
|
|
115
|
+
}
|
|
116
|
+
/** A process runs this workspace's or this package's files (the same anchors as the sweep). */
|
|
117
|
+
export function runsFrom(roots) {
|
|
118
|
+
const prefixes = roots.map((root) => `${path.resolve(root)}${path.sep}`);
|
|
119
|
+
return (command) => prefixes.some((prefix) => command.includes(prefix));
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=process-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Section = 'server' | 'deployable' | 'optional';
|
|
2
|
+
/** The keys of each section of the example, in file order. */
|
|
3
|
+
export declare function secretSections(file?: string): Record<Section, string[]>;
|
|
4
|
+
/** The keys a file must hold, non-empty, under `profile`. */
|
|
5
|
+
export declare function requiredSecrets(profile: string): string[];
|
|
6
|
+
/** What is wrong with a secrets file's contents; empty when nothing is. */
|
|
7
|
+
export declare function checkSecrets(values: Record<string, string>): string[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// config/secrets.env.example is the list of keys a secrets file may hold, in three sections:
|
|
2
|
+
// every server, deployable servers and optional. Everything here reads that file; nothing
|
|
3
|
+
// lists keys itself.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { repoRoot } from '@parity/ppn-network-config';
|
|
7
|
+
const HEADINGS = {
|
|
8
|
+
'every server': 'server',
|
|
9
|
+
'deployable servers': 'deployable',
|
|
10
|
+
optional: 'optional',
|
|
11
|
+
};
|
|
12
|
+
/** The keys of each section of the example, in file order. */
|
|
13
|
+
export function secretSections(file = path.join(repoRoot(import.meta.dirname), 'config', 'secrets.env.example')) {
|
|
14
|
+
const sections = { server: [], deployable: [], optional: [] };
|
|
15
|
+
let current = null;
|
|
16
|
+
for (const line of fs.readFileSync(file, 'utf-8').split('\n')) {
|
|
17
|
+
const heading = line.match(/^# ---- (.+) ----$/);
|
|
18
|
+
if (heading) {
|
|
19
|
+
current = HEADINGS[heading[1]];
|
|
20
|
+
if (!current)
|
|
21
|
+
throw new Error(`${file}: unknown section "${heading[1]}"`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const key = line.match(/^([A-Z_][A-Z0-9_]*)=/)?.[1];
|
|
25
|
+
if (!key)
|
|
26
|
+
continue;
|
|
27
|
+
if (!current)
|
|
28
|
+
throw new Error(`${file}: ${key} is outside a section`);
|
|
29
|
+
sections[current].push(key);
|
|
30
|
+
}
|
|
31
|
+
return sections;
|
|
32
|
+
}
|
|
33
|
+
/** The keys a file must hold, non-empty, under `profile`. */
|
|
34
|
+
export function requiredSecrets(profile) {
|
|
35
|
+
const s = secretSections();
|
|
36
|
+
return profile === 'deployable' ? [...s.server, ...s.deployable] : s.server;
|
|
37
|
+
}
|
|
38
|
+
/** What is wrong with a secrets file's contents; empty when nothing is. */
|
|
39
|
+
export function checkSecrets(values) {
|
|
40
|
+
const s = secretSections();
|
|
41
|
+
const profile = values['PPN_PROFILE'];
|
|
42
|
+
if (profile !== 'local' && profile !== 'deployable') {
|
|
43
|
+
return [`PPN_PROFILE: must be local or deployable, not "${profile ?? ''}"`];
|
|
44
|
+
}
|
|
45
|
+
const required = requiredSecrets(profile);
|
|
46
|
+
const allowed = new Set([...required, ...s.optional]);
|
|
47
|
+
const problems = [];
|
|
48
|
+
for (const key of required) {
|
|
49
|
+
if (!values[key])
|
|
50
|
+
problems.push(`${key}: missing`);
|
|
51
|
+
}
|
|
52
|
+
for (const key of Object.keys(values)) {
|
|
53
|
+
if (allowed.has(key))
|
|
54
|
+
continue;
|
|
55
|
+
problems.push(s.deployable.includes(key)
|
|
56
|
+
? `${key}: deployable only, and this file is local`
|
|
57
|
+
: `${key}: not in config/secrets.env.example`);
|
|
58
|
+
}
|
|
59
|
+
return problems;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=secrets-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets-example.js","sourceRoot":"","sources":["../../src/lib/secrets-example.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,0FAA0F;AAC1F,qBAAqB;AAErB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAA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C,GAAG,GAAG,qCAAqC,CAChD,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/lib/spawn-env.d.ts
CHANGED
|
@@ -20,6 +20,28 @@ export interface ChildEnvFacts {
|
|
|
20
20
|
ephemeral: boolean;
|
|
21
21
|
}
|
|
22
22
|
export declare function childEnv(f: ChildEnvFacts): Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Facts every custom process is handed in its own `env` (custom-process-env): zombie-cli starts
|
|
25
|
+
* nodes and custom processes with an empty environment but TZ, LANG, PATH and what the TOML
|
|
26
|
+
* gives each one, so neither zombie-cli's environment (childEnv) nor the shell's reaches them.
|
|
27
|
+
* Without PPN_HOME a launcher falls back to the checkout it sits in, or ~/.ppn
|
|
28
|
+
* (scripts/lib/workspace.sh), and reads that workspace's ports.local.env, binaries and data
|
|
29
|
+
* instead of this run's.
|
|
30
|
+
*/
|
|
31
|
+
export declare function customProcessEnv(f: {
|
|
32
|
+
workspace: string;
|
|
33
|
+
network: string;
|
|
34
|
+
dataDir: string;
|
|
35
|
+
}): Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* `toml` with `env` added to every `[[custom_processes]]` block, before any entry the block
|
|
38
|
+
* already has; an entry the block names itself is kept, not repeated. Other sections are left
|
|
39
|
+
* alone. Line-based, for the configs this repository generates and any hand-written one in the
|
|
40
|
+
* same shape: one key per line, `env = [` opening its array on the key's own line.
|
|
41
|
+
*/
|
|
42
|
+
export declare function withCustomProcessEnv(toml: string, env: Record<string, string>): string;
|
|
43
|
+
/** Where `ppn start` writes the config it spawns: beside the one it was made from, so relative paths still resolve. */
|
|
44
|
+
export declare function spawnTomlFor(source: string): string;
|
|
23
45
|
/** Keys `ppn start` writes into config/ports.local.env, derived from the real writer. */
|
|
24
46
|
export declare function localEnvKeys(): string[];
|
|
25
47
|
/** Keys `ppn start` puts into zombie-cli's environment, derived from the real builder. */
|
package/dist/lib/spawn-env.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
//
|
|
3
3
|
// zombienet forwards no environment to custom processes, so everything the dashboard,
|
|
4
4
|
// eth-rpc, the dub stack and the storage provider cannot derive has to be *stated*.
|
|
5
|
-
// `ppn start` states it
|
|
6
|
-
// zombie-cli's child environment (
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// `ppn start` states it three times: config/ports.local.env (read by custom processes),
|
|
6
|
+
// zombie-cli's child environment (which the configs' {{BIN}} and {{SCRIPTS}} are filled from),
|
|
7
|
+
// and each custom process's own `env` in the config it spawns (customProcessEnv), the only
|
|
8
|
+
// environment zombie-cli hands them. A deployment that spawns zombie-cli directly never runs
|
|
9
|
+
// `ppn start`, so it has to restate the same facts itself.
|
|
9
10
|
//
|
|
10
11
|
// This module is the canonical statement, and the contract a deployment implements: it is
|
|
11
12
|
// exported as `@parity/ppn/spawn-env` so the restating side can assert against the key lists
|
|
12
13
|
// rather than keeping its own copy in step by hand.
|
|
14
|
+
import path from 'node:path';
|
|
13
15
|
/** The gitignored file `ppn start` writes; every service overlays it on top of ports.env. */
|
|
14
16
|
export function localEnvContent(f) {
|
|
15
17
|
return ('# Generated by `ppn start` — gitignored, do not edit.\n' +
|
|
@@ -32,6 +34,71 @@ export function childEnv(f) {
|
|
|
32
34
|
EPHEMERAL: f.ephemeral ? '1' : '',
|
|
33
35
|
};
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Facts every custom process is handed in its own `env` (custom-process-env): zombie-cli starts
|
|
39
|
+
* nodes and custom processes with an empty environment but TZ, LANG, PATH and what the TOML
|
|
40
|
+
* gives each one, so neither zombie-cli's environment (childEnv) nor the shell's reaches them.
|
|
41
|
+
* Without PPN_HOME a launcher falls back to the checkout it sits in, or ~/.ppn
|
|
42
|
+
* (scripts/lib/workspace.sh), and reads that workspace's ports.local.env, binaries and data
|
|
43
|
+
* instead of this run's.
|
|
44
|
+
*/
|
|
45
|
+
export function customProcessEnv(f) {
|
|
46
|
+
return { PPN_HOME: f.workspace, PPN_NETWORK: f.network, PPN_DATA_DIR: f.dataDir };
|
|
47
|
+
}
|
|
48
|
+
const SECTION = /^\s*\[\[?\s*([\w.-]+)\s*\]\]?\s*(#.*)?$/;
|
|
49
|
+
/**
|
|
50
|
+
* `toml` with `env` added to every `[[custom_processes]]` block, before any entry the block
|
|
51
|
+
* already has; an entry the block names itself is kept, not repeated. Other sections are left
|
|
52
|
+
* alone. Line-based, for the configs this repository generates and any hand-written one in the
|
|
53
|
+
* same shape: one key per line, `env = [` opening its array on the key's own line.
|
|
54
|
+
*/
|
|
55
|
+
export function withCustomProcessEnv(toml, env) {
|
|
56
|
+
const lines = toml.split('\n');
|
|
57
|
+
const out = [];
|
|
58
|
+
const entry = (name, value) => `{ name = ${JSON.stringify(name)}, value = ${JSON.stringify(value)} }`;
|
|
59
|
+
let i = 0;
|
|
60
|
+
while (i < lines.length) {
|
|
61
|
+
const header = SECTION.exec(lines[i]);
|
|
62
|
+
out.push(lines[i++]);
|
|
63
|
+
if (!header || header[1] !== 'custom_processes' || !lines[i - 1].trim().startsWith('[['))
|
|
64
|
+
continue;
|
|
65
|
+
// The block runs to the next section header.
|
|
66
|
+
const start = i;
|
|
67
|
+
while (i < lines.length && !SECTION.test(lines[i]))
|
|
68
|
+
i++;
|
|
69
|
+
const block = lines.slice(start, i);
|
|
70
|
+
const named = new Set([...block.join('\n').matchAll(/\{\s*name\s*=\s*"([^"]+)"/g)].map((m) => m[1]));
|
|
71
|
+
const missing = Object.entries(env).filter(([name]) => !named.has(name)).map(([n, v]) => entry(n, v));
|
|
72
|
+
const at = block.findIndex((line) => /^\s*env\s*=\s*\[/.test(line));
|
|
73
|
+
if (missing.length === 0) {
|
|
74
|
+
out.push(...block);
|
|
75
|
+
}
|
|
76
|
+
else if (at === -1) {
|
|
77
|
+
// No env yet: after the block's last key, before the blank lines that separate it.
|
|
78
|
+
let last = block.length;
|
|
79
|
+
while (last > 0 && block[last - 1].trim() === '')
|
|
80
|
+
last--;
|
|
81
|
+
out.push(...block.slice(0, last), `env = [${missing.join(', ')}]`, ...block.slice(last));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const open = block[at].indexOf('[') + 1;
|
|
85
|
+
const rest = block[at].slice(open).trim();
|
|
86
|
+
if (rest === '') {
|
|
87
|
+
// Multi-line array: one entry per line, as the generators write them.
|
|
88
|
+
out.push(...block.slice(0, at + 1), ...missing.map((e) => ` ${e},`), ...block.slice(at + 1));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const joined = rest.startsWith(']') ? missing.join(', ') : `${missing.join(', ')}, `;
|
|
92
|
+
out.push(...block.slice(0, at), `${block[at].slice(0, open)}${joined}${rest}`, ...block.slice(at + 1));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out.join('\n');
|
|
97
|
+
}
|
|
98
|
+
/** Where `ppn start` writes the config it spawns: beside the one it was made from, so relative paths still resolve. */
|
|
99
|
+
export function spawnTomlFor(source) {
|
|
100
|
+
return path.join(path.dirname(source), `${path.basename(source, '.toml')}.spawn.toml`);
|
|
101
|
+
}
|
|
35
102
|
const DUMMY_LOCAL = { network: 'x', dataDir: 'x', ephemeral: false, identityDataDir: 'x' };
|
|
36
103
|
const DUMMY_CHILD = { binDir: 'x', workspace: 'x', scriptsDir: 'x', dataDir: 'x', ephemeral: false };
|
|
37
104
|
/** Keys `ppn start` writes into config/ports.local.env, derived from the real writer. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-env.js","sourceRoot":"","sources":["../../src/lib/spawn-env.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,sFAAsF;AACtF,oFAAoF;AACpF,
|
|
1
|
+
{"version":3,"file":"spawn-env.js","sourceRoot":"","sources":["../../src/lib/spawn-env.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,sFAAsF;AACtF,oFAAoF;AACpF,wFAAwF;AACxF,+FA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zF,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,YAAY;IAC1B,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAA2B;IAC5C,uFAAuF;IACvF,SAAS,EAAE,8DAA8D;IAEzE,gEAAgE;IAChE,EAAE;IACF,gFAAgF;IAChF,yFAAyF;IACzF,uFAAuF;IACvF,wFAAwF;IACxF,8EAA8E;IAC9E,EAAE;IACF,2FAA2F;IAC3F,2FAA2F;IAC3F,oFAAoF;IACpF,aAAa;IACb,WAAW,EAAE,sEAAsE;CACpF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parity/ppn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Spin up a local Polkadot ecosystem: fetch, generate, fork and run a network",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/cli.js",
|
|
11
|
-
"./spawn-env": "./dist/lib/spawn-env.js"
|
|
11
|
+
"./spawn-env": "./dist/lib/spawn-env.js",
|
|
12
|
+
"./secrets": "./dist/lib/secrets-example.js"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"@polkadot-labs/hdkd-helpers": "^0.0.11",
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"commander": "^15.0.0",
|
|
21
22
|
"polkadot-api": "^1.23.3",
|
|
22
23
|
"toml": "^4.2.0",
|
|
23
|
-
"@parity/ppn-network-config": "0.
|
|
24
|
+
"@parity/ppn-network-config": "0.10.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^24.0.0",
|
package/scripts/dub/postgres.sh
CHANGED
|
@@ -43,7 +43,7 @@ if [[ ! -x "$PG_DIST/bin/postgres" ]]; then
|
|
|
43
43
|
exit 1
|
|
44
44
|
fi
|
|
45
45
|
|
|
46
|
-
"$SCRIPT_DIR/../
|
|
46
|
+
"$SCRIPT_DIR/../require-free-ports.sh" "$DUB_POSTGRES_PORT" || exit 1
|
|
47
47
|
|
|
48
48
|
# initdb once; on restart the existing cluster is reused.
|
|
49
49
|
if [[ ! -f "$PGDATA/PG_VERSION" ]]; then
|
|
@@ -67,6 +67,9 @@ PG_OPTS=(
|
|
|
67
67
|
-p "$DUB_POSTGRES_PORT"
|
|
68
68
|
-c listen_addresses=127.0.0.1
|
|
69
69
|
-c unix_socket_directories=
|
|
70
|
+
# Keep dynamic shared memory under PGDATA, not /dev/shm, where systemd-logind's
|
|
71
|
+
# RemoveIPC deletes it when the user's last session ends.
|
|
72
|
+
-c dynamic_shared_memory_type=mmap
|
|
70
73
|
)
|
|
71
74
|
|
|
72
75
|
PG_PID=""
|
package/scripts/dub/service.sh
CHANGED
|
@@ -154,12 +154,13 @@ if [[ -z "${JWT_ED25519_PUBLIC_KEY:-}" && -z "${JWT_JWKS_JSON:-}" ]]; then
|
|
|
154
154
|
export JWT_ED25519_PUBLIC_KEY
|
|
155
155
|
fi
|
|
156
156
|
|
|
157
|
-
# 2.
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
157
|
+
# 2. Refuse a port that is already held. The supervision loop below would otherwise
|
|
158
|
+
# respawn against "Address already in use (os error 48)" forever. The holder is
|
|
159
|
+
# not ours to stop: it may be a leftover of a previous run (`ppn kill`), or
|
|
160
|
+
# anyone's. BIND_ADDR comes from the TOML env and is only set for the services
|
|
161
|
+
# that listen, so this is a no-op for the workers.
|
|
161
162
|
if [[ -n "${BIND_ADDR:-}" ]]; then
|
|
162
|
-
"$PROJECT_DIR/scripts/
|
|
163
|
+
"$PROJECT_DIR/scripts/require-free-ports.sh" "${BIND_ADDR##*:}" || exit 1
|
|
163
164
|
fi
|
|
164
165
|
|
|
165
166
|
# 3. Wait for Postgres. Every service connects and applies migrations before
|
package/scripts/ipfs-daemon.sh
CHANGED
|
@@ -12,8 +12,9 @@ source "$PROJECT_DIR/config/ports.env"
|
|
|
12
12
|
export IPFS_PATH="$BIN_DIR/.ipfs"
|
|
13
13
|
LOCK_FILE="$IPFS_PATH/repo.lock"
|
|
14
14
|
|
|
15
|
-
#
|
|
16
|
-
|
|
15
|
+
# A daemon that cannot bind its ports would restart below for ever: stop here instead, naming
|
|
16
|
+
# whatever holds them (a stale daemon from a previous run, or someone else's).
|
|
17
|
+
"$SCRIPT_DIR/require-free-ports.sh" "$IPFS_GATEWAY_PORT" "$IPFS_API_PORT" "$IPFS_SWARM_PORT" || exit 1
|
|
17
18
|
|
|
18
19
|
IPFS_PID=""
|
|
19
20
|
cleanup() {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Refuse to go on while anything listens on the given TCP port(s). Never kills it: the holder may
|
|
3
|
+
# be a previous run of this network, another checkout's network or a service that has nothing to
|
|
4
|
+
# do with PPN, and a signal cannot tell them apart. `ppn kill` stops a previous run of this
|
|
5
|
+
# workspace. Listeners only: a bare `lsof -i :port` also matches every client whose connection
|
|
6
|
+
# has that port at the other end.
|
|
7
|
+
# Usage: require-free-ports.sh 8080 5001 4001
|
|
8
|
+
set -uo pipefail
|
|
9
|
+
|
|
10
|
+
status=0
|
|
11
|
+
for port in "$@"; do
|
|
12
|
+
[[ -n "$port" ]] || continue
|
|
13
|
+
holders="" pid=""
|
|
14
|
+
# lsof -F pc: a `p<pid>` line, then its `c<command>` line. The name shown is argv[0]'s basename
|
|
15
|
+
# (`ps -o args=`): lsof's COMMAND is the kernel's name, on Linux the main thread's (`MainThread`
|
|
16
|
+
# for Node). lsof's COMMAND only when `ps` gives nothing.
|
|
17
|
+
while IFS= read -r line; do
|
|
18
|
+
case "$line" in
|
|
19
|
+
p*) pid=${line#p} ;;
|
|
20
|
+
c*)
|
|
21
|
+
name=$(ps -o args= -p "$pid" 2>/dev/null | awk 'NR == 1 { print $1 }')
|
|
22
|
+
name=${name##*/}
|
|
23
|
+
holders+="${holders:+, }${name:-${line#c}}($pid)"
|
|
24
|
+
;;
|
|
25
|
+
esac
|
|
26
|
+
done < <(lsof -nP -iTCP:"$port" -sTCP:LISTEN -F pc 2>/dev/null)
|
|
27
|
+
if [[ -n "$holders" ]]; then
|
|
28
|
+
echo "port $port is in use by $holders; nothing was stopped (\`ppn kill\` stops a previous run of this workspace)" >&2
|
|
29
|
+
status=1
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
exit "$status"
|
package/scripts/turn.sh
CHANGED
|
@@ -5,13 +5,12 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
5
5
|
ENTRY="$ROOT/bin/ppn.mjs"
|
|
6
6
|
[[ -f "$ENTRY" ]] || ENTRY="$ROOT/dist/bin.js"
|
|
7
7
|
|
|
8
|
-
# A leftover eturnal from a previous run holds the ports
|
|
9
|
-
#
|
|
8
|
+
# A leftover eturnal from a previous run holds the ports, or another network's relay does, or
|
|
9
|
+
# any other Erlang node (the old sweep killed every `beam` listener on them): refuse, naming it.
|
|
10
|
+
# `ppn kill` stops this workspace's own, through `ppn service turn`.
|
|
10
11
|
source "$ROOT/scripts/lib/workspace.sh"
|
|
11
12
|
source "$ROOT/config/ports.env"
|
|
12
13
|
[[ -f "$PPN_WS/config/ports.local.env" ]] && source "$PPN_WS/config/ports.local.env"
|
|
13
|
-
|
|
14
|
-
lsof -ti "tcp:$port" -sTCP:LISTEN -a -c beam 2>/dev/null | xargs kill 2>/dev/null || true
|
|
15
|
-
done
|
|
14
|
+
"$ROOT/scripts/require-free-ports.sh" "$TURN_PORT" "$TURN_PROXY_PORT" || exit 1
|
|
16
15
|
|
|
17
16
|
exec node "$ENTRY" service turn
|
|
@@ -180,11 +180,12 @@ env = [
|
|
|
180
180
|
{ name = "METRICS_ENABLED", value = "false" },
|
|
181
181
|
{ name = "RUST_LOG", value = "info" },
|
|
182
182
|
{ name = "PEOPLE_RPC_URL", value = "ws://127.0.0.1:10010" },
|
|
183
|
+
{ name = "ASSET_HUB_RPC_URL", value = "ws://127.0.0.1:10020" },
|
|
183
184
|
{ name = "PEOPLE_NETWORK", value = "paseo" },
|
|
184
185
|
{ name = "ATTESTER_ACCOUNT", value = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" },
|
|
185
186
|
{ name = "INVITER_ADDRESS", value = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" },
|
|
186
187
|
{ name = "BIND_ADDR", value = "127.0.0.1:8092" },
|
|
187
|
-
{ name = "
|
|
188
|
+
{ name = "TURN_PROVIDER", value = "coturn" },
|
|
188
189
|
{ name = "TURN_REALM", value = "previewnet.local" },
|
|
189
190
|
]
|
|
190
191
|
|
|
@@ -199,6 +200,7 @@ env = [
|
|
|
199
200
|
{ name = "METRICS_ENABLED", value = "false" },
|
|
200
201
|
{ name = "RUST_LOG", value = "info" },
|
|
201
202
|
{ name = "PEOPLE_RPC_URL", value = "ws://127.0.0.1:10010" },
|
|
203
|
+
{ name = "ASSET_HUB_RPC_URL", value = "ws://127.0.0.1:10020" },
|
|
202
204
|
{ name = "PEOPLE_NETWORK", value = "paseo" },
|
|
203
205
|
{ name = "ATTESTER_ACCOUNT", value = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" },
|
|
204
206
|
{ name = "INVITER_ADDRESS", value = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" },
|
|
@@ -215,6 +217,7 @@ env = [
|
|
|
215
217
|
{ name = "METRICS_ENABLED", value = "false" },
|
|
216
218
|
{ name = "RUST_LOG", value = "info" },
|
|
217
219
|
{ name = "PEOPLE_RPC_URL", value = "ws://127.0.0.1:10010" },
|
|
220
|
+
{ name = "ASSET_HUB_RPC_URL", value = "ws://127.0.0.1:10020" },
|
|
218
221
|
{ name = "PEOPLE_NETWORK", value = "paseo" },
|
|
219
222
|
{ name = "ATTESTER_ACCOUNT", value = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" },
|
|
220
223
|
{ name = "INVITER_ADDRESS", value = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" },
|
|
@@ -231,6 +234,7 @@ env = [
|
|
|
231
234
|
{ name = "METRICS_ENABLED", value = "false" },
|
|
232
235
|
{ name = "RUST_LOG", value = "info" },
|
|
233
236
|
{ name = "PEOPLE_RPC_URL", value = "ws://127.0.0.1:10010" },
|
|
237
|
+
{ name = "ASSET_HUB_RPC_URL", value = "ws://127.0.0.1:10020" },
|
|
234
238
|
{ name = "PEOPLE_NETWORK", value = "paseo" },
|
|
235
239
|
{ name = "ATTESTER_ACCOUNT", value = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" },
|
|
236
240
|
{ name = "INVITER_ADDRESS", value = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" },
|
package/scripts/kill-port.sh
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Kill any process listening on the given port(s).
|
|
3
|
-
# Usage: kill-port.sh 8080 5001 4001
|
|
4
|
-
|
|
5
|
-
for PORT in "$@"; do
|
|
6
|
-
PIDS=$(lsof -ti ":$PORT" 2>/dev/null)
|
|
7
|
-
if [ -n "$PIDS" ]; then
|
|
8
|
-
echo "Killing process(es) on port $PORT: $PIDS"
|
|
9
|
-
echo "$PIDS" | xargs kill -9 2>/dev/null || true
|
|
10
|
-
fi
|
|
11
|
-
done
|