@parity/ppn 0.2.0-rc.1

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.
Files changed (147) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +84 -0
  3. package/config/ports.env +128 -0
  4. package/config/versions.env +120 -0
  5. package/dist/bin.d.ts +2 -0
  6. package/dist/bin.js +30 -0
  7. package/dist/bin.js.map +1 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.js +471 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/commands/bite.d.ts +27 -0
  12. package/dist/commands/bite.js +556 -0
  13. package/dist/commands/bite.js.map +1 -0
  14. package/dist/commands/dashboard.d.ts +2 -0
  15. package/dist/commands/dashboard.js +503 -0
  16. package/dist/commands/dashboard.js.map +1 -0
  17. package/dist/commands/dist.d.ts +7 -0
  18. package/dist/commands/dist.js +121 -0
  19. package/dist/commands/dist.js.map +1 -0
  20. package/dist/commands/fetch.d.ts +11 -0
  21. package/dist/commands/fetch.js +550 -0
  22. package/dist/commands/fetch.js.map +1 -0
  23. package/dist/commands/fork.d.ts +1 -0
  24. package/dist/commands/fork.js +164 -0
  25. package/dist/commands/fork.js.map +1 -0
  26. package/dist/commands/generate.d.ts +7 -0
  27. package/dist/commands/generate.js +201 -0
  28. package/dist/commands/generate.js.map +1 -0
  29. package/dist/commands/genesis-toml.d.ts +1 -0
  30. package/dist/commands/genesis-toml.js +26 -0
  31. package/dist/commands/genesis-toml.js.map +1 -0
  32. package/dist/commands/nginx-conf.d.ts +1 -0
  33. package/dist/commands/nginx-conf.js +32 -0
  34. package/dist/commands/nginx-conf.js.map +1 -0
  35. package/dist/commands/service-context.d.ts +13 -0
  36. package/dist/commands/service-context.js +5 -0
  37. package/dist/commands/service-context.js.map +1 -0
  38. package/dist/commands/service.d.ts +28 -0
  39. package/dist/commands/service.js +807 -0
  40. package/dist/commands/service.js.map +1 -0
  41. package/dist/commands/stamp-spawn.d.ts +7 -0
  42. package/dist/commands/stamp-spawn.js +43 -0
  43. package/dist/commands/stamp-spawn.js.map +1 -0
  44. package/dist/commands/start.d.ts +33 -0
  45. package/dist/commands/start.js +462 -0
  46. package/dist/commands/start.js.map +1 -0
  47. package/dist/commands/upgrade.d.ts +15 -0
  48. package/dist/commands/upgrade.js +101 -0
  49. package/dist/commands/upgrade.js.map +1 -0
  50. package/dist/fork/chains.d.ts +25 -0
  51. package/dist/fork/chains.js +36 -0
  52. package/dist/fork/chains.js.map +1 -0
  53. package/dist/fork/codec.d.ts +36 -0
  54. package/dist/fork/codec.js +122 -0
  55. package/dist/fork/codec.js.map +1 -0
  56. package/dist/fork/manifest.d.ts +13 -0
  57. package/dist/fork/manifest.js +77 -0
  58. package/dist/fork/manifest.js.map +1 -0
  59. package/dist/fork/overrides.d.ts +45 -0
  60. package/dist/fork/overrides.js +255 -0
  61. package/dist/fork/overrides.js.map +1 -0
  62. package/dist/fork/products.d.ts +68 -0
  63. package/dist/fork/products.js +265 -0
  64. package/dist/fork/products.js.map +1 -0
  65. package/dist/fork/rpc.d.ts +25 -0
  66. package/dist/fork/rpc.js +51 -0
  67. package/dist/fork/rpc.js.map +1 -0
  68. package/dist/fork/shared-relay.d.ts +99 -0
  69. package/dist/fork/shared-relay.js +162 -0
  70. package/dist/fork/shared-relay.js.map +1 -0
  71. package/dist/fork/sleep.d.ts +3 -0
  72. package/dist/fork/sleep.js +2 -0
  73. package/dist/fork/sleep.js.map +1 -0
  74. package/dist/fork/validators.d.ts +81 -0
  75. package/dist/fork/validators.js +170 -0
  76. package/dist/fork/validators.js.map +1 -0
  77. package/dist/fork/verify.d.ts +79 -0
  78. package/dist/fork/verify.js +192 -0
  79. package/dist/fork/verify.js.map +1 -0
  80. package/dist/lib/archive.d.ts +8 -0
  81. package/dist/lib/archive.js +40 -0
  82. package/dist/lib/archive.js.map +1 -0
  83. package/dist/lib/fork-bundle-name.d.ts +4 -0
  84. package/dist/lib/fork-bundle-name.js +20 -0
  85. package/dist/lib/fork-bundle-name.js.map +1 -0
  86. package/dist/lib/github.d.ts +48 -0
  87. package/dist/lib/github.js +192 -0
  88. package/dist/lib/github.js.map +1 -0
  89. package/dist/lib/provenance.d.ts +67 -0
  90. package/dist/lib/provenance.js +98 -0
  91. package/dist/lib/provenance.js.map +1 -0
  92. package/dist/lib/spawn-env.d.ts +33 -0
  93. package/dist/lib/spawn-env.js +71 -0
  94. package/dist/lib/spawn-env.js.map +1 -0
  95. package/dist/lib/spawn-stamp.d.ts +34 -0
  96. package/dist/lib/spawn-stamp.js +63 -0
  97. package/dist/lib/spawn-stamp.js.map +1 -0
  98. package/dist/upgrade/chains.d.ts +4 -0
  99. package/dist/upgrade/chains.js +17 -0
  100. package/dist/upgrade/chains.js.map +1 -0
  101. package/dist/upgrade/fund.d.ts +38 -0
  102. package/dist/upgrade/fund.js +119 -0
  103. package/dist/upgrade/fund.js.map +1 -0
  104. package/dist/upgrade/provider-node.d.ts +2 -0
  105. package/dist/upgrade/provider-node.js +7 -0
  106. package/dist/upgrade/provider-node.js.map +1 -0
  107. package/dist/upgrade/signer.d.ts +21 -0
  108. package/dist/upgrade/signer.js +48 -0
  109. package/dist/upgrade/signer.js.map +1 -0
  110. package/dist/upgrade/sudo.d.ts +2 -0
  111. package/dist/upgrade/sudo.js +26 -0
  112. package/dist/upgrade/sudo.js.map +1 -0
  113. package/dist/upgrade/upgrade.d.ts +128 -0
  114. package/dist/upgrade/upgrade.js +539 -0
  115. package/dist/upgrade/upgrade.js.map +1 -0
  116. package/networks/README.md +120 -0
  117. package/networks/devnet.json +113 -0
  118. package/networks/kusama.json +56 -0
  119. package/networks/paseo-next-v2.json +87 -0
  120. package/networks/polkadot.json +57 -0
  121. package/networks/previewnet.json +186 -0
  122. package/package.json +54 -0
  123. package/scripts/assign-cores.sh +12 -0
  124. package/scripts/dashboard.sh +11 -0
  125. package/scripts/docker-entrypoint.sh +52 -0
  126. package/scripts/dub/postgres.sh +116 -0
  127. package/scripts/dub/service.sh +202 -0
  128. package/scripts/ensure-dot-cli.sh +23 -0
  129. package/scripts/eth-rpc.sh +45 -0
  130. package/scripts/force-open-hrmp.sh +11 -0
  131. package/scripts/grant-invites.sh +11 -0
  132. package/scripts/increase-people-lite-attestation-allowance.sh +11 -0
  133. package/scripts/install.sh +12 -0
  134. package/scripts/ipfs-daemon.sh +48 -0
  135. package/scripts/ipfs-swarm.sh +48 -0
  136. package/scripts/kill-port.sh +11 -0
  137. package/scripts/lib/workspace.sh +47 -0
  138. package/scripts/omni-node.sh +112 -0
  139. package/scripts/patch-bootnodes.sh +11 -0
  140. package/scripts/pin-bulletin-products.sh +11 -0
  141. package/scripts/pin-design-families.sh +144 -0
  142. package/scripts/set-dispatcher-address.sh +11 -0
  143. package/scripts/storage-provider-node.sh +11 -0
  144. package/web/assets/index-BW4b1s2y.js +7 -0
  145. package/web/assets/index-X3pZpnYk.css +1 -0
  146. package/web/index.html +13 -0
  147. package/zombienet-configs/local-dev.toml +253 -0
