Source: independent Bitcoin Economy uptime re-probe

Exact Node.js source used for the three-attempt, 37-provider uptime measurement.

Exact probe source

import { createHash } from "node:crypto";
import { lookup } from "node:dns/promises";
import { mkdir, writeFile } from "node:fs/promises";
import net from "node:net";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const here = dirname(fileURLToPath(import.meta.url));
const outputs = join(here, "..", "..", "outputs");
const snapshotUrl = "https://marketplace.bitcoineconomy.ai/live/snapshot.json";
const attemptsPerTarget = 3;
const timeoutMs = 10_000;
const maxBodyBytes = 5 * 1024 * 1024;
const concurrency = 6;

function ipv4IsPublic(address) {
  const octets = address.split(".").map(Number);
  const [a, b, c] = octets;
  if (a === 0 || a === 10 || a === 127 || a >= 224) return false;
  if (a === 100 && b >= 64 && b <= 127) return false;
  if (a === 169 && b === 254) return false;
  if (a === 172 && b >= 16 && b <= 31) return false;
  if (a === 192 && b === 168) return false;
  if (a === 192 && b === 0 && c === 0) return false;
  if (a === 192 && b === 0 && c === 2) return false;
  if (a === 198 && (b === 18 || b === 19 || b === 51)) return false;
  if (a === 203 && b === 0 && c === 113) return false;
  return true;
}

function ipIsPublic(address) {
  const version = net.isIP(address);
  if (version === 4) return ipv4IsPublic(address);
  if (version !== 6) return false;
  const lower = address.toLowerCase();
  if (lower === "::" || lower === "::1") return false;
  if (lower.startsWith("fc") || lower.startsWith("fd") || lower.startsWith("fe8") || lower.startsWith("fe9") || lower.startsWith("fea") || lower.startsWith("feb")) return false;
  if (lower.startsWith("2001:db8:")) return false;
  const mapped = lower.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/);
  return mapped ? ipv4IsPublic(mapped[1]) : true;
}

async function validatePublicUrl(rawUrl) {
  const url = new URL(rawUrl);
  if (!["http:", "https:"].includes(url.protocol)) throw new Error(`unsupported protocol ${url.protocol}`);
  if (url.hostname.endsWith(".onion")) throw new Error("Tor endpoint unavailable from this vantage");
  const addresses = await lookup(url.hostname, { all: true, verbatim: true });
  if (!addresses.length || addresses.some(({ address }) => !ipIsPublic(address))) {
    throw new Error(`hostname did not resolve exclusively to public addresses: ${addresses.map((item) => item.address).join(",") || "none"}`);
  }
  return url;
}

async function readLimited(response, controller) {
  const declared = Number(response.headers.get("content-length") || 0);
  if (declared > maxBodyBytes) throw new Error(`response too large (${declared} bytes)`);
  const reader = response.body?.getReader();
  if (!reader) return Buffer.alloc(0);
  const chunks = [];
  let total = 0;
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    total += value.length;
    if (total > maxBodyBytes) {
      controller.abort();
      throw new Error(`response exceeded ${maxBodyBytes} bytes`);
    }
    chunks.push(Buffer.from(value));
  }
  return Buffer.concat(chunks);
}

async function fetchSafely(rawUrl, controller, redirectsLeft = 3) {
  const url = await validatePublicUrl(rawUrl);
  const response = await fetch(url, {
    redirect: "manual",
    signal: controller.signal,
    headers: {
      accept: "application/json",
      "user-agent": "QuickScan-Uptime-Reprobe/1.0 (public bounty verification)",
    },
  });
  if ([301, 302, 303, 307, 308].includes(response.status)) {
    if (!redirectsLeft) throw new Error("too many redirects");
    const location = response.headers.get("location");
    if (!location) throw new Error("redirect omitted Location");
    return fetchSafely(new URL(location, url).toString(), controller, redirectsLeft - 1);
  }
  return { response, finalUrl: url.toString() };
}

