Skip to content
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

[WIP] improve(SpokePoolClient): Support restart of failed listener #1721

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 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
46 changes: 46 additions & 0 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class IndexedSpokePoolClient extends clients.SpokePoolClient {
* @returns void
*/
protected startWorker(): void {
// fromBlock is retained for the life of the SpokePoolClient and is reused in case of listener crash.
const {
finality,
eventSearchConfig: { fromBlock, maxBlockLookBack: blockRange },
Expand All @@ -92,6 +93,7 @@ export class IndexedSpokePoolClient extends clients.SpokePoolClient {
stdio: ["ignore", "inherit", "inherit", "ipc"],
});

this.worker.on("exit", (code, signal) => this.childExit(code, signal));
this.worker.on("message", (message) => this.indexerUpdate(message));
this.logger.debug({
at: "SpokePoolClient#startWorker",
Expand All @@ -100,6 +102,50 @@ export class IndexedSpokePoolClient extends clients.SpokePoolClient {
});
}

/**
* The worker process has exited. Optionally restart it based on the exit code.
* See also: https://nodejs.org/api/child_process.html#event-exit
* @param code Optional exit code.
* @param signal Optional signal resulting in termination.
* @returns void
*/
protected childExit(code?: number, signal?: string): void {
if (code === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any system defined constants (like EXIT_SUCCESS in the stdlib for C) that we can use instead of 0?

return;
}

this.logger.warn({
at: "SpokePoolClient#childExit",
message: `${this.chain} SpokePool listener exited.`,
code,
signal
});

// Flush all ingested deposits to protect against re-org.
// xxx this probably belongs upstream in a `protected SpokePoolClient.init()` method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed with putting this into init() to avoid any missed line items

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

// that is called in the constructor, such that it can be re-called by this method to
// re-initialise the same defaults.
Comment on lines +125 to +127
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will upstream this to the SDK.

this.currentTime = 0;
this.oldestTime = 0;
this.depositHashes = {};
this.depositHashesToFills = {};
this.speedUps = {};
this.slowFillRequests = {};
this.fills = {};
this.depositRoutes = {};

this.tokensBridged = [];
this.rootBundleRelays = [];
this.relayerRefundExecutions = [];
this.earliestDepositIdQueried = Number.MAX_SAFE_INTEGER;
this.latestDepositIdQueried = 0;
this.firstDepositIdForSpokePool = Number.MAX_SAFE_INTEGER;
this.lastDepositIdForSpokePool = Number.MAX_SAFE_INTEGER;

// Restart the listener process from the initial `fromBlock`.
this.startWorker();
}

/**
* Receive an update from the external indexer process.
* @param rawMessage Message to be parsed.
Expand Down