Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fd): have fault detector wait for providers
Updates the fault detector to wait for its L1 and L2 RPC providers using a new utility function in common-ts. This will prevent errors that users currently experience with the fault detector.
- Loading branch information
1 parent
2f50e29
commit c6c9c7d
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
'@eth-optimism/common-ts': patch | ||
--- | ||
|
||
Adds a function for waiting for ethers providers |
This file contains 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 @@ | ||
--- | ||
'@eth-optimism/fault-detector': patch | ||
--- | ||
|
||
Fault detector will now wait for providers to be connected |
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './logger' | ||
export * from './metrics' | ||
export * from './provider' |
This file contains 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,39 @@ | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { sleep } from '@eth-optimism/core-utils' | ||
|
||
import { Logger } from './logger' | ||
|
||
/** | ||
* Waits for an Ethers provider to be connected. | ||
* | ||
* @param provider Ethers provider to check. | ||
* @param opts Options for the function. | ||
* @param opts.logger Logger to use. | ||
* @param opts.intervalMs Interval to wait between checks. | ||
* @param opts.name Name of the provider for logs. | ||
*/ | ||
export const waitForProvider = async ( | ||
provider: Provider, | ||
opts?: { | ||
logger?: Logger | ||
intervalMs?: number | ||
name?: string | ||
} | ||
) => { | ||
opts?.logger?.info(`waiting for ${opts?.name || 'target'} provider...`) | ||
|
||
let connected = false | ||
while (!connected) { | ||
try { | ||
await provider.getBlockNumber() | ||
connected = true | ||
} catch (e) { | ||
opts?.logger?.info(`${provider} provider not connected, retrying...`) | ||
|
||
// Don't spam requests | ||
await sleep(opts?.intervalMs || 15000) | ||
} | ||
} | ||
|
||
opts?.logger?.info(`${opts?.name || 'target'} provider connected`) | ||
} |
This file contains 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