async function probeAttempt(endpoint, attempt) {
  const controller = new AbortController();
  const timer = setTimeout(() => controller.abort(new Error(`timeout after ${timeoutMs}ms`)), timeoutMs);
  const startedAt = new Date().toISOString();
  const started = performance.now();
  try {
    const { response, finalUrl } = await fetchSafely(endpoint, controller);
    const bytes = await readLimited(response, controller);
    const latencyMs = Math.round(performance.now() - started);
    let contractValid = false;
    let parseError = null;
    if (response.ok) {
      try {
        const parsed = JSON.parse(bytes.toString("utf8"));
        contractValid = Array.isArray(parsed?.data);
        if (!contractValid) parseError = "JSON response lacks top-level data[]";
      } catch (error) {
        parseError = `invalid JSON: ${error.message}`;
      }
    }
    return {
      attempt,
      startedAt,
      finalUrl,
      latencyMs,
      httpStatus: response.status,
      bytes: bytes.length,
      result: response.ok && contractValid ? "valid" : "degraded",
      error: response.ok ? parseError : `HTTP ${response.status}`,
    };
  } catch (error) {
    return {
      attempt,
      startedAt,
      finalUrl: endpoint,
      latencyMs: Math.round(performance.now() - started),
      httpStatus: null,
      bytes: 0,
      result: "transport-error",
      error: error?.message || String(error),
    };
  } finally {
    clearTimeout(timer);
  }
}

function firstClearnetUrl(provider) {
  if (provider.network === "unroutable") return null;
  return provider.urls?.find((raw) => {
    try {
      const url = new URL(raw);
      return ["http:", "https:"].includes(url.protocol) && !url.hostname.endsWith(".onion") && !["localhost", "127.0.0.1", "::1"].includes(url.hostname);
    } catch {
      return false;
    }
  }) || null;
}

function endpointFor(base) {
  const url = new URL(base);
  url.pathname = `${url.pathname.replace(/\/$/, "")}/v1/models`.replace(/\/+/g, "/");
  url.search = "";
  url.hash = "";
  return url.toString();
}

function median(numbers) {
  const sorted = [...numbers].sort((a, b) => a - b);
  if (!sorted.length) return null;
  const middle = Math.floor(sorted.length / 2);
  return sorted.length % 2 ? sorted[middle] : Math.round((sorted[middle - 1] + sorted[middle]) / 2);
}

function normalizePublished(status) {
  if (status === "unreachable") return "down";
  return status;
}

async function probeProvider(provider) {
  const base = firstClearnetUrl(provider);
  if (!base) {
    const status = provider.network === "tor" ? "unverified-tor-only" : provider.network === "unroutable" ? "unroutable" : "unprobeable";
    return { ...provider, endpoint: null, measuredStatus: status, medianLatencyMs: null, attempts: [], agrees: normalizePublished(provider.status) === status };
  }
  const endpoint = endpointFor(base);
  const attempts = [];
  for (let attempt = 1; attempt <= attemptsPerTarget; attempt += 1) {
    attempts.push(await probeAttempt(endpoint, attempt));
  }
  const valid = attempts.filter((item) => item.result === "valid");
  const httpResponses = attempts.filter((item) => item.httpStatus !== null);
  const measuredStatus = valid.length >= 2 ? "alive" : valid.length || httpResponses.length ? "degraded" : "down";
  const latencySamples = (valid.length ? valid : httpResponses).map((item) => item.latencyMs);
  return {
    ...provider,
    endpoint,
    measuredStatus,
    medianLatencyMs: median(latencySamples),
    attempts,
    agrees: normalizePublished(provider.status) === measuredStatus,
  };
}

async function mapLimit(items, limit, fn) {
  const results = new Array(items.length);
  let next = 0;
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
    while (true) {
      const index = next;
      next += 1;
      if (index >= items.length) return;
      results[index] = await fn(items[index], index);
    }
  }));
  return results;
}

