Commit 224b04c0 authored by Matt Masurka's avatar Matt Masurka Committed by GitHub

Adds delay to watcher (#1159)

* Adds delay to watcher

* Simplifies delay

* Adds changeset
parent e6e85a62
---
'@eth-optimism/core-utils': patch
---
Adds a pollInterval delay to watcher.ts
......@@ -10,16 +10,21 @@ export interface Layer {
export interface WatcherOptions {
l1: Layer
l2: Layer
pollInterval?: number
}
export class Watcher {
public l1: Layer
public l2: Layer
public pollInterval: number = 3000
public NUM_BLOCKS_TO_FETCH: number = 10_000_000
constructor(opts: WatcherOptions) {
this.l1 = opts.l1
this.l2 = opts.l2
if(opts.pollInterval) {
this.pollInterval = opts.pollInterval
}
}
public async getMessageHashesFromL1Tx(l1TxHash: string): Promise<string[]> {
......@@ -93,10 +98,14 @@ export class Watcher {
const failureLogs = await layer.provider.getLogs(failureFilter)
const logs = successLogs.concat(failureLogs)
matches = logs.filter((log: ethers.providers.Log) => log.data === msgHash)
// exit loop after first iteration if not polling
if (!pollForPending) {
break
}
// pause awhile before trying again
await new Promise(r => setTimeout(r, this.pollInterval))
}
// Message was relayed in the past
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment