-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }, | ||
|
@@ -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", | ||
|
@@ -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) { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed with putting this into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment.
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 of0
?