Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ Example response:
"mainnet": {
"totalBlocks": 7000000,
"processedBlocks": 3000000,
"progressPct": 42.9,
"historicalBlocksFetchedPct": 42.9,
"isRealtime": false,
"isComplete": false
},
"gnosis": {
"totalBlocks": 17000000,
"processedBlocks": 17000000,
"progressPct": 100.0,
"historicalBlocksFetchedPct": 100.0,
"isRealtime": true,
"isComplete": true
}
}
```

- `progressPct` is rounded to one decimal place (0–100).
- `historicalBlocksFetchedPct` is rounded to one decimal place (0–100).
- `isRealtime` flips to `true` once the chain enters live-sync mode.
- `isComplete` flips to `true` once all historical blocks are processed.
- Returns `{}` if the `/metrics` endpoint is unreachable.
Expand Down
4 changes: 2 additions & 2 deletions src/api/endpoints/sync-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const syncProgressHandler: RouteHandler<typeof syncProgressRoute> =
{
totalBlocks: number;
processedBlocks: number;
progressPct: number;
historicalBlocksFetchedPct: number;
isRealtime: boolean;
isComplete: boolean;
}
Expand All @@ -72,7 +72,7 @@ export const syncProgressHandler: RouteHandler<typeof syncProgressRoute> =
result[chain] = {
totalBlocks: t,
processedBlocks: processed,
progressPct: pct,
historicalBlocksFetchedPct: pct,
isRealtime: (isRealtime.get(chain) ?? 0) === 1,
isComplete: (isComplete.get(chain) ?? 0) === 1,
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const syncProgressRoute = createRoute({
tags: ["Indexer"],
summary: "Per-chain historical sync progress",
description:
"Returns the indexer's historical backfill progress per chain: total blocks to process, blocks already processed, percentage complete, and whether the chain is in realtime mode. Reads from Ponder's built-in Prometheus metrics. During initial sync, progressPct will rise from 0 to 100 and isComplete will flip to true once the chain is fully caught up.",
"Returns the indexer's historical backfill progress per chain: total blocks to process, blocks already processed, percentage complete, and whether the chain is in realtime mode. Reads from Ponder's built-in Prometheus metrics. During initial sync, historicalBlocksFetchedPct will rise from 0 to 100 and isComplete will flip to true once the chain is fully caught up.",
responses: {
200: {
description: "Per-chain sync progress.",
Expand Down
2 changes: 1 addition & 1 deletion src/api/schemas/sync-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ChainProgressSchema = z.object({
.number()
.int()
.describe("Blocks already processed (completed + served from cache)."),
progressPct: z
historicalBlocksFetchedPct: z
.number()
.describe("Completion percentage (0–100). Rounded to one decimal place."),
isRealtime: z
Expand Down
8 changes: 4 additions & 4 deletions tests/api/sync-progress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { syncProgressHandler } from "../../src/api/endpoints/sync-progress";
type ChainProgress = {
totalBlocks: number;
processedBlocks: number;
progressPct: number;
historicalBlocksFetchedPct: number;
isRealtime: boolean;
isComplete: boolean;
};
Expand Down Expand Up @@ -84,15 +84,15 @@ describe("GET /api/sync-progress", () => {
expect(body["gnosis"]!.processedBlocks).toBe(2_400_000);
});

it("computes progressPct correctly (rounded to 1 decimal)", async () => {
it("computes historicalBlocksFetchedPct correctly (rounded to 1 decimal)", async () => {
mockFetch(SAMPLE_METRICS);
const app = buildApp();
const res = await app.request("http://localhost/api/sync-progress");
const body = (await res.json()) as Record<string, ChainProgress>;
// mainnet: 3_000_000 / 7_000_000 = 42.857... → 42.9
expect(body["mainnet"]!.progressPct).toBe(42.9);
expect(body["mainnet"]!.historicalBlocksFetchedPct).toBe(42.9);
// gnosis: 2_400_000 / 17_000_000 = 14.117... → 14.1
expect(body["gnosis"]!.progressPct).toBe(14.1);
expect(body["gnosis"]!.historicalBlocksFetchedPct).toBe(14.1);
});

it("sets isRealtime and isComplete from metrics flags", async () => {
Expand Down
Loading