-
Notifications
You must be signed in to change notification settings - Fork 16
Onchain event handler preconditions #1843
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3f5dc4f
Create `ensRainbowClient` singleton for ENSIndexer app
tk-o f9e4e11
Simplify `ensrainbow/signleton.ts` file
tk-o 40bab87
Create `waitForEnsRainbowToBeReady` function
tk-o e84c0c7
Implement `eventHandlerPreconditios`
tk-o febed1c
docs(changeset): Introduced event handler preconditions to improve re…
tk-o 911035a
Merge remote-tracking branch 'origin/main' into feat/onchain-event-ha…
tk-o 22c3c22
Fix URL comparison for ENSRainbow singleton instnace
tk-o d0dd98c
Apply suggestions from code review
tk-o b9a0829
Apply PR feedback
tk-o ef53bf8
Update testing suite
tk-o d51b2ea
Update testing suite
tk-o 5647d79
Merge remote-tracking branch 'origin/main' into feat/onchain-event-ha…
tk-o 91308fb
Apply PR feedback
tk-o b78f2ce
Apply AI PR 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensindexer": minor | ||
| --- | ||
|
|
||
| Introduced indexing event handler preconditions to optimize the cross-service availability in an ENSNode instance when ENSRainbow is performing a cold-start. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { secondsToMilliseconds } from "date-fns"; | ||
| import pRetry from "p-retry"; | ||
|
|
||
| import { EnsRainbowApiClient } from "@ensnode/ensrainbow-sdk"; | ||
|
|
||
| const { ensRainbowUrl, labelSet } = config; | ||
|
|
||
| if (ensRainbowUrl.href === EnsRainbowApiClient.defaultOptions().endpointUrl.href) { | ||
| console.warn( | ||
| `Using default public ENSRainbow server which may cause increased network latency. For production, use your own ENSRainbow server that runs on the same network as the ENSIndexer server.`, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Singleton ENSRainbow Client instance for ENSIndexer app. | ||
| */ | ||
| export const ensRainbowClient = new EnsRainbowApiClient({ | ||
| endpointUrl: ensRainbowUrl, | ||
| labelSet, | ||
| }); | ||
|
|
||
| /** | ||
| * Cached promise for waiting for ENSRainbow to be ready. | ||
| * | ||
| * This ensures that multiple concurrent calls to | ||
| * {@link waitForEnsRainbowToBeReady} will share the same underlying promise | ||
| * in order to use the same retry sequence. | ||
| */ | ||
| let waitForEnsRainbowToBeReadyPromise: Promise<void> | undefined; | ||
|
|
||
| /** | ||
| * Wait for ENSRainbow to be ready | ||
| * | ||
| * Blocks execution until the ENSRainbow instance is ready to serve requests. | ||
| * | ||
| * Note: It may take 30+ minutes for the ENSRainbow instance to become ready in | ||
| * a cold start scenario. We use retries with a fixed interval between attempts | ||
| * for the ENSRainbow health check to allow for ample time for ENSRainbow to | ||
| * become ready. | ||
| * | ||
| * @throws When ENSRainbow fails to become ready after all configured retry attempts. | ||
| * This error will trigger termination of the ENSIndexer process. | ||
| */ | ||
| export function waitForEnsRainbowToBeReady(): Promise<void> { | ||
| if (waitForEnsRainbowToBeReadyPromise) { | ||
| return waitForEnsRainbowToBeReadyPromise; | ||
| } | ||
|
|
||
| console.log(`Waiting for ENSRainbow instance to be ready at '${ensRainbowUrl}'...`); | ||
|
|
||
| waitForEnsRainbowToBeReadyPromise = pRetry(async () => ensRainbowClient.health(), { | ||
|
tk-o marked this conversation as resolved.
|
||
| retries: 60, // This allows for a total of over 1 hour of retries with 1 minute between attempts. | ||
| minTimeout: secondsToMilliseconds(60), | ||
| maxTimeout: secondsToMilliseconds(60), | ||
| onFailedAttempt: ({ error, attemptNumber, retriesLeft }) => { | ||
| console.warn( | ||
| `Attempt ${attemptNumber} failed for the ENSRainbow health check at '${ensRainbowUrl}' (${error.message}). ${retriesLeft} retries left. This might be due to ENSRainbow having a cold start, which can take 30+ minutes.`, | ||
| ); | ||
| }, | ||
| }) | ||
|
tk-o marked this conversation as resolved.
tk-o marked this conversation as resolved.
|
||
| .then(() => console.log(`ENSRainbow instance is ready at '${ensRainbowUrl}'.`)) | ||
|
tk-o marked this conversation as resolved.
|
||
| .catch((error) => { | ||
| const errorMessage = error instanceof Error ? error.message : "Unknown error"; | ||
|
|
||
| console.error(`ENSRainbow health check failed after multiple attempts: ${errorMessage}`); | ||
|
|
||
| // Throw the error to terminate the ENSIndexer process due to the failed health check of a critical dependency | ||
| throw new Error(errorMessage, { | ||
| cause: error instanceof Error ? error : undefined, | ||
| }); | ||
|
tk-o marked this conversation as resolved.
|
||
| }); | ||
|
tk-o marked this conversation as resolved.
tk-o marked this conversation as resolved.
|
||
|
|
||
| return waitForEnsRainbowToBeReadyPromise; | ||
| } | ||
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
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.