const rawSnapshot = await fetch(snapshotUrl).then(async (response) => {
  if (!response.ok) throw new Error(`Snapshot returned ${response.status}`);
  return response.text();
});
const snapshot = JSON.parse(rawSnapshot);
const providers = snapshot.modules?.routstr?.providers;
if (!Array.isArray(providers) || !providers.length) throw new Error("Snapshot has no Routstr providers");
const startedAt = new Date().toISOString();
const results = await mapLimit(providers, concurrency, probeProvider);
const completedAt = new Date().toISOString();
const disagreements = results.filter((item) => !item.agrees);
const materialLatencyDifferences = results.filter((item) => {
  if (item.measuredStatus !== "alive" || item.status !== "alive" || item.latency_ms == null || item.medianLatencyMs == null) return false;
  const delta = Math.abs(item.medianLatencyMs - item.latency_ms);
  return delta > 250 && delta / Math.max(item.latency_ms, 1) > 0.5;
});

const rawOutput = {
  schemaVersion: 1,
  generatedAt: completedAt,
  snapshotUrl,
  snapshotGeneratedAt: snapshot.generated_at,
  snapshotSha256: createHash("sha256").update(rawSnapshot).digest("hex"),
  vantage: "Single independent public-network vantage in America/Los_Angeles; no Tor proxy",
  method: { attemptsPerTarget, timeoutMs, maxBodyBytes, concurrency, request: "GET first public clearnet URL + /v1/models", alive: "at least 2 of 3 attempts returned 2xx JSON with top-level data[]", degraded: "some HTTP response or one valid response, but fewer than 2 valid attempts", down: "all attempts failed before an HTTP response" },
  startedAt,
  completedAt,
  providerCount: results.length,
  disagreements: disagreements.map((item) => item.d),
  materialLatencyDifferences: materialLatencyDifferences.map((item) => item.d),
  providers: results,
};

function esc(value) {
  return String(value ?? "—").replaceAll("|", "\|").replaceAll("\n", " ");
}

function attemptSummary(item) {
  if (!item.attempts.length) return "n/a";
  return item.attempts.map((attempt) => attempt.httpStatus === null ? `ERR/${attempt.latencyMs}ms` : `${attempt.httpStatus}/${attempt.latencyMs}ms${attempt.result === "valid" ? "✓" : ""}`).join("; ");
}

const statusCounts = Object.groupBy(results, (item) => item.measuredStatus);
const rows = results.map((item) => `| ${esc(item.name || item.d)} | `${esc(item.d)}` | ${item.endpoint ? `[models](${item.endpoint})` : "—"} | ${esc(item.status)}${item.latency_ms == null ? "" : ` / ${item.latency_ms} ms`} | ${esc(item.measuredStatus)}${item.medianLatencyMs == null ? "" : ` / ${item.medianLatencyMs} ms`} | ${esc(attemptSummary(item))} | ${item.agrees ? "agree" : "**disagree**"} |`).join("\n");
const disagreementRows = disagreements.length ? disagreements.map((item) => `- **${item.name || item.d}** (`${item.d}`): published **${item.status}${item.latency_ms == null ? "" : `, ${item.latency_ms} ms`}**; measured **${item.measuredStatus}${item.medianLatencyMs == null ? "" : `, ${item.medianLatencyMs} ms`}**. Attempts: ${attemptSummary(item)}.`).join("\n") : "- None. Every published categorical status matched this independent pass.";
const latencyRows = materialLatencyDifferences.length ? materialLatencyDifferences.map((item) => {
  const delta = item.medianLatencyMs - item.latency_ms;
  return `- **${item.name || item.d}** (`${item.d}`): published ${item.latency_ms} ms; measured median ${item.medianLatencyMs} ms (${delta >= 0 ? "+" : ""}${delta} ms).`;
}).join("\n") : "- None exceeded both 250 ms absolute and 50% relative difference.";

