This repository has been archived by the owner on Dec 5, 2021. It is now read-only.
forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider: use fallback provider helper
Allow the DTL to sync from multiple web3 backends using the `ethers.providers.FallbackProvider`. Multiple URLs can be passed through as a comma delimited string to configure multiple providers. A helper function is added to `core-utils` to allow easy configuration between services. This PR only introduces the usage of the fallback provider into the DTL. In the future, it should be added to other services that query L1 as well.
- Loading branch information
1 parent
3492792
commit e0be02e
Showing
8 changed files
with
88 additions
and
14 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,6 @@ | ||
--- | ||
'@eth-optimism/core-utils': patch | ||
'@eth-optimism/data-transport-layer': patch | ||
--- | ||
|
||
Add fallback provider support to DTL using helper function in core-utils |
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
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
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,40 @@ | ||
/** | ||
* Provider Utilities | ||
*/ | ||
|
||
import { ethers } from 'ethers' | ||
import { Provider } from '@ethersproject/providers' | ||
|
||
// Copied from @ethersproject/providers since it is not | ||
// currently exported | ||
export interface FallbackProviderConfig { | ||
// The Provider | ||
provider: Provider | ||
// The priority to favour this Provider; higher values are used first | ||
priority?: number | ||
// Timeout before also triggering the next provider; this does not stop | ||
// this provider and if its result comes back before a quorum is reached | ||
// it will be incorporated into the vote | ||
// - lower values will cause more network traffic but may result in a | ||
// faster retult. | ||
stallTimeout?: number | ||
// How much this provider contributes to the quorum; sometimes a specific | ||
// provider may be more reliable or trustworthy than others, but usually | ||
// this should be left as the default | ||
weight?: number | ||
} | ||
|
||
export const FallbackProvider = (config: string | FallbackProviderConfig[]) => { | ||
const configs = [] | ||
if (typeof config === 'string') { | ||
const urls = config.split(',') | ||
for (const [i, url] of urls.entries()) { | ||
configs.push({ | ||
priority: i, | ||
provider: new ethers.providers.StaticJsonRpcProvider(url), | ||
}) | ||
} | ||
return new ethers.providers.FallbackProvider(configs) | ||
} | ||
return new ethers.providers.FallbackProvider(config) | ||
} |
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
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
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
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