@@ -0,0 +1,79 @@
1
+ import type { ForkManifest } from './manifest.js';
2
+ import { type Sleep } from './sleep.js';
3
+ export interface ChainTarget {
4
+ key: string;
5
+ url: string;
6
+ /** Block the bite captured; the fork must continue from here, not restart. */
7
+ biteBlock: number;
8
+ }
9
+ export interface ChainResult {
10
+ key: string;
11
+ best: number;
12
+ finalized: number;
13
+ produced: number;
14
+ ok: boolean;
15
+ problems: string[];
16
+ }
17
+ /**
18
+ * Sample each chain twice, `waitMs` apart.
19
+ *
20
+ * Two samples rather than one because the interesting failures are all "stops after a
21
+ * while": a single reading cannot tell a live chain from one that stalled at a plausible
22
+ * height.
23
+ */
24
+ export declare function checkChains(targets: readonly ChainTarget[], waitMs: number, sleep?: Sleep): Promise<ChainResult[]>;
25
+ export interface WaitOptions {
26
+ /**
27
+ * Also require each chain's finalized height to advance.
28
+ *
29
+ * A parachain block is only final once the relay block carrying its candidate is
30
+ * finalized by GRANDPA, so for the first minute of a fork every parachain produces
31
+ * blocks while its finality sits still — indistinguishable, in a 30s sample, from the
32
+ * dispute-lifetime bug that leaves a chain permanently unfinalized. Waiting for one
33
+ * finality step proves the pipeline is primed, and turns that race into a bounded wait.
34
+ */
35
+ requireFinality?: boolean;
36
+ pollMs?: number;
37
+ sleep?: Sleep;
38
+ now?: () => number;
39
+ }
40
+ /**
41
+ * Block until every chain is ready, or `timeoutMs` elapses.
42
+ *
43
+ * `checkChains` measures across two samples, so a chain it cannot reach for the first one
44
+ * is unmeasurable however healthy it is. In fork mode the collators restore multi-hundred-MB
45
+ * DB snapshots and come up long after the relay, so "the relay answers" is not a readiness
46
+ * signal for the network — waiting on that alone is what made a CI run indict four
47
+ * collators that were busily producing blocks.
48
+ *
49
+ * Chains drop out of the poll once ready; one that goes down afterwards is caught by the
50
+ * production check that follows.
51
+ */
52
+ export declare function waitForChains(targets: readonly ChainTarget[], timeoutMs: number, opts?: WaitOptions): Promise<{
53
+ ok: boolean;
54
+ waitedMs: number;
55
+ missing: string[];
56
+ }>;
57
+ /**
58
+ * Every parachain must be on its own chain.
59
+ *
60
+ * `fork-toml.ts` does set `chain` alongside `chain_spec_path` — this guards against losing
61
+ * it again. Without it zombienet applies one spec to every parachain, and the only symptom
62
+ * is their heights drifting together, so compare genesis hashes, which are unambiguous.
63
+ */
64
+ export declare function checkDistinctChains(targets: readonly ChainTarget[]): Promise<{
65
+ ok: boolean;
66
+ problems: string[];
67
+ }>;
68
+ /**
69
+ * The fork must have diverged from the network it was bitten from.
70
+ *
71
+ * Leaving bootNodes in the spawn specs makes the fork rejoin production and follow its
72
+ * chain — which looks healthy on every other metric while not being a fork at all.
73
+ */
74
+ export declare function checkDiverged(forkRelayUrl: string, sourceRelayUrl: string, biteBlock: number): Promise<{
75
+ ok: boolean;
76
+ detail: string;
77
+ }>;
78
+ /** Chain targets for every chain the bundle carries. */
79
+ export declare function targetsFromManifest(manifest: ForkManifest, portOf: (key: string) => number, host?: string): ChainTarget[];
@@ -0,0 +1,192 @@
1
+ // Is a running fork actually working?
2
+ //
3
+ // Spawning a fork succeeds long before it is correct. The failures seen in practice were
4
+ // all of the "looks fine, isn't" kind: parachains converging on one chain because `chain`
5
+ // was missing, nodes producing but never finalizing because the dispute lifetime was
6
+ // unset, collators dying a hundred blocks in on pruned state, and a fork quietly rejoining
7
+ // production because bootNodes were not stripped. None of those show up as a failed spawn.
8
+ //
9
+ // So the checks here are the ones those bugs would have failed, against a live network.
10
+ import { rpc } from './rpc.js';
11
+ import { sleep as realSleep } from './sleep.js';
12
+ async function head(url) {
13
+ const [h, fh] = await Promise.all([
14
+ rpc(url, 'chain_getHeader'),
15
+ rpc(url, 'chain_getFinalizedHead'),
16
+ ]);
17
+ const f = await rpc(url, 'chain_getHeader', [fh]);
18
+ return { best: parseInt(h.number, 16), finalized: parseInt(f.number, 16) };
19
+ }
20
+ /**
21
+ * Sample each chain twice, `waitMs` apart.
22
+ *
23
+ * Two samples rather than one because the interesting failures are all "stops after a
24
+ * while": a single reading cannot tell a live chain from one that stalled at a plausible
25
+ * height.
26
+ */
27
+ export async function checkChains(targets, waitMs, sleep = realSleep) {
28
+ const first = new Map();
29
+ for (const t of targets) {
30
+ try {
31
+ first.set(t.key, await head(t.url));
32
+ }
33
+ catch {
34
+ /* reported below as unreachable */
35
+ }
36
+ }
37
+ await sleep(waitMs);
38
+ const results = [];
39
+ for (const t of targets) {
40
+ const problems = [];
41
+ const before = first.get(t.key);
42
+ let now = null;
43
+ try {
44
+ now = await head(t.url);
45
+ }
46
+ catch (e) {
47
+ problems.push(`unreachable: ${e.message}`);
48
+ }
49
+ if (!now) {
50
+ results.push({ key: t.key, best: 0, finalized: 0, produced: 0, ok: false, problems });
51
+ continue;
52
+ }
53
+ if (!before) {
54
+ // Reachable now but not when sampling began, so the heights are real and the delta
55
+ // is not. Reporting this as a plain zeroed row is what made four healthy collators
56
+ // look dead in CI: say which half of the measurement is missing.
57
+ problems.push('was unreachable when sampling started — production not measured');
58
+ results.push({
59
+ key: t.key,
60
+ best: now.best,
61
+ finalized: now.finalized,
62
+ produced: 0,
63
+ ok: false,
64
+ problems,
65
+ });
66
+ continue;
67
+ }
68
+ // Continuing from the bite, not restarted at genesis: the whole point of a fork.
69
+ if (now.best < t.biteBlock) {
70
+ problems.push(`best #${now.best} is below the bite block #${t.biteBlock} — restarted?`);
71
+ }
72
+ const produced = now.best - before.best;
73
+ if (produced <= 0)
74
+ problems.push(`not producing (stuck at #${now.best})`);
75
+ // Blocks without finality is the signature of the dispute-lifetime bug.
76
+ if (now.finalized <= before.finalized) {
77
+ problems.push(`not finalizing (stuck at #${now.finalized})`);
78
+ }
79
+ if (now.finalized < t.biteBlock) {
80
+ problems.push(`finalized #${now.finalized} is below the bite block #${t.biteBlock} — restarted?`);
81
+ }
82
+ results.push({
83
+ key: t.key,
84
+ best: now.best,
85
+ finalized: now.finalized,
86
+ produced,
87
+ ok: problems.length === 0,
88
+ problems,
89
+ });
90
+ }
91
+ return results;
92
+ }
93
+ /**
94
+ * Block until every chain is ready, or `timeoutMs` elapses.
95
+ *
96
+ * `checkChains` measures across two samples, so a chain it cannot reach for the first one
97
+ * is unmeasurable however healthy it is. In fork mode the collators restore multi-hundred-MB
98
+ * DB snapshots and come up long after the relay, so "the relay answers" is not a readiness
99
+ * signal for the network — waiting on that alone is what made a CI run indict four
100
+ * collators that were busily producing blocks.
101
+ *
102
+ * Chains drop out of the poll once ready; one that goes down afterwards is caught by the
103
+ * production check that follows.
104
+ */
105
+ export async function waitForChains(targets, timeoutMs, opts = {}) {
106
+ const sleep = opts.sleep ?? realSleep;
107
+ const now = opts.now ?? (() => Date.now());
108
+ const pollMs = opts.pollMs ?? 5_000;
109
+ const started = now();
110
+ const firstFinalized = new Map();
111
+ let missing = targets.map((t) => t.key);
112
+ for (;;) {
113
+ const pending = [];
114
+ for (const t of targets) {
115
+ if (!missing.includes(t.key))
116
+ continue;
117
+ try {
118
+ const h = await head(t.url);
119
+ if (opts.requireFinality) {
120
+ const first = firstFinalized.get(t.key);
121
+ if (first === undefined)
122
+ firstFinalized.set(t.key, h.finalized);
123
+ if (first === undefined || h.finalized <= first)
124
+ pending.push(t.key);
125
+ }
126
+ }
127
+ catch {
128
+ pending.push(t.key);
129
+ }
130
+ }
131
+ missing = pending;
132
+ if (missing.length === 0)
133
+ return { ok: true, waitedMs: now() - started, missing: [] };
134
+ if (now() - started >= timeoutMs)
135
+ return { ok: false, waitedMs: now() - started, missing };
136
+ await sleep(pollMs);
137
+ }
138
+ }
139
+ /**
140
+ * Every parachain must be on its own chain.
141
+ *
142
+ * `fork-toml.ts` does set `chain` alongside `chain_spec_path` — this guards against losing
143
+ * it again. Without it zombienet applies one spec to every parachain, and the only symptom
144
+ * is their heights drifting together, so compare genesis hashes, which are unambiguous.
145
+ */
146
+ export async function checkDistinctChains(targets) {
147
+ const seen = new Map();
148
+ const problems = [];
149
+ for (const t of targets) {
150
+ try {
151
+ const genesis = await rpc(t.url, 'chain_getBlockHash', [0]);
152
+ const other = seen.get(genesis);
153
+ if (other)
154
+ problems.push(`${t.key} and ${other} share genesis ${genesis}`);
155
+ else
156
+ seen.set(genesis, t.key);
157
+ }
158
+ catch {
159
+ problems.push(`${t.key}: could not read genesis`);
160
+ }
161
+ }
162
+ return { ok: problems.length === 0, problems };
163
+ }
164
+ /**
165
+ * The fork must have diverged from the network it was bitten from.
166
+ *
167
+ * Leaving bootNodes in the spawn specs makes the fork rejoin production and follow its
168
+ * chain — which looks healthy on every other metric while not being a fork at all.
169
+ */
170
+ export async function checkDiverged(forkRelayUrl, sourceRelayUrl, biteBlock) {
171
+ const at = biteBlock + 5;
172
+ const [mine, theirs] = await Promise.all([
173
+ rpc(forkRelayUrl, 'chain_getBlockHash', [at]).catch(() => null),
174
+ rpc(sourceRelayUrl, 'chain_getBlockHash', [at]).catch(() => null),
175
+ ]);
176
+ if (!mine)
177
+ return { ok: false, detail: `fork has no block #${at}` };
178
+ if (!theirs)
179
+ return { ok: true, detail: `source has no block #${at}; nothing to compare` };
180
+ return mine === theirs
181
+ ? { ok: false, detail: `fork and source share block #${at} (${mine}) — not diverged` }
182
+ : { ok: true, detail: `block #${at} differs from source` };
183
+ }
184
+ /** Chain targets for every chain the bundle carries. */
185
+ export function targetsFromManifest(manifest, portOf, host = 'http://127.0.0.1') {
186
+ return Object.entries(manifest.chains).map(([key, chain]) => ({
187
+ key,
188
+ url: `${host}:${portOf(key)}`,
189
+ biteBlock: manifest.biteBlocks[chain.paraId === null ? 'relay' : String(chain.paraId)] ?? 0,
190
+ }));
191
+ }
192
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/fork/verify.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,EAAE;AACF,yFAAyF;AACzF,0FAA0F;AAC1F,qFAAqF;AACrF,2FAA2F;AAC3F,2FAA2F;AAC3F,EAAE;AACF,wFAAwF;AAExF,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAc,MAAM,YAAY,CAAC;AAkB5D,KAAK,UAAU,IAAI,CAAC,GAAW;IAC7B,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChC,GAAG,CAAqB,GAAG,EAAE,iBAAiB,CAAC;QAC/C,GAAG,CAAS,GAAG,EAAE,wBAAwB,CAAC;KAC3C,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,MAAM,GAAG,CAAqB,GAAG,EAAE,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAA+B,EAC/B,MAAc,EACd,QAAe,S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AG,CAAC,EAAE;QAC7B,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;KAC5F,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function extractTarGz(archive: string, dest: string, opts?: {
2
+ strip?: number;
3
+ only?: string;
4
+ }): void;
5
+ export declare function extractZip(archive: string, dest: string): void;
6
+ /** First file with this name anywhere under dir — tarballs nest under a versioned path. */
7
+ export declare function findFile(dir: string, name: string): string | undefined;
8
+ export declare function withTempDir<T>(fn: (dir: string) => T): T;
@@ -0,0 +1,40 @@
1
+ // Unpacking the archives some upstreams ship instead of bare binaries.
2
+ //
3
+ // `tar` and `unzip` are called as child processes rather than pulled in as libraries:
4
+ // they are already required on every machine that runs PPN, and a tarball is exactly the
5
+ // kind of thing where the system tool is more trustworthy than a dependency.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import os from 'node:os';
9
+ import { execFileSync } from 'node:child_process';
10
+ export function extractTarGz(archive, dest, opts = {}) {
11
+ fs.mkdirSync(dest, { recursive: true });
12
+ const args = ['-xzf', archive, '-C', dest];
13
+ if (opts.strip !== undefined)
14
+ args.push(`--strip-components=${opts.strip}`);
15
+ if (opts.only)
16
+ args.push(opts.only);
17
+ execFileSync('tar', args, { stdio: 'inherit' });
18
+ }
19
+ export function extractZip(archive, dest) {
20
+ fs.mkdirSync(dest, { recursive: true });
21
+ execFileSync('unzip', ['-oq', archive, '-d', dest], { stdio: 'inherit' });
22
+ }
23
+ /** First file with this name anywhere under dir — tarballs nest under a versioned path. */
24
+ export function findFile(dir, name) {
25
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true, recursive: true })) {
26
+ if (entry.isFile() && entry.name === name)
27
+ return path.join(entry.parentPath ?? dir, entry.name);
28
+ }
29
+ return undefined;
30
+ }
31
+ export function withTempDir(fn) {
32
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-'));
33
+ try {
34
+ return fn(dir);
35
+ }
36
+ finally {
37
+ fs.rmSync(dir, { recursive: true, force: true });
38
+ }
39
+ }
40
+ //# sourceMappingURL=archive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/lib/archive.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,sFAAsF;AACtF,yFAAyF;AACzF,6EAA6E;AAE7E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,IAAY,EACZ,OAA0C,EAAE;IAE5C,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5E,IAAI,IAAI,CAAC,IAAI;QAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,IAAY;IACtD,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,QAAQ,CAAC,GAAW,EAAE,IAAY;IAChD,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAClF,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,EAAsB;IACnD,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Directory and asset stem for a network's bundle, e.g. `fork-bundle-previewnet`. */
2
+ export declare function forkBundleName(network: string): string;
3
+ /** The published release asset, e.g. `fork-bundle-previewnet.tar.gz`. */
4
+ export declare function forkBundleAsset(network: string): string;
@@ -0,0 +1,20 @@
1
+ // The name of a network's fork bundle — one definition, used by the directory `ppn bite`
2
+ // writes, the release asset the nightly bite publishes, and everything that reads either.
3
+ //
4
+ // Every network is named, previewnet included. It used to be the exception: its bundle was
5
+ // the unsuffixed `fork-bundle.tar.gz` while everyone else got `fork-bundle-<network>`. That
6
+ // encoded an assumption this repo has no business making — for forking, the network behind
7
+ // previewnet.substrate.dev is just another source, no more the engine's own than dot.li is —
8
+ // and it read as "the obvious bundle" only to someone who already knew that host existed.
9
+ //
10
+ // Three commands derived the name independently, which is how the exception survived a
11
+ // refactor: fixing one site left the others disagreeing. It lives here so there is one.
12
+ /** Directory and asset stem for a network's bundle, e.g. `fork-bundle-previewnet`. */
13
+ export function forkBundleName(network) {
14
+ return `fork-bundle-${network}`;
15
+ }
16
+ /** The published release asset, e.g. `fork-bundle-previewnet.tar.gz`. */
17
+ export function forkBundleAsset(network) {
18
+ return `${forkBundleName(network)}.tar.gz`;
19
+ }
20
+ //# sourceMappingURL=fork-bundle-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fork-bundle-name.js","sourceRoot":"","sources":["../../src/lib/fork-bundle-name.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,0FAA0F;AAC1F,EAAE;AACF,2FAA2F;AAC3F,4FAA4F;AAC5F,2FAA2F;AAC3F,6FAA6F;AAC7F,0FAA0F;AAC1F,EAAE;AACF,uFAAuF;AACvF,wFAAwF;AAExF,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,eAAe,OAAO,EAAE,CAAC;AAClC,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,48 @@
1
+ export interface ReleaseAsset {
2
+ name: string;
3
+ url: string;
4
+ size: number;
5
+ }
6
+ export interface Release {
7
+ repo: string;
8
+ tag: string;
9
+ assets: ReleaseAsset[];
10
+ }
11
+ /** From the environment, or from git's credential helper (what `gh auth login` writes). */
12
+ export declare function githubToken(): string;
13
+ /**
14
+ * Read a release's metadata. `latest` tries the /latest endpoint first; anything else is a tag.
15
+ * Throws with the repo named, because "cannot read release X" is nearly always a token
16
+ * that cannot see a private repo rather than a wrong pin.
17
+ *
18
+ * `/releases/latest` only exists once a repo has marked a full (non-prerelease) release —
19
+ * a repo publishing only nightlies or prereleases 404s on it forever. In that case fall back
20
+ * to the newest release in the list, whatever kind it is: for a `latest` pin, "the freshest
21
+ * thing published" is what the descriptor means.
22
+ */
23
+ export declare function fetchRelease(repo: string, tag: string, token: string,
24
+ /**
25
+ * Asset names the caller is going to ask this release for. Only consulted on the `latest`
26
+ * fallback below, where it is the difference between the right release and a coin toss.
27
+ */
28
+ wanted?: string[]): Promise<Release>;
29
+ /** The same list with each release's assets, so a caller can tell which one holds what. */
30
+ export declare function listReleaseDetails(repo: string, token: string, perPage?: number): Promise<{
31
+ tag_name: string;
32
+ assets: ReleaseAsset[];
33
+ }[]>;
34
+ export declare function downloadAsset(release: Release, assetName: string, dest: string, token: string): Promise<boolean>;
35
+ /**
36
+ * Download one file out of a repository at a tag, rather than out of a release.
37
+ *
38
+ * Needed because not everything a release implies is published as an asset. The identity
39
+ * backend's API reference is committed under `docs/api-reference/` and its release carries
40
+ * only the binary tarballs, so the reference has to come from the tree — at the same tag as
41
+ * the binary, or it documents a different version of the service than the one running.
42
+ *
43
+ * Returns false on 404 (the path is not there at that tag), which callers treat as optional.
44
+ */
45
+ export declare function downloadRepoFile(repo: string, ref: string, repoPath: string, dest: string, token: string): Promise<boolean>;
46
+ /** Download a plain URL — the release/download path, for repos that need no auth. */
47
+ export declare function downloadUrl(url: string, dest: string): Promise<boolean>;
48
+ export declare function makeExecutable(file: string): void;
@@ -0,0 +1,192 @@
1
+ // Downloading release assets from GitHub.
2
+ //
3
+ // Assets are fetched through the API by asset id, not through browser_download_url: a
4
+ // private repo's assets are only reachable that way, and several of the repos PPN pulls
5
+ // from are private.
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { execFileSync } from 'node:child_process';
9
+ /** From the environment, or from git's credential helper (what `gh auth login` writes). */
10
+ export function githubToken() {
11
+ if (process.env.GITHUB_TOKEN)
12
+ return process.env.GITHUB_TOKEN;
13
+ try {
14
+ const out = execFileSync('git', ['credential', 'fill'], {
15
+ input: 'protocol=https\nhost=github.com\n\n',
16
+ encoding: 'utf-8',
17
+ stdio: ['pipe', 'pipe', 'ignore'],
18
+ });
19
+ const line = out.split('\n').find((l) => l.startsWith('password='));
20
+ if (line)
21
+ return line.slice('password='.length).trim();
22
+ }
23
+ catch {
24
+ /* no credential helper */
25
+ }
26
+ throw new Error('no GitHub token — set GITHUB_TOKEN, or run `gh auth login` (choose HTTPS and let it\n' +
27
+ ' configure git credentials). Release assets on private repos need it.');
28
+ }
29
+ const api = (token) => ({
30
+ Authorization: `token ${token}`,
31
+ Accept: 'application/vnd.github+json',
32
+ });
33
+ /**
34
+ * Read a release's metadata. `latest` tries the /latest endpoint first; anything else is a tag.
35
+ * Throws with the repo named, because "cannot read release X" is nearly always a token
36
+ * that cannot see a private repo rather than a wrong pin.
37
+ *
38
+ * `/releases/latest` only exists once a repo has marked a full (non-prerelease) release —
39
+ * a repo publishing only nightlies or prereleases 404s on it forever. In that case fall back
40
+ * to the newest release in the list, whatever kind it is: for a `latest` pin, "the freshest
41
+ * thing published" is what the descriptor means.
42
+ */
43
+ export async function fetchRelease(repo, tag, token,
44
+ /**
45
+ * Asset names the caller is going to ask this release for. Only consulted on the `latest`
46
+ * fallback below, where it is the difference between the right release and a coin toss.
47
+ */
48
+ wanted = []) {
49
+ if (tag === 'latest') {
50
+ const res = await fetch(`https://api.github.com/repos/${repo}/releases/latest`, {
51
+ headers: api(token),
52
+ });
53
+ if (res.ok) {
54
+ const json = (await res.json());
55
+ return { repo, tag: json.tag_name, assets: json.assets ?? [] };
56
+ }
57
+ if (res.status === 404) {
58
+ // A repo publishing only prereleases 404s here for ever, so fall back to the list. The
59
+ // list is ordered by creation, and "newest" alone is not enough to pick correctly:
60
+ // individuality-community publishes a nightly *and* a rolling `e2e-zombienet-snapshot`
61
+ // that share a created_at to the second. The snapshot carries node tarballs and no
62
+ // runtime WASM, so whichever of the two the tie happens to put first decided whether a
63
+ // fetch worked — and the tie flips whenever the rolling tag is republished.
64
+ //
65
+ // So prefer the newest release that actually carries what the caller came for, and only
66
+ // fall back to the plain newest when nothing does (or when nothing was named).
67
+ const releases = await listReleaseDetails(repo, token, 20);
68
+ const carries = (r) => wanted.length > 0 && wanted.every((w) => r.assets.some((a) => a.name === w));
69
+ const match = releases.find(carries);
70
+ if (match) {
71
+ if (match !== releases[0]) {
72
+ console.log(` (${repo} marks no latest release; its newest is ${releases[0].tag_name}, which ` +
73
+ `does not carry ${wanted.join(', ')} — using ${match.tag_name})`);
74
+ }
75
+ else {
76
+ console.log(` (${repo} marks no latest release; using its newest, ${match.tag_name})`);
77
+ }
78
+ return { repo, tag: match.tag_name, assets: match.assets };
79
+ }
80
+ const newest = releases[0];
81
+ if (newest) {
82
+ console.log(` (${repo} marks no latest release; using its newest, ${newest.tag_name})`);
83
+ return { repo, tag: newest.tag_name, assets: newest.assets };
84
+ }
85
+ }
86
+ throw new Error(`could not read release ${repo} @ latest (HTTP ${res.status})\n` +
87
+ ` Check the pin, and that your token can read ${repo}.`);
88
+ }
89
+ const res = await fetch(`https://api.github.com/repos/${repo}/releases/tags/${tag}`, {
90
+ headers: api(token),
91
+ });
92
+ if (!res.ok) {
93
+ throw new Error(`could not read release ${repo} @ ${tag} (HTTP ${res.status})\n` +
94
+ ` Check the pin, and that your token can read ${repo}.`);
95
+ }
96
+ const json = (await res.json());
97
+ return { repo, tag: json.tag_name, assets: json.assets ?? [] };
98
+ }
99
+ /** The same list with each release's assets, so a caller can tell which one holds what. */
100
+ export async function listReleaseDetails(repo, token, perPage = 10) {
101
+ const res = await fetch(`https://api.github.com/repos/${repo}/releases?per_page=${perPage}`, {
102
+ headers: api(token),
103
+ });
104
+ if (!res.ok)
105
+ throw new Error(`could not list releases for ${repo} (HTTP ${res.status})`);
106
+ return (await res.json()).map((r) => ({
107
+ tag_name: r.tag_name,
108
+ assets: r.assets ?? [],
109
+ }));
110
+ }
111
+ async function writeStream(res, dest) {
112
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
113
+ const buf = Buffer.from(await res.arrayBuffer());
114
+ fs.writeFileSync(dest, buf);
115
+ }
116
+ /**
117
+ * Download one named asset out of a release. Returns false when the release has no such
118
+ * asset — callers decide whether that is fatal, because several assets are optional.
119
+ */
120
+ /**
121
+ * Retry a download that died mid-stream.
122
+ *
123
+ * These are 100 MB+ binaries pulled from a CDN, and a cut connection surfaces from undici as
124
+ * `TypeError: terminated` — no status code, nothing the caller can distinguish from a real
125
+ * failure. One interrupted stream then fails the whole fetch, which on CI means a red run that
126
+ * says nothing about the change under test. A 404 or 403 is *not* retried: those are answers,
127
+ * not accidents.
128
+ */
129
+ async function withRetry(what, attempt) {
130
+ const delays = [1000, 3000, 8000];
131
+ for (let i = 0;; i++) {
132
+ try {
133
+ return await attempt();
134
+ }
135
+ catch (err) {
136
+ if (i >= delays.length) {
137
+ throw new Error(`${what} failed after ${delays.length + 1} attempts: ` +
138
+ (err instanceof Error ? err.message : String(err)));
139
+ }
140
+ const why = err instanceof Error ? err.message : String(err);
141
+ console.log(` … ${what} interrupted (${why}), retrying in ${delays[i] / 1000}s`);
142
+ await new Promise((r) => setTimeout(r, delays[i]));
143
+ }
144
+ }
145
+ }
146
+ export async function downloadAsset(release, assetName, dest, token) {
147
+ const asset = release.assets.find((a) => a.name === assetName);
148
+ if (!asset)
149
+ return false;
150
+ return withRetry(`download of ${assetName}`, async () => {
151
+ const res = await fetch(asset.url, {
152
+ headers: { Authorization: `token ${token}`, Accept: 'application/octet-stream' },
153
+ });
154
+ if (!res.ok)
155
+ return false;
156
+ await writeStream(res, dest);
157
+ return true;
158
+ });
159
+ }
160
+ /**
161
+ * Download one file out of a repository at a tag, rather than out of a release.
162
+ *
163
+ * Needed because not everything a release implies is published as an asset. The identity
164
+ * backend's API reference is committed under `docs/api-reference/` and its release carries
165
+ * only the binary tarballs, so the reference has to come from the tree — at the same tag as
166
+ * the binary, or it documents a different version of the service than the one running.
167
+ *
168
+ * Returns false on 404 (the path is not there at that tag), which callers treat as optional.
169
+ */
170
+ export async function downloadRepoFile(repo, ref, repoPath, dest, token) {
171
+ return withRetry(`download of ${repoPath}`, async () => {
172
+ const res = await fetch(`https://api.github.com/repos/${repo}/contents/${repoPath}?ref=${encodeURIComponent(ref)}`, { headers: { Authorization: `token ${token}`, Accept: 'application/vnd.github.raw' } });
173
+ if (!res.ok)
174
+ return false;
175
+ await writeStream(res, dest);
176
+ return true;
177
+ });
178
+ }
179
+ /** Download a plain URL — the release/download path, for repos that need no auth. */
180
+ export async function downloadUrl(url, dest) {
181
+ return withRetry(`download of ${path.basename(dest)}`, async () => {
182
+ const res = await fetch(url, { redirect: 'follow' });
183
+ if (!res.ok)
184
+ return false;
185
+ await writeStream(res, dest);
186
+ return true;
187
+ });
188
+ }
189
+ export function makeExecutable(file) {
190
+ fs.chmodSync(file, 0o755);
191
+ }
192
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/lib/github.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,sFAAsF;AACtF,wFAAwF;AACxF,oBAAoB;AAEpB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAclD,2FAA2F;AAC3F,MAAM,UAAU,WAAW;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE;YACtD,KAAK,EAAE,qCAAqC;YAC5C,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QA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