-
Notifications
You must be signed in to change notification settings - Fork 15
refactor(ensnode-sdk): improve indexing status data model #1628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tk-o
wants to merge
21
commits into
main
Choose a base branch
from
refactor/ensnode-indexing-status-data-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4b065e5
Extract CrossChainIndexingStatus business-layer from generic types.ts…
tk-o 752211c
Update import paths
tk-o 8a091e9
Extract CrossChainIndexingStatus business-layer from generic helpers.…
tk-o 3c30a97
Remove empty helpers.ts file
tk-o 4babb45
Extract CrossChainIndexingStatus serialize-layer from generic seriali…
tk-o 8e5500d
Update import paths
tk-o 17d56b4
Extract CrossChainIndexingStatus serialize-layer from generic seriali…
tk-o ffd7b9d
Extract CrossChainIndexingStatus zod-schema-layer from generic zod-sc…
tk-o f3621c3
Extract CrossChainIndexingStatus deserialize-layer from generic deser…
tk-o a18df44
Update import paths
tk-o ac95ad7
Extract CrossChainIndexingStatus zod-schema-layer from generic valida…
tk-o 79442e2
Extract RealtimeIndexingStatusProjection business-layer from generic …
tk-o 4a25502
Extract RealtimeIndexingStatusProjection business-layer from generic …
tk-o b555191
Extract RealtimeIndexingStatusProjection serialize-layer from generic…
tk-o e05ac9c
Extract RealtimeIndexingStatusProjection serialize-layer from generic…
tk-o 8cc84fd
Extract RealtimeIndexingStatusProjection zod-schema-layer from generi…
tk-o 62010f7
Extract RealtimeIndexingStatusProjection zod-schema-layer from generi…
tk-o 8466552
Extract RealtimeIndexingStatusProjection deserialize-layer from gener…
tk-o 8c40bfa
Apply AI agent feedback
tk-o bf5bf94
Apply AI agent feedback
tk-o 66ae12d
Apply AI agent feedback
tk-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
packages/ensnode-sdk/src/ensindexer/indexing-status/deserialize.ts
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...de-sdk/src/ensindexer/indexing-status/deserialize/cross-chain-indexing-status-snapshot.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { prettifyError } from "zod/v4"; | ||
|
|
||
| import type { CrossChainIndexingStatusSnapshot } from "../cross-chain-indexing-status-snapshot"; | ||
| import type { SerializedCrossChainIndexingStatusSnapshot } from "../serialize/cross-chain-indexing-status-snapshot"; | ||
| import { makeCrossChainIndexingStatusSnapshotSchema } from "../zod-schema/cross-chain-indexing-status-snapshot"; | ||
|
|
||
| /** | ||
| * Deserialize an {@link CrossChainIndexingStatusSnapshot} object. | ||
| */ | ||
| export function deserializeCrossChainIndexingStatusSnapshot( | ||
| maybeSnapshot: SerializedCrossChainIndexingStatusSnapshot, | ||
| valueLabel?: string, | ||
| ): CrossChainIndexingStatusSnapshot { | ||
| const schema = makeCrossChainIndexingStatusSnapshotSchema(valueLabel); | ||
| const parsed = schema.safeParse(maybeSnapshot); | ||
|
|
||
| if (parsed.error) { | ||
| throw new Error( | ||
| `Cannot deserialize into CrossChainIndexingStatusSnapshot:\n${prettifyError(parsed.error)}\n`, | ||
| ); | ||
| } | ||
|
|
||
| return parsed.data; | ||
| } |
24 changes: 24 additions & 0 deletions
24
...ode-sdk/src/ensindexer/indexing-status/deserialize/realtime-indexing-status-projection.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { prettifyError } from "zod/v4"; | ||
|
|
||
| import type { RealtimeIndexingStatusProjection } from "../realtime-indexing-status-projection"; | ||
| import type { SerializedRealtimeIndexingStatusProjection } from "../serialize/realtime-indexing-status-projection"; | ||
| import { makeRealtimeIndexingStatusProjectionSchema } from "../zod-schema/realtime-indexing-status-projection"; | ||
|
|
||
| /** | ||
| * Deserialize into a {@link RealtimeIndexingStatusProjection} object. | ||
| */ | ||
| export function deserializeRealtimeIndexingStatusProjection( | ||
| maybeProjection: SerializedRealtimeIndexingStatusProjection, | ||
| valueLabel?: string, | ||
| ): RealtimeIndexingStatusProjection { | ||
| const schema = makeRealtimeIndexingStatusProjectionSchema(valueLabel); | ||
| const parsed = schema.safeParse(maybeProjection); | ||
|
|
||
| if (parsed.error) { | ||
| throw new Error( | ||
| `Cannot deserialize into RealtimeIndexingStatusProjection:\n${prettifyError(parsed.error)}\n`, | ||
| ); | ||
| } | ||
|
|
||
| return parsed.data; | ||
| } | ||
28 changes: 0 additions & 28 deletions
28
packages/ensnode-sdk/src/ensindexer/indexing-status/helpers.ts
This file was deleted.
Oops, something went wrong.
11 changes: 5 additions & 6 deletions
11
packages/ensnode-sdk/src/ensindexer/indexing-status/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| export * from "./chain-indexing-status-snapshot"; | ||
| export * from "./deserialize"; | ||
| export * from "./cross-chain-indexing-status-snapshot"; | ||
| export * from "./deserialize/chain-indexing-status-snapshot"; | ||
| export * from "./deserialize/cross-chain-indexing-status-snapshot"; | ||
| export * from "./deserialize/omnichain-indexing-status-snapshot"; | ||
| export * from "./helpers"; | ||
| export * from "./deserialize/realtime-indexing-status-projection"; | ||
| export * from "./omnichain-indexing-status-snapshot"; | ||
| export * from "./projection"; | ||
| export * from "./serialize"; | ||
| export * from "./realtime-indexing-status-projection"; | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export * from "./serialize/chain-indexing-status-snapshot"; | ||
| export * from "./serialize/omnichain-indexing-status-snapshot"; | ||
| export * from "./serialized-types"; | ||
| export * from "./types"; | ||
| export * from "./serialize/realtime-indexing-status-projection"; | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export * from "./validate/chain-indexing-status-snapshot"; | ||
28 changes: 0 additions & 28 deletions
28
packages/ensnode-sdk/src/ensindexer/indexing-status/projection.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/ensnode-sdk/src/ensindexer/indexing-status/realtime-indexing-status-projection.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { Duration, UnixTimestamp } from "../../shared/types"; | ||
| import type { CrossChainIndexingStatusSnapshot } from "./cross-chain-indexing-status-snapshot"; | ||
|
|
||
| /** | ||
| * A "realtime" indexing status projection based on worst-case assumptions | ||
| * from the `snapshot`. | ||
| * | ||
| * Invariants: | ||
| * - `projectedAt` is always >= `snapshot.snapshotTime`. | ||
| * - `worstCaseDistance` is always equal to | ||
| * `projectedAt - snapshot.slowestChainIndexingCursor`. | ||
| */ | ||
| export type RealtimeIndexingStatusProjection = { | ||
| /** | ||
| * The timestamp representing "now" as of the time this projection was generated. | ||
| */ | ||
| projectedAt: UnixTimestamp; | ||
|
|
||
| /** | ||
| * The distance between `projectedAt` and `snapshot.slowestChainIndexingCursor`. | ||
| * | ||
| * This is "worst-case" because it assumes all of the following: | ||
| * - the `snapshot` (which may have `snapshot.snapshotTime < projectedAt`) is still the | ||
| * latest snapshot and no indexing progress has been made since `snapshotTime`. | ||
| * - each indexed chain has added a new block as of `projectedAt`. | ||
| */ | ||
| worstCaseDistance: Duration; | ||
|
|
||
| /** | ||
| * The {@link CrossChainIndexingStatusSnapshot} that this projection is based on. | ||
| */ | ||
| snapshot: CrossChainIndexingStatusSnapshot; | ||
| }; | ||
|
|
||
| /** | ||
| * Create realtime indexing status projection from | ||
| * a {@link CrossChainIndexingStatusSnapshot}. | ||
| */ | ||
| export function createRealtimeIndexingStatusProjection( | ||
| snapshot: CrossChainIndexingStatusSnapshot, | ||
| now: UnixTimestamp, | ||
| ): RealtimeIndexingStatusProjection { | ||
| /** | ||
| * The timestamp when the realtime indexing status was projected. | ||
| * | ||
| * Due to possible clock skew between different systems, | ||
| * if the "now" timestamp on the system generating this indexing status | ||
| * projection is less than the snapshot time, then this value must be set to | ||
| * equal to the whichever is higher between the `now` and | ||
| * the snapshot time to ensure all invariants are followed. | ||
| */ | ||
| const projectedAt = Math.max(now, snapshot.snapshotTime); | ||
|
|
||
| return { | ||
| projectedAt, | ||
| worstCaseDistance: projectedAt - snapshot.slowestChainIndexingCursor, | ||
| snapshot, | ||
| }; | ||
| } |
30 changes: 0 additions & 30 deletions
30
packages/ensnode-sdk/src/ensindexer/indexing-status/serialize.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.