const report = `# Independent re-probe of Bitcoin Economy marketplace uptime

Measured ${results.length} Routstr provider rows independently from ${startedAt} through ${completedAt}. The source snapshot was [live/snapshot.json](${snapshotUrl}), generated ${snapshot.generated_at}, SHA-256 `${rawOutput.snapshotSha256}`.

## Result

- Measured alive: ${statusCounts.alive?.length || 0}
- Measured degraded: ${statusCounts.degraded?.length || 0}
- Measured down: ${statusCounts.down?.length || 0}
- Tor-only, not tested from this vantage: ${statusCounts["unverified-tor-only"]?.length || 0}
- Unroutable announcements, not tested: ${statusCounts.unroutable?.length || 0}
- Published-status disagreements: ${disagreements.length}
- Material latency differences: ${materialLatencyDifferences.length}

## Reproducible method

This was a single independent public-network vantage in America/Los_Angeles, with no Tor proxy. For every row in `snapshot.modules.routstr.providers`, I selected the first public non-onion HTTP(S) URL and requested `/v1/models` three times. Each attempt had a 10-second deadline, at most three validated public-address redirects, a 5 MiB body cap, no credentials, and no payment. DNS results in private, loopback, link-local, or documentation ranges were refused before any request.

An attempt counted as valid only when it returned HTTP 2xx and parseable JSON with a top-level `data[]` array. A row is **alive** with at least two valid attempts, **degraded** when the host produced an HTTP response or only one valid response but fewer than two valid attempts, and **down** only when all three attempts failed before any HTTP response. Tor-only and unroutable rows are reported separately rather than mislabeled down. Latency is the median completed-response time of valid attempts, or of HTTP responses when none were valid.

Equivalent per-target check:

```sh
for attempt in 1 2 3; do
  curl --silent --show-error --max-time 10 --output body.json \\
    --write-out '%{http_code} %{time_total}\\n' "https://PROVIDER.example/v1/models"
  jq -e '.data | type == "array"' body.json
done

Run it against every provider in the cited snapshot, preserving Tor-only and unroutable classifications instead of sending requests to local/private destinations.

Every published provider row

means that attempt returned 2xx JSON with data[]. ERR means no HTTP response. Published latency is the marketplace’s last six-hour probe; measured latency is this pass’s median, so ordinary timing drift is expected.

Provider Stable d Endpoint Published Independently measured Three attempts Status verdict
${rows}

Explicit status disagreements

${disagreementRows}

Material latency differences

Flagged only when the absolute difference exceeded 250 ms and the relative difference exceeded 50%; smaller timing drift is shown in the full table but is not called a disagreement.

${latencyRows}

Limitations

  • This is one short measurement window from one network, not a replacement for the marketplace’s rolling 65-run history.
  • Tor-only services were not tested because this vantage had no Tor proxy; they are not called down.
  • The pass tests discovery/health at /v1/models, not paid inference, model quality, or Lightning/Cashu settlement.
  • Provider announcements can change after the cited snapshot; the timestamp and SHA-256 bind the population that was tested.

Raw attempt records, exact URLs, HTTP codes, timings, response sizes, and errors accompany this report in bitcoin-economy-uptime-raw.json.
`;

await mkdir(outputs, { recursive: true });
await writeFile(join(outputs, “bitcoin-economy-uptime-raw.json”), JSON.stringify(rawOutput, null, 2) + “\n”);
await writeFile(join(outputs, “bitcoin-economy-uptime-reprobe.md”), report);
console.log(JSON.stringify({
generatedAt: completedAt,
providerCount: results.length,
counts: Object.fromEntries(Object.entries(statusCounts).map(([key, value]) => [key, value.length])),
disagreements: disagreements.map((item) => ({ d: item.d, published: item.status, measured: item.measuredStatus })),
materialLatencyDifferences: materialLatencyDifferences.map((item) => ({ d: item.d, publishedMs: item.latency_ms, measuredMs: item.medianLatencyMs })),
}, null, 2));


Write a comment