Skip to content

Commit 228fcba

Browse files
ralyodioclaude
andauthored
No single point of failure for status, node board or bootstrap (#59)
* feat: no single point of failure for status, node board or bootstrap c0mpute.com/status, /nodes, the home count and new-node bootstrap all hung off one unsupervised aggregator process in the dev2 web container and one seed on dev2, with no compiled-in seeds. - A second seed + status aggregator now runs on vienna (netcup, p2p 46339, read-only status on :8091). - The site reads every aggregator in STATUS_AGGREGATOR_URLS in parallel and uses the one that sees the most workers; the in-container aggregator is restarted when it exits (backoff 2 s..60 s). - Both seeds are compiled in (bootstrap::DEFAULT_SEEDS) for the worker and the aggregator, and /bootstrap.json serves them when its env var is empty. - The worker treats a user-level infernet.service as managing the daemon (infernet v0.1.62 installs one), so the two never start rival daemons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(worker): reap leaked infernet daemons from the installer's git checkout too bbs ran a bun daemon from ~/.infernet/source for a week next to infernet.service; the reaper only matched the npm path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: v0.2.33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 17a90d7 commit 228fcba

17 files changed

Lines changed: 176 additions & 79 deletions

File tree

‎.nixpacks/Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ RUN chmod +x /usr/local/bin/railway-web-start.sh
5252
# The aggregator serves its JSON on loopback; the site reads it there.
5353
ENV C0MPUTE_STATUS_BIND=127.0.0.1:8090
5454
ENV STATUS_AGGREGATOR_URL=http://127.0.0.1:8090
55+
# Every aggregator the site reads (lib/aggregators.ts): this container's own plus the vienna seed's.
56+
ENV STATUS_AGGREGATOR_URLS=http://127.0.0.1:8090,http://152.53.47.37:8091
5557

5658
# Runs as root, exactly as the Railway image built from Dockerfile.web does (semgrep
5759
# never scanned that file: its name is not a Dockerfile pattern). Moving to a

‎Cargo.lock‎

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ members = [
2323
]
2424

2525
[workspace.package]
26-
version = "0.2.32"
26+
version = "0.2.33"
2727
edition = "2024"
2828
license = "MIT"
2929
repository = "https://github.com/profullstack/c0mpute"

‎Dockerfile.web‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ RUN chmod +x /usr/local/bin/railway-web-start.sh
4747
# The aggregator serves its JSON on loopback; the site reads it there.
4848
ENV C0MPUTE_STATUS_BIND=127.0.0.1:8090
4949
ENV STATUS_AGGREGATOR_URL=http://127.0.0.1:8090
50+
# Every aggregator the site reads (lib/aggregators.ts): this container's own plus the vienna seed's.
51+
ENV STATUS_AGGREGATOR_URLS=http://127.0.0.1:8090,http://152.53.47.37:8091
5052

5153
ENTRYPOINT ["/usr/local/bin/railway-web-start.sh"]

‎apps/tui/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@c0mpute/tui",
3-
"version": "0.2.32",
3+
"version": "0.2.33",
44
"private": true,
55
"type": "module",
66
"bin": {

‎apps/web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "c0mpute",
3-
"version": "0.2.32",
3+
"version": "0.2.33",
44
"private": true,
55
"type": "module",
66
"scripts": {

‎apps/web/src/app/bootstrap.json/route.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* The peer list comes from the `BOOTSTRAP_PEERS_JSON` env var — a JSON array of
77
* `{ id, addrs, operator?, region? }` objects — so seeds can be added, rotated,
88
* or removed by editing an env var, with no code deploy (per DIP-0010: "so we
9-
* can update it without a binary release"). Unset/malformed → an empty list,
10-
* which is a valid file: nodes then fall back to their hardcoded list + mDNS
11-
* rather than seeing a 404.
9+
* can update it without a binary release"). Unset/malformed/empty → the
10+
* built-in DEFAULT_PEERS (our two seeds), never an empty list.
1211
*
1312
* Shape mirrors `node/crates/c0mpute-net/src/bootstrap.rs::BootstrapFile`.
1413
*/
@@ -27,8 +26,29 @@ interface BootstrapPeer {
2726
region?: string;
2827
}
2928

29+
// Used when BOOTSTRAP_PEERS_JSON is unset or unusable, so a missing env var can
30+
// never empty the list. Mirrors DEFAULT_SEEDS in c0mpute-net/src/bootstrap.rs.
31+
const DEFAULT_PEERS: BootstrapPeer[] = [
32+
{
33+
id: "12D3KooWADm5FfNxzPRanv1vacpPD7eh1bWv6pqmDCGE69Zof2n6",
34+
addrs: ["/ip4/23.95.228.174/tcp/46337"],
35+
operator: "profullstack",
36+
region: "us-east",
37+
},
38+
{
39+
id: "12D3KooWN99F7k4Fj6SdUqZ2VG4ZBLuw1e1ftwdPDBx3GsiDXzqv",
40+
addrs: ["/ip4/152.53.47.37/tcp/46339"],
41+
operator: "profullstack",
42+
region: "eu-central",
43+
},
44+
];
45+
3046
function loadPeers(): BootstrapPeer[] {
31-
const raw = process.env.BOOTSTRAP_PEERS_JSON;
47+
const peers = parsePeers(process.env.BOOTSTRAP_PEERS_JSON);
48+
return peers.length > 0 ? peers : DEFAULT_PEERS;
49+
}
50+
51+
function parsePeers(raw: string | undefined): BootstrapPeer[] {
3252
if (!raw) return [];
3353
try {
3454
const parsed = JSON.parse(raw);

‎apps/web/src/app/releases/latest.json/route.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const dynamic = "force-dynamic";
2828
* this in sync with the workspace version in `Cargo.toml` on each release so a
2929
* freshly built CLI reports "already latest" rather than a phantom upgrade.
3030
*/
31-
const FALLBACK_VERSION = "0.2.32";
31+
const FALLBACK_VERSION = "0.2.33";
3232
const FALLBACK_MIN_REQUIRED = "0.0.1";
3333

3434
type Channel = "stable" | "beta" | "nightly";

‎apps/web/src/lib/aggregators.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* The status aggregators this site reads (DIP-0014). Anyone can run one, and
3+
* each sees the network from its own seat, so the site asks every configured
4+
* aggregator at once and uses the answer that sees the most workers. One
5+
* aggregator down (or restarting) then changes nothing on /status or /nodes.
6+
*
7+
* STATUS_AGGREGATOR_URLS is a comma list; STATUS_AGGREGATOR_URL (one URL) is
8+
* still read for older deploys.
9+
*/
10+
export function aggregatorUrls(): string[] {
11+
const raw = [process.env.STATUS_AGGREGATOR_URLS, process.env.STATUS_AGGREGATOR_URL]
12+
.filter(Boolean)
13+
.join(",");
14+
const urls = raw
15+
.split(",")
16+
.map((u) => u.trim().replace(/\/+$/, ""))
17+
.filter((u) => /^https?:\/\//.test(u));
18+
return [...new Set(urls)];
19+
}
20+
21+
/**
22+
* GET `path` from every aggregator in parallel (2 s each) and return the JSON
23+
* body with the highest `workers_online`, or null when none answered.
24+
*/
25+
export async function fetchFromAggregators<T extends { workers_online?: number; network?: { workers_online?: number } }>(
26+
path: string,
27+
opts: { revalidate?: number } = {},
28+
urls: string[] = aggregatorUrls(),
29+
): Promise<T | null> {
30+
if (urls.length === 0) return null;
31+
const answers: (T | null)[] = await Promise.all(
32+
urls.map(async (base): Promise<T | null> => {
33+
try {
34+
const r = await fetch(`${base}${path}`, {
35+
signal: AbortSignal.timeout(2_000),
36+
...(opts.revalidate
37+
? { next: { revalidate: opts.revalidate } }
38+
: { cache: "no-store" as const }),
39+
});
40+
return r.ok ? ((await r.json()) as T) : null;
41+
} catch {
42+
return null;
43+
}
44+
}),
45+
);
46+
const seen = (a: T) => a.workers_online ?? a.network?.workers_online ?? 0;
47+
return answers
48+
.filter((a): a is T => a !== null)
49+
.reduce<T | null>((best, a) => (best === null || seen(a) > seen(best) ? a : best), null);
50+
}

‎apps/web/src/lib/nodes.ts‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "server-only";
2+
import { fetchFromAggregators } from "./aggregators";
23

34
/** One row of the public node board, as served by the aggregator's `GET /nodes`. */
45
export interface NodeRow {
@@ -22,23 +23,9 @@ export interface NodesPayload {
2223
/** The mission number. A goal, not a count. */
2324
export const NODE_GOAL = 100_000;
2425

25-
const AGGREGATOR_URL = process.env.STATUS_AGGREGATOR_URL ?? null;
26-
2726
export async function getNodesPayload(): Promise<NodesPayload> {
28-
if (AGGREGATOR_URL) {
29-
try {
30-
const r = await fetch(`${AGGREGATOR_URL.replace(/\/$/, "")}/nodes`, {
31-
signal: AbortSignal.timeout(2_000),
32-
cache: "no-store",
33-
});
34-
if (r.ok) {
35-
const data = (await r.json()) as Omit<NodesPayload, "source">;
36-
return { ...data, source: "aggregator" };
37-
}
38-
} catch {
39-
// fall through
40-
}
41-
}
27+
const data = await fetchFromAggregators<Omit<NodesPayload, "source">>("/nodes");
28+
if (data) return { ...data, source: "aggregator" };
4229
return {
4330
generated_at: new Date().toISOString(),
4431
workers_online: 0,

0 commit comments

Comments
 (0)