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 { ...@@ -10,16 +10,21 @@ export interface Layer {
export interface WatcherOptions { export interface WatcherOptions {
l1: Layer l1: Layer
l2: Layer l2: Layer
pollInterval?: number
} }
export class Watcher { export class Watcher {
public l1: Layer public l1: Layer
public l2: Layer public l2: Layer
public pollInterval: number = 3000
public NUM_BLOCKS_TO_FETCH: number = 10_000_000 public NUM_BLOCKS_TO_FETCH: number = 10_000_000
constructor(opts: WatcherOptions) { constructor(opts: WatcherOptions) {
this.l1 = opts.l1 this.l1 = opts.l1
this.l2 = opts.l2 this.l2 = opts.l2
if(opts.pollInterval) {
this.pollInterval = opts.pollInterval
}
} }
public async getMessageHashesFromL1Tx(l1TxHash: string): Promise<string[]> { public async getMessageHashesFromL1Tx(l1TxHash: string): Promise<string[]> {
...@@ -93,10 +98,14 @@ export class Watcher { ...@@ -93,10 +98,14 @@ export class Watcher {
const failureLogs = await layer.provider.getLogs(failureFilter) const failureLogs = await layer.provider.getLogs(failureFilter)
const logs = successLogs.concat(failureLogs) const logs = successLogs.concat(failureLogs)
matches = logs.filter((log: ethers.providers.Log) => log.data === msgHash) matches = logs.filter((log: ethers.providers.Log) => log.data === msgHash)
// exit loop after first iteration if not polling // exit loop after first iteration if not polling
if (!pollForPending) { if (!pollForPending) {
break break
} }
// pause awhile before trying again
await new Promise(r => setTimeout(r, this.pollInterval))
} }
// Message was relayed in the past // 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