From 5857532825a67d32413caa7f339140f120034926 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sat, 14 Nov 2026 03:18:33 +0000 Subject: [PATCH] feat(nodes): per-node jobs by type, run time, earnings vs est. power on /nodes The status aggregator already correlated JobAccept -> JobReceipt but only network-wide. It now remembers the accepted winner and agreed price, credits a completed job to that node only when the receipt comes from the same peer, and GET /nodes carries jobs_24h {jobs, busy_s, paid_usd, by_type} per row. Prices are capped and non-finite ones credited as 0, since anyone can gossip an accept. c0mpute.com/nodes shows a network table by job type (jobs, nodes, avg run time, avg price, what the node keeps per job and per busy hour) and per-node columns: jobs 24h with top types, busy time, earned after the 5% fee, estimated power cost and net. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/app/nodes/page.tsx | 144 +++++++++++++++++- apps/web/src/lib/nodes.ts | 81 ++++++++++ .../c0mpute-core/src/status_aggregator.rs | 120 +++++++++++++++ 3 files changed, 341 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/nodes/page.tsx b/apps/web/src/app/nodes/page.tsx index 552b1b8e..7bb16a92 100644 --- a/apps/web/src/app/nodes/page.tsx +++ b/apps/web/src/app/nodes/page.tsx @@ -1,10 +1,21 @@ import Link from "next/link"; import { CodeBlock } from "@/components/CodeBlock"; -import { getNodesPayload, NODE_GOAL } from "@/lib/nodes"; +import { + BUSY_WATTS, + duration, + getNodesPayload, + NODE_GOAL, + operatorEarnings, + POWER_USD_PER_KWH, + powerCostUsd, + summarizeByType, + usd, +} from "@/lib/nodes"; +import { MARKET_FEE_PCT } from "@/lib/market"; import { pageOg } from "@/lib/og"; const DESCRIPTION = - "Every c0mpute node online right now, ranked by its c0mpute bench score, with who runs each one and who invited them. How to name your node. The goal is 100,000 nodes."; + "Every c0mpute node online right now: jobs each one ran in the last 24 hours by type, how long they took, what they earned against the power they used, who runs each node and who invited them. The goal is 100,000 nodes."; export const metadata = { title: "nodes — c0mpute", @@ -17,6 +28,26 @@ export const metadata = { // loopback call over in-memory state. export const dynamic = "force-dynamic"; +/** Short label for a workload type: "infernet.inference" -> "inference". */ +function jobLabel(t: string): string { + const known: Record = { + "infernet.inference": "chat / inference", + "tts.synthesize": "text to speech", + "stt.transcribe": "speech to text", + "diffusion.txt2img": "images", + "music.txt2music": "music", + "video.txt2vid": "video", + "video.img2vid": "image to video", + "ffmpeg.transcode": "transcode", + "workflow.step": "workflow step", + "container.run": "container", + "infernet.temporal.train": "fine-tune", + "infernet.temporal.infer": "temporal inference", + unknown: "other", + }; + return known[t] ?? t; +} + function ago(s: number): string { if (s < 90) return `${s}s ago`; return `${Math.round(s / 60)}m ago`; @@ -26,12 +57,16 @@ export default async function NodesPage() { const p = await getNodesPayload(); const online = p.workers_online; const pct = Math.max(0.5, Math.min(100, (online / NODE_GOAL) * 100)); + const byType = summarizeByType(p.nodes); + const totalJobs = byType.reduce((a, t) => a + t.jobs, 0); + const totalEarned = operatorEarnings(byType.reduce((a, t) => a + t.paid_usd, 0)); + const earningNodes = p.nodes.filter((n) => (n.jobs_24h?.jobs ?? 0) > 0).length; return ( -
+

nodes

-

// every node online now, best benchmark first

+

// every node online now, best benchmark first, with what it ran and earned in the last 24h

@@ -58,6 +93,67 @@ export default async function NodesPage() { See hardware details and per-workload benchmarks.

+
+

[ last 24h: what nodes earned, by job type ]

+ {totalJobs === 0 ? ( +

+ No completed jobs heard in the last 24 hours yet (the window restarts when the aggregator does). +

+ ) : ( + <> +

+ {earningNodes} nodes ran{" "} + {totalJobs.toLocaleString()} jobs and kept{" "} + {usd(totalEarned)} after the {MARKET_FEE_PCT}% fee. +

+
+ + + + + + + + + + + + + + {byType.map((t) => ( + + + + + + + + + + ))} + +
job typejobsnodesavg run timeavg pricenode keeps / jobnode keeps / busy hour
+ {jobLabel(t.type)} + {t.type} + {t.jobs.toLocaleString()}{t.nodes}{duration(t.busy_s / t.jobs)}{usd(t.paid_usd / t.jobs)}{usd(operatorEarnings(t.paid_usd) / t.jobs)} + {t.busy_s > 0 ? usd(operatorEarnings(t.paid_usd) / (t.busy_s / 3600)) : "-"} +
+
+ + )} +

+ Counted from the job accepts and receipts every node gossips: a job is + credited to a node only when its receipt comes from the peer the buyer + accepted. Run time is accept to receipt. Price is what the buyer agreed + to before the {MARKET_FEE_PCT}% house fee; the node keeps the rest. Free + jobs count at $0. Est. power on the board below assumes{" "} + {BUSY_WATTS.cpu} W for a CPU node and {BUSY_WATTS["gpu:nvidia"]} W for a + GPU node while busy, at ${POWER_USD_PER_KWH}/kWh; it is a typical + figure, not a measurement, and an idle node costs close to nothing + extra. Demand is early: these are real numbers, not a promise. +

+
+

[ board ]

{p.nodes.length === 0 ? ( @@ -72,6 +168,11 @@ export default async function NodesPage() { class cores bench + jobs 24h + busy + earned + est. power + net version invited by seen @@ -103,6 +204,41 @@ export default async function NodesPage() { {n.class} {n.cores ?? "-"} {n.bench_score?.toLocaleString() ?? "-"} + {n.jobs_24h && n.jobs_24h.jobs > 0 ? ( + (() => { + const j = n.jobs_24h; + const earned = operatorEarnings(j.paid_usd); + const power = powerCostUsd(n.class, j.busy_s); + const net = earned - power; + return ( + <> + + {j.jobs.toLocaleString()} + {Object.entries(j.by_type) + .sort((a, b) => b[1].jobs - a[1].jobs) + .slice(0, 3) + .map(([t, w]) => ( + + {jobLabel(t)} {w.jobs} + + ))} + + {duration(j.busy_s)} + {usd(earned)} + {usd(power)} + = 0 ? "accent" : "text-red-500"}`}>{usd(net)} + + ); + })() + ) : ( + <> + 0 + - + - + - + - + + )} {n.version ?? "-"} {n.ref ? {n.ref} : "-"} {ago(n.last_seen_s)} diff --git a/apps/web/src/lib/nodes.ts b/apps/web/src/lib/nodes.ts index c4f3f8f8..f184ab56 100644 --- a/apps/web/src/lib/nodes.ts +++ b/apps/web/src/lib/nodes.ts @@ -1,5 +1,6 @@ import "server-only"; import { fetchFromAggregators } from "./aggregators"; +import { OPERATOR_SHARE_PCT } from "./market"; /** * One row of the public node board, as served by the aggregator's `GET /nodes`. @@ -38,6 +39,23 @@ export interface NodeRow { * process and it stopped bidding. Absent when there is no duplicate. */ duplicate?: { instances: number; reported: boolean; yielding: boolean } | null; + /** + * Jobs this node completed in the last 24h as the aggregator heard them on + * the job topics: run time (accept to receipt) and what buyers agreed to pay, + * before the fee, by workload type. Absent when it completed none, and from + * aggregators older than this field. + */ + jobs_24h?: NodeJobs | null; +} + +export interface WorkloadJobs { + jobs: number; + busy_s: number; + paid_usd: number; +} + +export interface NodeJobs extends WorkloadJobs { + by_type: Record; } export interface BenchSample { @@ -69,6 +87,69 @@ export function priceLabel(p: Pricing | null | undefined): string { return p.min_usd > 0 ? `dynamic · min ${usd(p.min_usd)}` : "dynamic"; } +/** + * Rough power draw while a job runs, by board class. Only used for the + * "est. power" column: the board knows the class, not the machine, so this is + * a typical figure for a desktop under load, not a measurement. + */ +export const BUSY_WATTS: Record = { + cpu: 65, + "gpu:apple": 40, + "gpu:nvidia": 250, + "gpu:amd": 250, +}; + +/** Electricity price used for the estimate (about the US residential average). */ +export const POWER_USD_PER_KWH = 0.17; + +/** Estimated electricity spent on `busySeconds` of work on a node of `cls`. */ +export function powerCostUsd(cls: string, busySeconds: number): number { + const watts = BUSY_WATTS[cls] ?? BUSY_WATTS.cpu; + return (watts / 1000) * (busySeconds / 3600) * POWER_USD_PER_KWH; +} + +/** What the operator keeps from what buyers paid: the share after the house fee. */ +export function operatorEarnings(paidUsd: number): number { + return (paidUsd * OPERATOR_SHARE_PCT) / 100; +} + +/** One row of the network-wide "by job type" table. */ +export interface WorkloadSummary extends WorkloadJobs { + type: string; + nodes: number; +} + +/** Sum every node's 24h jobs by workload type, busiest type first. */ +export function summarizeByType(nodes: NodeRow[]): WorkloadSummary[] { + const by = new Map(); + for (const n of nodes) { + for (const [type, w] of Object.entries(n.jobs_24h?.by_type ?? {})) { + const row = by.get(type) ?? { type, jobs: 0, busy_s: 0, paid_usd: 0, nodes: 0 }; + row.jobs += w.jobs; + row.busy_s += w.busy_s; + row.paid_usd += w.paid_usd; + row.nodes += 1; + by.set(type, row); + } + } + return [...by.values()].sort((a, b) => b.jobs - a.jobs || a.type.localeCompare(b.type)); +} + +/** "$0.0042" for sub-cent amounts, "$1.23" otherwise, "$0" for nothing. */ +export function usd(n: number): string { + if (n === 0) return "$0"; + const sign = n < 0 ? "-" : ""; + const a = Math.abs(n); + return a < 0.01 ? `${sign}$${a.toPrecision(2)}` : `${sign}$${a.toFixed(2)}`; +} + +/** "42s" / "3.5m" / "2.1h". */ +export function duration(seconds: number): string { + if (seconds < 90) return `${Math.round(seconds)}s`; + if (seconds < 5400) return `${(seconds / 60).toFixed(1)}m`; + return `${(seconds / 3600).toFixed(1)}h`; +} + export interface NodesPayload { generated_at: string; workers_online: number; diff --git a/node/crates/c0mpute-core/src/status_aggregator.rs b/node/crates/c0mpute-core/src/status_aggregator.rs index 0d7ed0df..d9787074 100644 --- a/node/crates/c0mpute-core/src/status_aggregator.rs +++ b/node/crates/c0mpute-core/src/status_aggregator.rs @@ -176,12 +176,29 @@ struct WorkloadStats { struct InFlight { workload_type: String, accepted_at_ms: u64, + /// The winning bidder's full peer id, from the accept. + worker: String, + /// The price the buyer agreed to, in dollars (0 for free jobs). + price_usd: f64, } struct Completed { workload_type: String, completed_at_ms: u64, latency_s: Option, + /// Who ran it and for how much, when we saw the accept and the receipt + /// came from the accepted winner. `None` otherwise: the job still counts + /// network-wide but is credited to no node. + credit: Option<(String, f64)>, +} + +/// Highest agreed price we credit to a node for one job. Anyone can gossip an +/// accept, so a forged one must not put a fantasy number on the board. +const MAX_CREDITED_PRICE_USD: f64 = 1_000.0; + +/// An accept's price as we credit it: finite, non-negative, capped. +fn credited_price(usd: f64) -> f64 { + if usd.is_finite() && usd > 0.0 { usd.min(MAX_CREDITED_PRICE_USD) } else { 0.0 } } /// Jobs tracked at once. Accepts and receipts come from any peer on the @@ -211,6 +228,8 @@ impl JobState { workload_type: a.workload_type, // Never ahead of our clock, or it would never age out. accepted_at_ms: a.published_at_ms.min(now_ms()), + worker: a.winning_bidder_peer_id, + price_usd: credited_price(a.agreed_price_usd), }, ); } @@ -235,6 +254,12 @@ impl JobState { .checked_sub(inf.accepted_at_ms) .map(|d| d as f64 / 1000.0) }); + // Credit the node only when the receipt comes from the peer the buyer + // accepted; a receipt from anyone else proves nothing about who ran it. + let credit = started + .as_ref() + .filter(|inf| inf.worker == r.worker_peer_id) + .map(|inf| (inf.worker.clone(), inf.price_usd)); let workload_type = started .map(|inf| inf.workload_type) .unwrap_or_else(|| "unknown".to_string()); @@ -248,6 +273,7 @@ impl JobState { // at the front would block eviction of everything behind it. completed_at_ms: r.completed_at_ms.min(now_ms()), latency_s, + credit, }); } @@ -497,6 +523,10 @@ struct NodeRow { /// from two instances of it. #[serde(skip_serializing_if = "Option::is_none")] duplicate: Option, + /// Jobs this node completed in the last 24h, by type, with run time and + /// what buyers paid. Absent when it completed none. + #[serde(skip_serializing_if = "Option::is_none")] + jobs_24h: Option, } #[derive(Serialize, Debug, PartialEq, Clone, Default)] @@ -519,6 +549,54 @@ fn reported_duplicate(hw: &serde_json::Value) -> Option { }) } +/// One workload type's share of a node's last 24h on the board. +#[derive(Serialize, Debug, PartialEq, Clone, Default)] +struct NodeWorkloadJobs { + /// Completed jobs. + jobs: u64, + /// Accept-to-receipt time summed over those jobs, in seconds. + busy_s: f64, + /// What buyers agreed to pay for them, in dollars, before any fee. + paid_usd: f64, +} + +/// A node's completed jobs over the last 24h, as this aggregator heard them +/// on the job topics: totals plus a breakdown by workload type. In-memory, so +/// an aggregator restart starts the window over. +#[derive(Serialize, Debug, PartialEq, Clone, Default)] +struct NodeJobs { + jobs: u64, + busy_s: f64, + paid_usd: f64, + by_type: BTreeMap, +} + +/// Fold the 24h completions into per-node stats keyed by short id (the board's +/// row id). +fn node_job_stats<'a>(completed: impl IntoIterator) -> HashMap { + let mut out: HashMap = HashMap::new(); + for c in completed { + let Some((worker, price)) = &c.credit else { continue }; + let busy = c.latency_s.unwrap_or(0.0).max(0.0); + let n = out.entry(short_id(worker)).or_default(); + n.jobs += 1; + n.busy_s += busy; + n.paid_usd += price; + let t = n.by_type.entry(c.workload_type.clone()).or_default(); + t.jobs += 1; + t.busy_s += busy; + t.paid_usd += price; + } + out +} + +/// Put each node's 24h job stats on its row. +fn apply_job_stats(payload: &mut NodesPayload, stats: &HashMap) { + for n in &mut payload.nodes { + n.jobs_24h = stats.get(&n.id).cloned(); + } +} + /// Add what the aggregator saw itself: ads from more than one instance. fn apply_instance_counts(payload: &mut NodesPayload, instances: &HashMap) { for n in &mut payload.nodes { @@ -696,6 +774,7 @@ fn build_nodes(ads: &[(String, c0mpute_net::topics::CapabilityAd)], now: u64) -> donates: donates(&ad.tags), last_seen_s: now.saturating_sub(ad.published_at_ms) / 1000, duplicate: reported_duplicate(&ad.hardware), + jobs_24h: None, }) .collect(); // Benchmarked nodes first, best score first; then by id for a stable order. @@ -751,6 +830,9 @@ async fn nodes_handler(State(state): State) -> Json { .map(|(p, n)| (short_id(&p.to_base58()), n)) .collect(); apply_instance_counts(&mut payload, &instances); + state.jobs.evict(now_ms()).await; + let stats = node_job_stats(state.jobs.completed.read().await.iter()); + apply_job_stats(&mut payload, &stats); keep_reachable_gateways(&mut payload, &*state.gateways.read().await); Json(payload) } @@ -1225,17 +1307,55 @@ mod tests { InFlight { workload_type: "ffmpeg.transcode".into(), accepted_at_ms: now - 2 * 60 * 60 * 1000, + worker: "worker".into(), + price_usd: 0.0, }, ); jobs.completed.write().await.push_back(Completed { workload_type: "ffmpeg.transcode".into(), completed_at_ms: now - 25 * 60 * 60 * 1000, latency_s: Some(3.0), + credit: None, }); jobs.evict(now).await; assert_eq!(jobs.in_flight.read().await.len(), 0); assert_eq!(jobs.completed.read().await.len(), 0); } + + #[tokio::test] + async fn completions_credit_the_accepted_worker_by_type() { + let jobs = JobState::default(); + let now = now_ms(); + let worker = "12D3KooWworkerAAAAAAAAAAAAAAAAworkerXYZ12345"; + let mut a = accept_for("t1", "tts.synthesize"); + a.winning_bidder_peer_id = worker.into(); + a.agreed_price_usd = 0.02; + a.published_at_ms = now - 4_000; + jobs.on_accept(a).await; + let mut a = accept_for("i1", "infernet.inference"); + a.winning_bidder_peer_id = worker.into(); + a.agreed_price_usd = f64::INFINITY; // forged: credited as 0 + a.published_at_ms = now - 2_000; + jobs.on_accept(a).await; + // A receipt from a peer the buyer did not accept credits nobody. + let mut a = accept_for("x1", "tts.synthesize"); + a.winning_bidder_peer_id = worker.into(); + jobs.on_accept(a).await; + for (id, from) in [("t1", worker), ("i1", worker), ("x1", "someone-else")] { + let mut r = receipt_for(id, now); + r.worker_peer_id = from.into(); + jobs.on_receipt(r).await; + } + let completed = jobs.completed.read().await; + assert_eq!(completed.len(), 3, "all three still count network-wide"); + let stats = node_job_stats(completed.iter()); + let n = &stats[&short_id(worker)]; + assert_eq!(n.jobs, 2); + assert!((n.paid_usd - 0.02).abs() < 1e-9); + assert!((n.busy_s - 6.0).abs() < 0.5); + assert_eq!(n.by_type["tts.synthesize"].jobs, 1); + assert_eq!(n.by_type["infernet.inference"].paid_usd, 0.0); + } } #[cfg(test)]