Skip to content

Commit 1902bfb

Browse files
committed
Use getIndexingMetadataContext for all ENSNode Metadata reads from ENSDb instnace
1 parent 7595a41 commit 1902bfb

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

apps/ensapi/src/cache/indexing-status.cache.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { EnsNodeMetadataKeys } from "@ensnode/ensdb-sdk";
2-
import { type CrossChainIndexingStatusSnapshot, SWRCache } from "@ensnode/ensnode-sdk";
2+
import {
3+
type CrossChainIndexingStatusSnapshot,
4+
IndexingMetadataContextStatusCodes,
5+
SWRCache,
6+
} from "@ensnode/ensnode-sdk";
37

48
import { ensDbClient } from "@/lib/ensdb/singleton";
59
import { lazyProxy } from "@/lib/lazy";
@@ -16,9 +20,11 @@ export const indexingStatusCache = lazyProxy<SWRCache<CrossChainIndexingStatusSn
1620
new SWRCache<CrossChainIndexingStatusSnapshot>({
1721
fn: async (_cachedResult) =>
1822
ensDbClient
19-
.getIndexingStatusSnapshot() // get the latest indexing status snapshot
20-
.then((snapshot) => {
21-
if (snapshot === undefined) {
23+
.getIndexingMetadataContext() // get the latest indexing status snapshot
24+
.then((indexingMetadataContext) => {
25+
if (
26+
indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized
27+
) {
2228
// An indexing status snapshot has not been found in ENSDb yet.
2329
// This might happen during application startup, i.e. when ENSDb
2430
// has not yet been populated with the first snapshot.
@@ -30,7 +36,7 @@ export const indexingStatusCache = lazyProxy<SWRCache<CrossChainIndexingStatusSn
3036
// Therefore, return it so that this current invocation of `readCache` will:
3137
// - Replace the currently cached value (if any) with this new value.
3238
// - Return this non-null value.
33-
return snapshot;
39+
return indexingMetadataContext.indexingStatus;
3440
})
3541
.catch((error) => {
3642
// Either the indexing status snapshot fetch failed, or the indexing status snapshot was not found in ENSDb yet.

apps/ensapi/src/config/config.schema.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pRetry from "p-retry";
22
import { prettifyError, ZodError, z } from "zod/v4";
33

4-
import type { EnsApiPublicConfig } from "@ensnode/ensnode-sdk";
4+
import { type EnsApiPublicConfig, IndexingMetadataContextStatusCodes } from "@ensnode/ensnode-sdk";
55
import {
66
buildRpcConfigsFromEnv,
77
canFallbackToTheGraph,
@@ -70,13 +70,13 @@ export async function buildConfigFromEnvironment(env: EnsApiEnvironment): Promis
7070
// https://github.com/namehash/ensnode/issues/1806
7171
const ensIndexerPublicConfig = await pRetry(
7272
async () => {
73-
const config = await ensDbClient.getEnsIndexerPublicConfig();
73+
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
7474

75-
if (!config) {
76-
throw new Error("ENSIndexer Public Config not yet available in ENSDb.");
75+
if (indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized) {
76+
throw new Error("Indexing metadata context is uninitialized in ENSDb.");
7777
}
7878

79-
return config;
79+
return indexingMetadataContext.stackInfo.ensIndexer;
8080
},
8181
{
8282
retries: 13, // This allows for a total of over 1 hour of retries with the exponential backoff strategy

apps/ensindexer/ponder/src/api/handlers/ensnode-api.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
EnsIndexerIndexingStatusResponseCodes,
77
type EnsIndexerIndexingStatusResponseError,
88
type EnsIndexerIndexingStatusResponseOk,
9+
IndexingMetadataContextStatusCodes,
910
serializeEnsIndexerIndexingStatusResponse,
1011
serializeEnsIndexerPublicConfig,
1112
} from "@ensnode/ensnode-sdk";
@@ -17,32 +18,33 @@ const app = new Hono();
1718

1819
// include ENSIndexer Public Config endpoint
1920
app.get("/config", async (c) => {
20-
const publicConfig = await ensDbClient.getEnsIndexerPublicConfig();
21+
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
2122

2223
// Invariant: the public config is guaranteed to be available in ENSDb after
2324
// application startup.
24-
if (typeof publicConfig === "undefined") {
25+
if (indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized) {
2526
throw new Error("Unreachable: ENSIndexer Public Config is not available in ENSDb");
2627
}
2728

2829
// respond with the serialized public config object
29-
return c.json(serializeEnsIndexerPublicConfig(publicConfig));
30+
return c.json(serializeEnsIndexerPublicConfig(indexingMetadataContext.stackInfo.ensIndexer));
3031
});
3132

3233
app.get("/indexing-status", async (c) => {
3334
try {
34-
const crossChainSnapshot = await ensDbClient.getIndexingStatusSnapshot();
35+
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
3536

3637
// Invariant: the Indexing Status Snapshot is expected to be available in
3738
// ENSDb shortly after application startup. There is a possibility that
3839
// the snapshot is not yet available at the time of the request,
3940
// i.e. when ENSDb has not yet been populated with the first snapshot.
4041
// In this case, we treat the snapshot as unavailable and respond with
4142
// an error response.
42-
if (typeof crossChainSnapshot === "undefined") {
43+
if (indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized) {
4344
throw new Error("ENSDb does not contain an Indexing Status Snapshot");
4445
}
4546

47+
const crossChainSnapshot = indexingMetadataContext.indexingStatus;
4648
const projectedAt = getUnixTime(new Date());
4749
const realtimeProjection = createRealtimeIndexingStatusProjection(
4850
crossChainSnapshot,

packages/integration-test-env/src/orchestrator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import {
3939
} from "testcontainers";
4040

4141
import { ENSNamespaceIds } from "@ensnode/datasources";
42-
import { OmnichainIndexingStatusIds } from "@ensnode/ensnode-sdk";
42+
import {
43+
IndexingMetadataContextStatusCodes,
44+
OmnichainIndexingStatusIds,
45+
} from "@ensnode/ensnode-sdk";
4346

4447
const MONOREPO_ROOT = resolve(import.meta.dirname, "../../..");
4548
const ENSRAINBOW_DIR = resolve(MONOREPO_ROOT, "apps/ensrainbow");
@@ -198,9 +201,10 @@ async function pollIndexingStatus(
198201
while (Date.now() - start < timeoutMs) {
199202
checkAborted();
200203
try {
201-
const snapshot = await ensDbClient.getIndexingStatusSnapshot();
202-
if (snapshot !== undefined) {
203-
const omnichainStatus = snapshot.omnichainSnapshot.omnichainStatus;
204+
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
205+
206+
if (indexingMetadataContext.statusCode === IndexingMetadataContextStatusCodes.Initialized) {
207+
const { omnichainStatus } = indexingMetadataContext.indexingStatus.omnichainSnapshot;
204208
log(`Omnichain status: ${omnichainStatus}`);
205209
if (
206210
omnichainStatus === OmnichainIndexingStatusIds.Following ||

0 commit comments

Comments
 (0)