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
5 changes: 5 additions & 0 deletions .changeset/quick-paws-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ensnode/ensnode-sdk": minor
---

Introduces `validateChainIndexingStatusSnapshot` which enables validating values against business-layer requirements.
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { type ParsePayload, prettifyError } from "zod/v4/core";
import { prettifyError } from "zod/v4/core";

import {
checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotBackfill,
checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotCompleted,
checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotFollowing,
checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotUnstarted,
OmnichainIndexingStatusIds,
type SerializedOmnichainIndexingStatusSnapshot,
} from "@ensnode/ensnode-sdk";
import type { PrometheusMetrics } from "@ensnode/ponder-metadata";

import { PonderAppSettingsSchema } from "./zod-schemas";
Expand All @@ -32,43 +24,3 @@ export function validatePonderMetrics(metrics: PrometheusMetrics) {
);
}
}

/**
* Invariant: SerializedOmnichainSnapshot Has Valid Chains
*
* Validates that the `chains` property of a {@link SerializedOmnichainIndexingStatusSnapshot}
* is consistent with the reported `omnichainStatus`.
*/
export function invariant_serializedOmnichainSnapshotHasValidChains(
ctx: ParsePayload<SerializedOmnichainIndexingStatusSnapshot>,
) {
const omnichainSnapshot = ctx.value;
const chains = Object.values(omnichainSnapshot.chains);
let hasValidChains = false;

switch (omnichainSnapshot.omnichainStatus) {
case OmnichainIndexingStatusIds.Unstarted:
hasValidChains = checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotUnstarted(chains);
break;

case OmnichainIndexingStatusIds.Backfill:
hasValidChains = checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotBackfill(chains);
break;

case OmnichainIndexingStatusIds.Completed:
hasValidChains = checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotCompleted(chains);
break;

case OmnichainIndexingStatusIds.Following:
hasValidChains = checkChainIndexingStatusSnapshotsForOmnichainStatusSnapshotFollowing(chains);
break;
}

if (!hasValidChains) {
ctx.issues.push({
code: "custom",
input: omnichainSnapshot,
message: `"chains" are not consistent with the reported '${omnichainSnapshot.omnichainStatus}' "omnichainStatus"`,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";

import { earlierBlockRef, laterBlockRef } from "./block-refs.mock";
import {
type ChainIndexingConfigDefinite,
type ChainIndexingConfigIndefinite,
ChainIndexingConfigTypeIds,
createIndexingConfig,
} from "./chain-indexing-status-snapshot";

describe("Chain Indexing Status Snapshot", () => {
describe("createIndexingConfig", () => {
it("returns 'definite' indexer config if the endBlock exists", () => {
// arrange
const startBlock = earlierBlockRef;
const endBlock = laterBlockRef;

// act
const indexingConfig = createIndexingConfig(startBlock, endBlock);

// assert
expect(indexingConfig).toStrictEqual({
configType: ChainIndexingConfigTypeIds.Definite,
startBlock: earlierBlockRef,
endBlock: laterBlockRef,
} satisfies ChainIndexingConfigDefinite);
});

it("returns 'indefinite' indexer config if the endBlock does not exist", () => {
// arrange
const startBlock = earlierBlockRef;
const endBlock = null;

// act
const indexingConfig = createIndexingConfig(startBlock, endBlock);

// assert
expect(indexingConfig).toStrictEqual({
configType: ChainIndexingConfigTypeIds.Indefinite,
startBlock: earlierBlockRef,
} satisfies ChainIndexingConfigIndefinite);
});
});
});
Loading