@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.
- package/LICENSE +202 -0
- package/README.md +84 -0
- package/config/ports.env +128 -0
- package/config/versions.env +120 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +30 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +471 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/bite.d.ts +27 -0
- package/dist/commands/bite.js +556 -0
- package/dist/commands/bite.js.map +1 -0
- package/dist/commands/dashboard.d.ts +2 -0
- package/dist/commands/dashboard.js +503 -0
- package/dist/commands/dashboard.js.map +1 -0
- package/dist/commands/dist.d.ts +7 -0
- package/dist/commands/dist.js +121 -0
- package/dist/commands/dist.js.map +1 -0
- package/dist/commands/fetch.d.ts +11 -0
- package/dist/commands/fetch.js +550 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/fork.d.ts +1 -0
- package/dist/commands/fork.js +164 -0
- package/dist/commands/fork.js.map +1 -0
- package/dist/commands/generate.d.ts +7 -0
- package/dist/commands/generate.js +201 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/genesis-toml.d.ts +1 -0
- package/dist/commands/genesis-toml.js +26 -0
- package/dist/commands/genesis-toml.js.map +1 -0
- package/dist/commands/nginx-conf.d.ts +1 -0
- package/dist/commands/nginx-conf.js +32 -0
- package/dist/commands/nginx-conf.js.map +1 -0
- package/dist/commands/service-context.d.ts +13 -0
- package/dist/commands/service-context.js +5 -0
- package/dist/commands/service-context.js.map +1 -0
- package/dist/commands/service.d.ts +28 -0
- package/dist/commands/service.js +807 -0
- package/dist/commands/service.js.map +1 -0
- package/dist/commands/stamp-spawn.d.ts +7 -0
- package/dist/commands/stamp-spawn.js +43 -0
- package/dist/commands/stamp-spawn.js.map +1 -0
- package/dist/commands/start.d.ts +33 -0
- package/dist/commands/start.js +462 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/upgrade.d.ts +15 -0
- package/dist/commands/upgrade.js +101 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/fork/chains.d.ts +25 -0
- package/dist/fork/chains.js +36 -0
- package/dist/fork/chains.js.map +1 -0
- package/dist/fork/codec.d.ts +36 -0
- package/dist/fork/codec.js +122 -0
- package/dist/fork/codec.js.map +1 -0
- package/dist/fork/manifest.d.ts +13 -0
- package/dist/fork/manifest.js +77 -0
- package/dist/fork/manifest.js.map +1 -0
- package/dist/fork/overrides.d.ts +45 -0
- package/dist/fork/overrides.js +255 -0
- package/dist/fork/overrides.js.map +1 -0
- package/dist/fork/products.d.ts +68 -0
- package/dist/fork/products.js +265 -0
- package/dist/fork/products.js.map +1 -0
- package/dist/fork/rpc.d.ts +25 -0
- package/dist/fork/rpc.js +51 -0
- package/dist/fork/rpc.js.map +1 -0
- package/dist/fork/shared-relay.d.ts +99 -0
- package/dist/fork/shared-relay.js +162 -0
- package/dist/fork/shared-relay.js.map +1 -0
- package/dist/fork/sleep.d.ts +3 -0
- package/dist/fork/sleep.js +2 -0
- package/dist/fork/sleep.js.map +1 -0
- package/dist/fork/validators.d.ts +81 -0
- package/dist/fork/validators.js +170 -0
- package/dist/fork/validators.js.map +1 -0
- package/dist/fork/verify.d.ts +79 -0
- package/dist/fork/verify.js +192 -0
- package/dist/fork/verify.js.map +1 -0
- package/dist/lib/archive.d.ts +8 -0
- package/dist/lib/archive.js +40 -0
- package/dist/lib/archive.js.map +1 -0
- package/dist/lib/fork-bundle-name.d.ts +4 -0
- package/dist/lib/fork-bundle-name.js +20 -0
- package/dist/lib/fork-bundle-name.js.map +1 -0
- package/dist/lib/github.d.ts +48 -0
- package/dist/lib/github.js +192 -0
- package/dist/lib/github.js.map +1 -0
- package/dist/lib/provenance.d.ts +67 -0
- package/dist/lib/provenance.js +98 -0
- package/dist/lib/provenance.js.map +1 -0
- package/dist/lib/spawn-env.d.ts +33 -0
- package/dist/lib/spawn-env.js +71 -0
- package/dist/lib/spawn-env.js.map +1 -0
- package/dist/lib/spawn-stamp.d.ts +34 -0
- package/dist/lib/spawn-stamp.js +63 -0
- package/dist/lib/spawn-stamp.js.map +1 -0
- package/dist/upgrade/chains.d.ts +4 -0
- package/dist/upgrade/chains.js +17 -0
- package/dist/upgrade/chains.js.map +1 -0
- package/dist/upgrade/fund.d.ts +38 -0
- package/dist/upgrade/fund.js +119 -0
- package/dist/upgrade/fund.js.map +1 -0
- package/dist/upgrade/provider-node.d.ts +2 -0
- package/dist/upgrade/provider-node.js +7 -0
- package/dist/upgrade/provider-node.js.map +1 -0
- package/dist/upgrade/signer.d.ts +21 -0
- package/dist/upgrade/signer.js +48 -0
- package/dist/upgrade/signer.js.map +1 -0
- package/dist/upgrade/sudo.d.ts +2 -0
- package/dist/upgrade/sudo.js +26 -0
- package/dist/upgrade/sudo.js.map +1 -0
- package/dist/upgrade/upgrade.d.ts +128 -0
- package/dist/upgrade/upgrade.js +539 -0
- package/dist/upgrade/upgrade.js.map +1 -0
- package/networks/README.md +120 -0
- package/networks/devnet.json +113 -0
- package/networks/kusama.json +56 -0
- package/networks/paseo-next-v2.json +87 -0
- package/networks/polkadot.json +57 -0
- package/networks/previewnet.json +186 -0
- package/package.json +54 -0
- package/scripts/assign-cores.sh +12 -0
- package/scripts/dashboard.sh +11 -0
- package/scripts/docker-entrypoint.sh +52 -0
- package/scripts/dub/postgres.sh +116 -0
- package/scripts/dub/service.sh +202 -0
- package/scripts/ensure-dot-cli.sh +23 -0
- package/scripts/eth-rpc.sh +45 -0
- package/scripts/force-open-hrmp.sh +11 -0
- package/scripts/grant-invites.sh +11 -0
- package/scripts/increase-people-lite-attestation-allowance.sh +11 -0
- package/scripts/install.sh +12 -0
- package/scripts/ipfs-daemon.sh +48 -0
- package/scripts/ipfs-swarm.sh +48 -0
- package/scripts/kill-port.sh +11 -0
- package/scripts/lib/workspace.sh +47 -0
- package/scripts/omni-node.sh +112 -0
- package/scripts/patch-bootnodes.sh +11 -0
- package/scripts/pin-bulletin-products.sh +11 -0
- package/scripts/pin-design-families.sh +144 -0
- package/scripts/set-dispatcher-address.sh +11 -0
- package/scripts/storage-provider-node.sh +11 -0
- package/web/assets/index-BW4b1s2y.js +7 -0
- package/web/assets/index-X3pZpnYk.css +1 -0
- package/web/index.html +13 -0
- package/zombienet-configs/local-dev.toml +253 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface ProvenanceArtifact {
|
|
2
|
+
name: string;
|
|
3
|
+
repo: string;
|
|
4
|
+
/** The descriptor's tag, `latest` included. */
|
|
5
|
+
pinned: string;
|
|
6
|
+
/** What the pin meant when the fetch ran. */
|
|
7
|
+
resolved: string;
|
|
8
|
+
sha256: string;
|
|
9
|
+
/** Executables only: what the artifact says with --version. */
|
|
10
|
+
version?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Provenance {
|
|
13
|
+
fetchedAt: string;
|
|
14
|
+
network: string;
|
|
15
|
+
platform: string;
|
|
16
|
+
/** Node binaries, from the descriptor's per-network pins. */
|
|
17
|
+
binaries: ProvenanceArtifact[];
|
|
18
|
+
runtimes: ProvenanceArtifact[];
|
|
19
|
+
/**
|
|
20
|
+
* Everything else a network runs that is not a chain: the device-uniqueness backend,
|
|
21
|
+
* zombienet, kubo, postgres. Pinned in config/versions.env rather than the descriptor,
|
|
22
|
+
* because they have no per-network dimension — but "which DUB is this?" is still a
|
|
23
|
+
* question about the running network, and until this existed nothing on the box answered it.
|
|
24
|
+
*/
|
|
25
|
+
toolchain: ProvenanceArtifact[];
|
|
26
|
+
}
|
|
27
|
+
export declare const PROVENANCE_FILE = "provenance.json";
|
|
28
|
+
export interface StampInput {
|
|
29
|
+
kind: 'binary' | 'runtime' | 'toolchain';
|
|
30
|
+
name: string;
|
|
31
|
+
repo: string;
|
|
32
|
+
pinned: string;
|
|
33
|
+
resolved: string;
|
|
34
|
+
/** Where the artifact landed. Skipped (with a note) if the download failed. */
|
|
35
|
+
file: string;
|
|
36
|
+
/**
|
|
37
|
+
* A hash already known to be this file's, from `reusable()` deciding the download could be
|
|
38
|
+
* skipped. Hashing 3.7 GB is not free, and without this a skipped artifact would be hashed
|
|
39
|
+
* twice per fetch: once to prove it was current, once to stamp it.
|
|
40
|
+
*/
|
|
41
|
+
sha256?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Write bin/provenance.json. Artifacts whose file is absent are dropped rather than guessed
|
|
45
|
+
* at — a failed download has no provenance, and the fetch already reported it loudly.
|
|
46
|
+
*/
|
|
47
|
+
/** The stamp a previous fetch left in this directory, or null if there is none to read. */
|
|
48
|
+
export declare function readProvenance(binDir: string): Provenance | null;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a file on disk is already the artifact a fetch is about to download — and if so, its
|
|
51
|
+
* hash, so the caller can stamp it without hashing again.
|
|
52
|
+
*
|
|
53
|
+
* The previous stamp is the cache index. It is the right one because it records what a pin
|
|
54
|
+
* *resolved to*, not what it said: a `latest` pin that has moved since the last fetch resolves
|
|
55
|
+
* to a different tag, so the recorded tag no longer matches and the artifact is re-downloaded.
|
|
56
|
+
* Nothing else in the workspace knows that — the file on disk looks identical either way.
|
|
57
|
+
*
|
|
58
|
+
* Three ways this correctly declines to skip:
|
|
59
|
+
* - no previous stamp, or the artifact is not in it -> never fetched here
|
|
60
|
+
* - the resolved tag differs -> the pin moved
|
|
61
|
+
* - the file is missing, or hashes differently -> deleted, truncated, or edited
|
|
62
|
+
*
|
|
63
|
+
* Names are unique across the three groups in practice (polkadot, asset_hub.wasm, dub), so the
|
|
64
|
+
* lookup is by name alone; a collision would only ever cause an unnecessary download.
|
|
65
|
+
*/
|
|
66
|
+
export declare function reusable(prev: Provenance | null, name: string, resolved: string, file: string): string | null;
|
|
67
|
+
export declare function writeProvenance(binDir: string, network: string, inputs: StampInput[]): void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Stamping what a fetch actually downloaded.
|
|
2
|
+
//
|
|
3
|
+
// "Which binaries is this network running?" is a historical fact, not a lookup: a descriptor
|
|
4
|
+
// pinned to `latest` resolves somewhere else next week, so answering from the descriptor at
|
|
5
|
+
// query time silently rewrites history. `ppn fetch` therefore records, next to the binaries
|
|
6
|
+
// themselves, what each pin resolved to and what landed on disk — and the dashboard reads the
|
|
7
|
+
// stamp, never re-resolves.
|
|
8
|
+
//
|
|
9
|
+
// It covers everything the network runs, not only the chains: the shared toolchain (the
|
|
10
|
+
// device-uniqueness backend, zombienet, kubo, postgres) is pinned in config/versions.env
|
|
11
|
+
// rather than in a descriptor, and used to be stamped nowhere at all — so "which DUB is
|
|
12
|
+
// staging running?" had no answer short of ssh and `--version`.
|
|
13
|
+
import crypto from 'node:crypto';
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { spawnSync } from 'node:child_process';
|
|
17
|
+
export const PROVENANCE_FILE = 'provenance.json';
|
|
18
|
+
function sha256(file) {
|
|
19
|
+
return crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
/** `--version`'s first line, or undefined for anything that does not answer. */
|
|
22
|
+
function probeVersion(file) {
|
|
23
|
+
const r = spawnSync(file, ['--version'], { encoding: 'utf-8', timeout: 10_000 });
|
|
24
|
+
const line = (r.stdout || '').split('\n')[0].trim();
|
|
25
|
+
return r.status === 0 && line ? line : undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Write bin/provenance.json. Artifacts whose file is absent are dropped rather than guessed
|
|
29
|
+
* at — a failed download has no provenance, and the fetch already reported it loudly.
|
|
30
|
+
*/
|
|
31
|
+
/** The stamp a previous fetch left in this directory, or null if there is none to read. */
|
|
32
|
+
export function readProvenance(binDir) {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(fs.readFileSync(path.join(binDir, PROVENANCE_FILE), 'utf-8'));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether a file on disk is already the artifact a fetch is about to download — and if so, its
|
|
42
|
+
* hash, so the caller can stamp it without hashing again.
|
|
43
|
+
*
|
|
44
|
+
* The previous stamp is the cache index. It is the right one because it records what a pin
|
|
45
|
+
* *resolved to*, not what it said: a `latest` pin that has moved since the last fetch resolves
|
|
46
|
+
* to a different tag, so the recorded tag no longer matches and the artifact is re-downloaded.
|
|
47
|
+
* Nothing else in the workspace knows that — the file on disk looks identical either way.
|
|
48
|
+
*
|
|
49
|
+
* Three ways this correctly declines to skip:
|
|
50
|
+
* - no previous stamp, or the artifact is not in it -> never fetched here
|
|
51
|
+
* - the resolved tag differs -> the pin moved
|
|
52
|
+
* - the file is missing, or hashes differently -> deleted, truncated, or edited
|
|
53
|
+
*
|
|
54
|
+
* Names are unique across the three groups in practice (polkadot, asset_hub.wasm, dub), so the
|
|
55
|
+
* lookup is by name alone; a collision would only ever cause an unnecessary download.
|
|
56
|
+
*/
|
|
57
|
+
export function reusable(prev, name, resolved, file) {
|
|
58
|
+
if (!prev)
|
|
59
|
+
return null;
|
|
60
|
+
const known = [...(prev.binaries ?? []), ...(prev.runtimes ?? []), ...(prev.toolchain ?? [])]
|
|
61
|
+
.find((a) => a.name === name);
|
|
62
|
+
if (!known || known.resolved !== resolved)
|
|
63
|
+
return null;
|
|
64
|
+
if (!fs.existsSync(file))
|
|
65
|
+
return null;
|
|
66
|
+
const actual = sha256(file);
|
|
67
|
+
return actual === known.sha256 ? actual : null;
|
|
68
|
+
}
|
|
69
|
+
export function writeProvenance(binDir, network, inputs) {
|
|
70
|
+
const entry = (i) => {
|
|
71
|
+
if (!fs.existsSync(i.file))
|
|
72
|
+
return null;
|
|
73
|
+
const base = {
|
|
74
|
+
name: i.name,
|
|
75
|
+
repo: i.repo,
|
|
76
|
+
pinned: i.pinned,
|
|
77
|
+
resolved: i.resolved,
|
|
78
|
+
sha256: i.sha256 ?? sha256(i.file),
|
|
79
|
+
};
|
|
80
|
+
// Runtimes are WASM and answer nothing; the two executable kinds are asked.
|
|
81
|
+
if (i.kind !== 'runtime') {
|
|
82
|
+
const v = probeVersion(i.file);
|
|
83
|
+
if (v)
|
|
84
|
+
base.version = v;
|
|
85
|
+
}
|
|
86
|
+
return base;
|
|
87
|
+
};
|
|
88
|
+
const provenance = {
|
|
89
|
+
fetchedAt: new Date().toISOString(),
|
|
90
|
+
network,
|
|
91
|
+
platform: `${process.platform}-${process.arch}`,
|
|
92
|
+
binaries: inputs.filter((i) => i.kind === 'binary').map(entry).filter((e) => e !== null),
|
|
93
|
+
runtimes: inputs.filter((i) => i.kind === 'runtime').map(entry).filter((e) => e !== null),
|
|
94
|
+
toolchain: inputs.filter((i) => i.kind === 'toolchain').map(entry).filter((e) => e !== null),
|
|
95
|
+
};
|
|
96
|
+
fs.writeFileSync(path.join(binDir, PROVENANCE_FILE), JSON.stringify(provenance, null, 2) + '\n');
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=provenance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provenance.js","sourceRoot":"","sources":["../../src/lib/provenance.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,6FAA6F;AAC7F,4FAA4F;AAC5F,4FAA4F;AAC5F,8FAA8F;AAC9F,4BAA4B;AAC5B,EAAE;AACF,wFAAwF;AACxF,yFAAyF;AACzF,wFAAwF;AACxF,gEAAgE;AAEhE,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA8B/C,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,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,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAA2B,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;QACjH,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAA2B,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;QAClH,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAA2B,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;KACtH,CAAC;IACF,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Facts config/ports.local.env states for zombienet's custom processes. */
|
|
2
|
+
export interface LocalEnvFacts {
|
|
3
|
+
/** The network this run resolved to, so every service resolves the same one. */
|
|
4
|
+
network: string;
|
|
5
|
+
/** The data dir this run writes to — per-mode (data/ vs data-fork/). */
|
|
6
|
+
dataDir: string;
|
|
7
|
+
ephemeral: boolean;
|
|
8
|
+
/** Where the identity postgres cluster keeps its data. */
|
|
9
|
+
identityDataDir: string;
|
|
10
|
+
}
|
|
11
|
+
/** The gitignored file `ppn start` writes; every service overlays it on top of ports.env. */
|
|
12
|
+
export declare function localEnvContent(f: LocalEnvFacts): string;
|
|
13
|
+
/** Facts `ppn start` puts into zombie-cli's environment (inherited by node-level procs). */
|
|
14
|
+
export interface ChildEnvFacts {
|
|
15
|
+
binDir: string;
|
|
16
|
+
/** The workspace this run resolved to, so the launchers do not resolve it again. */
|
|
17
|
+
workspace: string;
|
|
18
|
+
scriptsDir: string;
|
|
19
|
+
dataDir: string;
|
|
20
|
+
ephemeral: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function childEnv(f: ChildEnvFacts): Record<string, string>;
|
|
23
|
+
/** Keys `ppn start` writes into config/ports.local.env, derived from the real writer. */
|
|
24
|
+
export declare function localEnvKeys(): string[];
|
|
25
|
+
/** Keys `ppn start` puts into zombie-cli's environment, derived from the real builder. */
|
|
26
|
+
export declare function childEnvKeys(): string[];
|
|
27
|
+
/** Every key a spawn receives through `ppn start`, deduplicated. */
|
|
28
|
+
export declare function spawnEnvKeys(): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Keys the server path deliberately does not supply. Each needs a reason, and the reason has
|
|
31
|
+
* to be about the *server*, not about effort.
|
|
32
|
+
*/
|
|
33
|
+
export declare const WAIVED: Record<string, string>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The spawn environment `ppn start` states, in one place.
|
|
2
|
+
//
|
|
3
|
+
// zombienet forwards no environment to custom processes, so everything the dashboard,
|
|
4
|
+
// eth-rpc, the dub stack and the storage provider cannot derive has to be *stated*.
|
|
5
|
+
// `ppn start` states it twice: config/ports.local.env (read by custom processes) and
|
|
6
|
+
// zombie-cli's child environment (inherited by node-level processes). A server never runs
|
|
7
|
+
// `ppn start` — ppn.service spawns zombie-cli directly — so the same facts are restated by
|
|
8
|
+
// hand across server/redeploy.sh, server/systemd/ppn.service and /etc/ppn/deploy.env.
|
|
9
|
+
//
|
|
10
|
+
// This module is the canonical statement: `ppn start` builds its real environment from the
|
|
11
|
+
// builders below, and the key lists are derived from those same builders — so the list the
|
|
12
|
+
// server-side conformance test (server/tests/spawn-env-conformance.test.mjs) checks against
|
|
13
|
+
// cannot drift from what the code actually does.
|
|
14
|
+
/** The gitignored file `ppn start` writes; every service overlays it on top of ports.env. */
|
|
15
|
+
export function localEnvContent(f) {
|
|
16
|
+
return ('# Generated by `ppn start` — gitignored, do not edit.\n' +
|
|
17
|
+
`WEB3_STORAGE_PROVIDER_STORAGE_MODE=${f.ephemeral ? 'inmemory' : 'disk'}\n` +
|
|
18
|
+
`DUB_POSTGRES_DATA_DIR=${f.identityDataDir}\n` +
|
|
19
|
+
`PPN_NETWORK=${f.network}\n` +
|
|
20
|
+
// zombienet forwards no env to custom processes, and the data dir is per-mode
|
|
21
|
+
// (data/ vs data-fork/): without this the dashboard reads the *other* mode's
|
|
22
|
+
// spawn stamp and logs — a fork reporting itself as yesterday's genesis.
|
|
23
|
+
`PPN_DATA_DIR=${f.dataDir}\n`);
|
|
24
|
+
}
|
|
25
|
+
export function childEnv(f) {
|
|
26
|
+
return {
|
|
27
|
+
BIN: f.binDir,
|
|
28
|
+
// zombienet forwards node-level env but gives custom processes no HOME, which is the
|
|
29
|
+
// one thing the shell fallback would need — so the resolved workspace travels here.
|
|
30
|
+
PPN_HOME: f.workspace,
|
|
31
|
+
SCRIPTS: f.scriptsDir,
|
|
32
|
+
DATA_DIR: f.dataDir,
|
|
33
|
+
EPHEMERAL: f.ephemeral ? '1' : '',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const DUMMY_LOCAL = { network: 'x', dataDir: 'x', ephemeral: false, identityDataDir: 'x' };
|
|
37
|
+
const DUMMY_CHILD = { binDir: 'x', workspace: 'x', scriptsDir: 'x', dataDir: 'x', ephemeral: false };
|
|
38
|
+
/** Keys `ppn start` writes into config/ports.local.env, derived from the real writer. */
|
|
39
|
+
export function localEnvKeys() {
|
|
40
|
+
return [...localEnvContent(DUMMY_LOCAL).matchAll(/^([A-Z_][A-Z0-9_]*)=/gm)].map((m) => m[1]);
|
|
41
|
+
}
|
|
42
|
+
/** Keys `ppn start` puts into zombie-cli's environment, derived from the real builder. */
|
|
43
|
+
export function childEnvKeys() {
|
|
44
|
+
return Object.keys(childEnv(DUMMY_CHILD));
|
|
45
|
+
}
|
|
46
|
+
/** Every key a spawn receives through `ppn start`, deduplicated. */
|
|
47
|
+
export function spawnEnvKeys() {
|
|
48
|
+
return [...new Set([...localEnvKeys(), ...childEnvKeys()])];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Keys the server path deliberately does not supply. Each needs a reason, and the reason has
|
|
52
|
+
* to be about the *server*, not about effort.
|
|
53
|
+
*/
|
|
54
|
+
export const WAIVED = {
|
|
55
|
+
// A server persists by definition; ephemeral is a laptop mode. Nothing reads it there.
|
|
56
|
+
EPHEMERAL: 'ephemeral is a local-only mode; a deployment always persists',
|
|
57
|
+
// KNOWN GAP, deliberately recorded rather than silently waived.
|
|
58
|
+
//
|
|
59
|
+
// `ppn start` sets it so every service resolves the network the user asked for.
|
|
60
|
+
// On a server nothing sets it, and currentNetworkName() (network-config/src/networks.ts)
|
|
61
|
+
// falls back to previewnet. Staging and prod run previewnet, so this is *accidentally*
|
|
62
|
+
// correct today and breaks nothing — but the first non-previewnet deployment would have
|
|
63
|
+
// every service resolve previewnet's chains, ports and bin directory instead.
|
|
64
|
+
//
|
|
65
|
+
// Not fixed here because the fix belongs with `ppn start --server` (see docs/DASHBOARD.md,
|
|
66
|
+
// "Why a server does not run `ppn start`"), which makes one path the sole author of all of
|
|
67
|
+
// this. Until then it is written down, and the conformance test keeps it from being
|
|
68
|
+
// forgotten.
|
|
69
|
+
PPN_NETWORK: 'KNOWN GAP: falls back to previewnet, which is what servers run today',
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=spawn-env.js.map
|
|
@@ -0,0 +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,qFAAq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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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const SPAWN_FILE = "spawn.json";
|
|
2
|
+
export interface Bite {
|
|
3
|
+
at: string;
|
|
4
|
+
source: string;
|
|
5
|
+
blocks: Record<string, number>;
|
|
6
|
+
}
|
|
7
|
+
export interface SpawnStamp {
|
|
8
|
+
spawnedAt: string;
|
|
9
|
+
network: string;
|
|
10
|
+
mode: 'genesis' | 'fork';
|
|
11
|
+
/** Fork mode only: which live network this continues from, and at which blocks. */
|
|
12
|
+
bite: Bite | null;
|
|
13
|
+
profile: string;
|
|
14
|
+
/** Absent in a checkout, which has no packed release to name. */
|
|
15
|
+
ppnVersion?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface StampSpawnInput {
|
|
18
|
+
network: string;
|
|
19
|
+
mode: 'genesis' | 'fork';
|
|
20
|
+
/**
|
|
21
|
+
* The fork bundle's manifest, when this is a fork. Passed in rather than resolved here:
|
|
22
|
+
* where a bundle lives is `ppn start`'s decision, and this module stays free of it.
|
|
23
|
+
*/
|
|
24
|
+
forkManifest?: string | null;
|
|
25
|
+
/** Repo/release root, for the packed version. A checkout simply has no manifest there. */
|
|
26
|
+
repoRoot: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Write `<dataDir>/spawn.json` and return what was written.
|
|
30
|
+
*
|
|
31
|
+
* The directory is created if absent: on a server the stamp is written just before the
|
|
32
|
+
* service starts, which may be the first thing to touch a freshly wiped DATA_DIR.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeSpawnStamp(dataDir: string, input: StampSpawnInput): SpawnStamp;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Stamping what a spawn actually was.
|
|
2
|
+
//
|
|
3
|
+
// The sibling of lib/provenance.ts, split by lifetime: provenance records what `ppn fetch`
|
|
4
|
+
// downloaded and lives in bin/, this records how one network was brought up and lives beside
|
|
5
|
+
// the chain state it describes. Both exist because they are historical facts, not lookups —
|
|
6
|
+
// `mode` and `bite` cannot be re-derived once a bundle moves on, so they are written at the
|
|
7
|
+
// moment they are true.
|
|
8
|
+
//
|
|
9
|
+
// One writer, called by every path that spawns. There used to be exactly one such path
|
|
10
|
+
// (`ppn start`), so this logic sat inside it — and a server, which spawns zombie-cli straight
|
|
11
|
+
// from ppn.service, wrote no stamp at all. Its dashboard then had no spawn time, no profile
|
|
12
|
+
// and no PPN version to show. Adding a second caller to the same writer is the point: a field
|
|
13
|
+
// added here cannot reach one path and silently miss the other.
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
export const SPAWN_FILE = 'spawn.json';
|
|
17
|
+
/** The bite fields a manifest contributes, or null when there is no usable manifest. */
|
|
18
|
+
function biteFrom(manifest) {
|
|
19
|
+
if (!manifest || !fs.existsSync(manifest))
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const m = JSON.parse(fs.readFileSync(manifest, 'utf-8'));
|
|
23
|
+
return { at: m.bittenAt, source: m.source, blocks: m.biteBlocks };
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// A half-written manifest is not worth failing a spawn over; the mode still says `fork`.
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function packedVersion(repoRoot) {
|
|
31
|
+
const dist = path.join(repoRoot, '.ppn-dist.json');
|
|
32
|
+
if (!fs.existsSync(dist))
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(fs.readFileSync(dist, 'utf-8')).version;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Write `<dataDir>/spawn.json` and return what was written.
|
|
43
|
+
*
|
|
44
|
+
* The directory is created if absent: on a server the stamp is written just before the
|
|
45
|
+
* service starts, which may be the first thing to touch a freshly wiped DATA_DIR.
|
|
46
|
+
*/
|
|
47
|
+
export function writeSpawnStamp(dataDir, input) {
|
|
48
|
+
const version = packedVersion(input.repoRoot);
|
|
49
|
+
const stamp = {
|
|
50
|
+
spawnedAt: new Date().toISOString(),
|
|
51
|
+
network: input.network,
|
|
52
|
+
mode: input.mode,
|
|
53
|
+
bite: input.mode === 'fork' ? biteFrom(input.forkManifest) : null,
|
|
54
|
+
profile: process.env.PPN_PROFILE || 'local',
|
|
55
|
+
// Set only when there is one: an own `ppnVersion: undefined` would survive in the
|
|
56
|
+
// returned object but not in the JSON, so the return would not equal what was written.
|
|
57
|
+
...(version ? { ppnVersion: version } : {}),
|
|
58
|
+
};
|
|
59
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
60
|
+
fs.writeFileSync(path.join(dataDir, SPAWN_FILE), JSON.stringify(stamp, null, 2) + '\n');
|
|
61
|
+
return stamp;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=spawn-stamp.js.map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CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAsB;IACrE,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAe;QACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI;QACjE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO;QAC3C,kFAAkF;QAClF,uFAAuF;QACvF,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC;IACF,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACxF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Which chain does a runtime upgrade target, and where does it listen locally?
|
|
2
|
+
//
|
|
3
|
+
// Ports come from the same table the zombienet configs are generated from
|
|
4
|
+
// (toml-generator reads config/ports.env), so an upgrade can never be aimed at a port
|
|
5
|
+
// nothing was told to listen on. Chain keys match the spawner's runtime-upload keys.
|
|
6
|
+
import { PORTS, RELAY_BASE_PORT, VALID_PARACHAINS } from '@parity/ppn-network-config';
|
|
7
|
+
export const UPGRADE_CHAINS = ['relay', ...VALID_PARACHAINS];
|
|
8
|
+
/** Default WS endpoint of a chain on a locally running network. */
|
|
9
|
+
export function localWsUrl(chain) {
|
|
10
|
+
if (chain === 'relay')
|
|
11
|
+
return `ws://127.0.0.1:${RELAY_BASE_PORT}`;
|
|
12
|
+
if (VALID_PARACHAINS.includes(chain)) {
|
|
13
|
+
return `ws://127.0.0.1:${PORTS[chain]}`;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`unknown chain "${chain}" — expected one of: ${UPGRADE_CHAINS.join(', ')}`);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=chains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../../src/upgrade/chains.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,0EAA0E;AAC1E,sFAAsF;AACtF,qFAAqF;AAErF,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGtF,MAAM,CAAC,MAAM,cAAc,GAAe,CAAC,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC;AAEzE,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,kBAAkB,eAAe,EAAE,CAAC;IAClE,IAAK,gBAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,OAAO,kBAAkB,KAAK,CAAC,KAAkB,CAAC,EAAE,CAAC;IACvD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,wBAAwB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createClient } from 'polkadot-api';
|
|
2
|
+
import { type SudoSigner } from './signer.js';
|
|
3
|
+
type Provider = Parameters<typeof createClient>[0];
|
|
4
|
+
/**
|
|
5
|
+
* Below this free balance the account cannot be trusted to pay upgrade fees: 1000 PAS.
|
|
6
|
+
* Two bars hide in here. The obvious one is the existential deposit — 1 PAS on the
|
|
7
|
+
* paseo relay (mirroring Polkadot), and production's relay Alice sits at exactly that,
|
|
8
|
+
* unable to pay for anything. The real one is the apply step: apply_authorized_upgrade
|
|
9
|
+
* carries the entire runtime as a signed extrinsic, and at Polkadot-scale byte fees a
|
|
10
|
+
* ~2 MB blob costs on the order of 200 PAS in length fee alone.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MIN_FREE = 10000000000000n;
|
|
13
|
+
/** What a top-up transfers. 10k PAS — pocket change next to a dev account's 1M. */
|
|
14
|
+
export declare const TOP_UP = 100000000000000n;
|
|
15
|
+
/**
|
|
16
|
+
* Well-known dev accounts to draw the top-up from, in the order previewnet is likely
|
|
17
|
+
* to have left them untouched. Alice herself is deliberately absent — she is the one
|
|
18
|
+
* being funded.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DONOR_URIS: string[];
|
|
21
|
+
export interface EnsureFundsOptions {
|
|
22
|
+
provider: Provider;
|
|
23
|
+
wsUrl: string;
|
|
24
|
+
/** The account that must be able to pay — the sudo signer. Defaults to //Alice. */
|
|
25
|
+
sudo?: SudoSigner;
|
|
26
|
+
minFree?: bigint;
|
|
27
|
+
topUp?: bigint;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
log?: (msg: string) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Make sure the sudo account can pay fees on the chain, transferring a top-up from the
|
|
33
|
+
* first funded well-known dev account when it cannot. A no-op when already funded —
|
|
34
|
+
* genesis networks and deployable profiles (whose operator key is funded, and whose dev
|
|
35
|
+
* accounts are stripped) never reach the transfer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ensureFunds(opts: EnsureFundsOptions): Promise<bigint>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Make sure the sudo account can pay fees, topping it up from a well-known dev account.
|
|
2
|
+
//
|
|
3
|
+
// A fork makes //Alice sudo everywhere (the bite overrides Sudo::Key), but on the
|
|
4
|
+
// production relay Alice has been spent down to exactly the existential deposit — and
|
|
5
|
+
// an account at ED cannot pay for anything: any withdrawal would reap it, so the tx
|
|
6
|
+
// pool rejects with Invalid::Payment before the upgrade logic runs.
|
|
7
|
+
//
|
|
8
|
+
// Why a transfer and not something else: teleporting from Asset Hub bounces off the
|
|
9
|
+
// vanilla paseo relay runtime — para 1500 is not among its trusted teleport locations
|
|
10
|
+
// (`UntrustedTeleportLocation`). A bite-time System.Account inject also works (verified
|
|
11
|
+
// on-chain), but it only helps bundles bitten after the fix — this transfer funds the
|
|
12
|
+
// sudo on ANY bundle, published ones included. Previewnet's relay genesis endows every
|
|
13
|
+
// other dev account with 1M PAS, so a plain transfer_keep_alive from the first funded
|
|
14
|
+
// donor settles it in one block, on the same chain, with keys everyone has.
|
|
15
|
+
//
|
|
16
|
+
// Browser-clean like upgrade.ts: no node: imports, provider injected by the caller.
|
|
17
|
+
import { createClient } from 'polkadot-api';
|
|
18
|
+
import { TX_OPTIONS } from './upgrade.js';
|
|
19
|
+
import { signerFromUri } from './signer.js';
|
|
20
|
+
/**
|
|
21
|
+
* Below this free balance the account cannot be trusted to pay upgrade fees: 1000 PAS.
|
|
22
|
+
* Two bars hide in here. The obvious one is the existential deposit — 1 PAS on the
|
|
23
|
+
* paseo relay (mirroring Polkadot), and production's relay Alice sits at exactly that,
|
|
24
|
+
* unable to pay for anything. The real one is the apply step: apply_authorized_upgrade
|
|
25
|
+
* carries the entire runtime as a signed extrinsic, and at Polkadot-scale byte fees a
|
|
26
|
+
* ~2 MB blob costs on the order of 200 PAS in length fee alone.
|
|
27
|
+
*/
|
|
28
|
+
export const MIN_FREE = 10000000000000n;
|
|
29
|
+
/** What a top-up transfers. 10k PAS — pocket change next to a dev account's 1M. */
|
|
30
|
+
export const TOP_UP = 100000000000000n;
|
|
31
|
+
/**
|
|
32
|
+
* Well-known dev accounts to draw the top-up from, in the order previewnet is likely
|
|
33
|
+
* to have left them untouched. Alice herself is deliberately absent — she is the one
|
|
34
|
+
* being funded.
|
|
35
|
+
*/
|
|
36
|
+
export const DONOR_URIS = [
|
|
37
|
+
'//Bob',
|
|
38
|
+
'//Charlie',
|
|
39
|
+
'//Dave',
|
|
40
|
+
'//Eve',
|
|
41
|
+
'//Ferdie',
|
|
42
|
+
'//Alice//stash',
|
|
43
|
+
'//Bob//stash',
|
|
44
|
+
];
|
|
45
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
46
|
+
/**
|
|
47
|
+
* Make sure the sudo account can pay fees on the chain, transferring a top-up from the
|
|
48
|
+
* first funded well-known dev account when it cannot. A no-op when already funded —
|
|
49
|
+
* genesis networks and deployable profiles (whose operator key is funded, and whose dev
|
|
50
|
+
* accounts are stripped) never reach the transfer.
|
|
51
|
+
*/
|
|
52
|
+
export async function ensureFunds(opts) {
|
|
53
|
+
const log = opts.log ?? (() => { });
|
|
54
|
+
const minFree = opts.minFree ?? MIN_FREE;
|
|
55
|
+
const topUp = opts.topUp ?? TOP_UP;
|
|
56
|
+
const sudo = opts.sudo ?? signerFromUri('//Alice');
|
|
57
|
+
const address = sudo.address();
|
|
58
|
+
const client = createClient(opts.provider);
|
|
59
|
+
try {
|
|
60
|
+
const api = client.getUnsafeApi();
|
|
61
|
+
const free = async (who) => {
|
|
62
|
+
const account = (await api.query.System.Account.getValue(who));
|
|
63
|
+
return account?.data?.free ?? 0n;
|
|
64
|
+
};
|
|
65
|
+
const before = await free(address);
|
|
66
|
+
if (before >= minFree)
|
|
67
|
+
return before;
|
|
68
|
+
let donor = null;
|
|
69
|
+
for (const uri of DONOR_URIS) {
|
|
70
|
+
const candidate = signerFromUri(uri);
|
|
71
|
+
if (candidate.address() === address)
|
|
72
|
+
continue;
|
|
73
|
+
if ((await free(candidate.address())) >= topUp * 2n) {
|
|
74
|
+
donor = candidate;
|
|
75
|
+
log(`sudo account holds ${before} — transferring ${topUp} from ${uri}`);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!donor) {
|
|
80
|
+
throw new Error(`the sudo account (${address}) holds ${before}, below the ${minFree} needed to pay ` +
|
|
81
|
+
'fees, and no well-known dev account on this chain can top it up — fund it manually');
|
|
82
|
+
}
|
|
83
|
+
const tx = api.tx.Balances.transfer_keep_alive({
|
|
84
|
+
dest: { type: 'Id', value: address },
|
|
85
|
+
value: topUp,
|
|
86
|
+
});
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
const sub = tx.signSubmitAndWatch(donor.signer, TX_OPTIONS).subscribe({
|
|
89
|
+
next: (ev) => {
|
|
90
|
+
if (ev.type !== 'finalized')
|
|
91
|
+
return;
|
|
92
|
+
if (ev.ok)
|
|
93
|
+
resolve();
|
|
94
|
+
else
|
|
95
|
+
reject(new Error(`top-up transfer failed: ${JSON.stringify(ev.dispatchError)}`));
|
|
96
|
+
sub.unsubscribe?.();
|
|
97
|
+
},
|
|
98
|
+
error: (err) => reject(new Error(`top-up transfer failed: ${err.message}`)),
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
// Finalization already implies the balance moved; the poll only covers RPC lag.
|
|
102
|
+
const deadline = Date.now() + (opts.timeoutMs ?? 60_000);
|
|
103
|
+
for (;;) {
|
|
104
|
+
const now = await free(address);
|
|
105
|
+
if (now >= minFree) {
|
|
106
|
+
log(`sudo account funded: ${now}`);
|
|
107
|
+
return now;
|
|
108
|
+
}
|
|
109
|
+
if (Date.now() > deadline) {
|
|
110
|
+
throw new Error(`top-up finalized but ${address} still holds ${now} on ${opts.wsUrl}`);
|
|
111
|
+
}
|
|
112
|
+
await sleep(2_000);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
client.destroy();
|
|
117
|
+
}
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AAG,QAAQ,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,gBAAgB,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YACzF,CAAC;YACD,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The Node-side WS provider, kept out of upgrade.ts so that module stays browser-clean
|
|
2
|
+
// (a browser bundle would use polkadot-api/ws-provider/web instead).
|
|
3
|
+
import { getWsProvider } from 'polkadot-api/ws-provider/node';
|
|
4
|
+
export function wsProvider(url) {
|
|
5
|
+
return getWsProvider(url);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=provider-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-node.js","sourceRoot":"","sources":["../../src/upgrade/provider-node.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,qEAAqE;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type PolkadotSigner } from 'polkadot-api/signer';
|
|
2
|
+
export interface ParsedSuri {
|
|
3
|
+
/** Mnemonic phrase or 0x-prefixed 32-byte seed; '' means the dev phrase. */
|
|
4
|
+
phrase: string;
|
|
5
|
+
/** Derivation junctions, e.g. '//Alice' or '//op/soft', possibly ''. */
|
|
6
|
+
paths: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Split a secret URI into phrase, junctions and password:
|
|
11
|
+
* `[phrase | 0xseed] [//hard[/soft]...] [///password]`.
|
|
12
|
+
* hdkd-helpers' own parseSuri refuses a URI without a phrase, which is exactly the
|
|
13
|
+
* common case here (//Alice), hence this one.
|
|
14
|
+
*/
|
|
15
|
+
export declare function splitSuri(uri: string): ParsedSuri;
|
|
16
|
+
export interface SudoSigner {
|
|
17
|
+
signer: PolkadotSigner;
|
|
18
|
+
publicKey: Uint8Array;
|
|
19
|
+
address: (ss58Prefix?: number) => string;
|
|
20
|
+
}
|
|
21
|
+
export declare function signerFromUri(uri: string): SudoSigner;
|