Commit 86b34454 authored by Murphy Law's avatar Murphy Law Committed by GitHub

Merge pull request #2322 from Inphi/feat/dtl-auth-config

dtl: Support Basic Authentication for RPC endpoints
parents 17b11bee 2163f1a9
---
'@eth-optimism/data-transport-layer': patch
---
dtl: Support basic authentication for RPC endpoints
...@@ -55,9 +55,13 @@ Here's the list of environment variables you can change: ...@@ -55,9 +55,13 @@ Here's the list of environment variables you can change:
| DATA_TRANSPORT_LAYER__SERVER_PORT | 7878 | Port to run the API on. | | DATA_TRANSPORT_LAYER__SERVER_PORT | 7878 | Port to run the API on. |
| DATA_TRANSPORT_LAYER__SYNC_FROM_L1 | true | Whether or not to sync from L1. | | DATA_TRANSPORT_LAYER__SYNC_FROM_L1 | true | Whether or not to sync from L1. |
| DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT | - | RPC endpoint for an L1 node. | | DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT | - | RPC endpoint for an L1 node. |
| DATA_TRANSPORT_LAYER__L1_RPC_USER | - | Basic Authentication user for the L1 node endpoint. |
| DATA_TRANSPORT_LAYER__L1_RPC_PASSWORD | - | Basic Authentication password for the L1 node endpoint. |
| DATA_TRANSPORT_LAYER__LOGS_PER_POLLING_INTERVAL | 2000 | Logs to sync per polling interval. | | DATA_TRANSPORT_LAYER__LOGS_PER_POLLING_INTERVAL | 2000 | Logs to sync per polling interval. |
| DATA_TRANSPORT_LAYER__SYNC_FROM_L2 | false | Whether or not to sync from L2. | | DATA_TRANSPORT_LAYER__SYNC_FROM_L2 | false | Whether or not to sync from L2. |
| DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT | - | RPC endpoint for an L2 node. | | DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT | - | RPC endpoint for an L2 node. |
| DATA_TRANSPORT_LAYER__L2_RPC_USER | - | Basic Authentication user for the L2 node endpoint. |
| DATA_TRANSPORT_LAYER__L2_RPC_PASSWORD | - | Basic Authentication password for the L2 node endpoint. |
| DATA_TRANSPORT_LAYER__TRANSACTIONS_PER_POLLING_INTERVAL | 1000 | Number of L2 transactions to query per polling interval. | | DATA_TRANSPORT_LAYER__TRANSACTIONS_PER_POLLING_INTERVAL | 1000 | Number of L2 transactions to query per polling interval. |
| DATA_TRANSPORT_LAYER__L2_CHAIN_ID | - | L2 chain ID. | | DATA_TRANSPORT_LAYER__L2_CHAIN_ID | - | L2 chain ID. |
| DATA_TRANSPORT_LAYER__LEGACY_SEQUENCER_COMPATIBILITY | false | Whether or not to enable "legacy" sequencer sync (without the custom `eth_getBlockRange` endpoint) | | DATA_TRANSPORT_LAYER__LEGACY_SEQUENCER_COMPATIBILITY | false | Whether or not to enable "legacy" sequencer sync (without the custom `eth_getBlockRange` endpoint) |
......
/* Imports: External */ /* Imports: External */
import { import { fromHexString, sleep } from '@eth-optimism/core-utils'
fromHexString,
FallbackProvider,
sleep,
} from '@eth-optimism/core-utils'
import { BaseService, Metrics } from '@eth-optimism/common-ts' import { BaseService, Metrics } from '@eth-optimism/common-ts'
import { TypedEvent } from '@eth-optimism/contracts/dist/types/common' import { TypedEvent } from '@eth-optimism/contracts/dist/types/common'
import { BaseProvider } from '@ethersproject/providers' import { BaseProvider, StaticJsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup' import { LevelUp } from 'levelup'
import { constants } from 'ethers' import { constants } from 'ethers'
import { Gauge, Counter } from 'prom-client' import { Gauge, Counter } from 'prom-client'
...@@ -114,8 +110,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -114,8 +110,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.l1IngestionMetrics = registerMetrics(this.metrics) this.l1IngestionMetrics = registerMetrics(this.metrics)
if (typeof this.options.l1RpcProvider === 'string') { if (typeof this.options.l1RpcProvider === 'string') {
this.state.l1RpcProvider = FallbackProvider(this.options.l1RpcProvider, { this.state.l1RpcProvider = new StaticJsonRpcProvider({
'User-Agent': 'data-transport-layer', url: this.options.l1RpcProvider,
user: this.options.l1RpcProviderUser,
password: this.options.l1RpcProviderPassword,
headers: { 'User-Agent': 'data-transport-layer' },
}) })
} else { } else {
this.state.l1RpcProvider = this.options.l1RpcProvider this.state.l1RpcProvider = this.options.l1RpcProvider
......
...@@ -93,6 +93,8 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> { ...@@ -93,6 +93,8 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {
typeof this.options.l2RpcProvider === 'string' typeof this.options.l2RpcProvider === 'string'
? new StaticJsonRpcProvider({ ? new StaticJsonRpcProvider({
url: this.options.l2RpcProvider, url: this.options.l2RpcProvider,
user: this.options.l2RpcProviderUser,
password: this.options.l2RpcProviderPassword,
headers: { 'User-Agent': 'data-transport-layer' }, headers: { 'User-Agent': 'data-transport-layer' },
}) })
: this.options.l2RpcProvider : this.options.l2RpcProvider
......
...@@ -20,8 +20,12 @@ export interface L1DataTransportServiceOptions { ...@@ -20,8 +20,12 @@ export interface L1DataTransportServiceOptions {
dangerouslyCatchAllErrors?: boolean dangerouslyCatchAllErrors?: boolean
hostname: string hostname: string
l1RpcProvider: string l1RpcProvider: string
l1RpcProviderUser?: string
l1RpcProviderPassword?: string
l2ChainId: number l2ChainId: number
l2RpcProvider: string l2RpcProvider: string
l2RpcProviderUser?: string
l2RpcProviderPassword?: string
metrics?: Metrics metrics?: Metrics
dbPath: string dbPath: string
logsPerPollingInterval: number logsPerPollingInterval: number
......
...@@ -26,6 +26,8 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli' ...@@ -26,6 +26,8 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
hostname: config.str('server-hostname', 'localhost'), hostname: config.str('server-hostname', 'localhost'),
confirmations: config.uint('confirmations', 35), confirmations: config.uint('confirmations', 35),
l1RpcProvider: config.str('l1-rpc-endpoint'), l1RpcProvider: config.str('l1-rpc-endpoint'),
l1RpcProviderUser: config.str('l1-rpc-user'),
l1RpcProviderPassword: config.str('l1-rpc-password'),
addressManager: config.str('address-manager'), addressManager: config.str('address-manager'),
pollingInterval: config.uint('polling-interval', 5000), pollingInterval: config.uint('polling-interval', 5000),
logsPerPollingInterval: config.uint('logs-per-polling-interval', 2000), logsPerPollingInterval: config.uint('logs-per-polling-interval', 2000),
...@@ -34,6 +36,8 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli' ...@@ -34,6 +36,8 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
false false
), ),
l2RpcProvider: config.str('l2-rpc-endpoint'), l2RpcProvider: config.str('l2-rpc-endpoint'),
l2RpcProviderUser: config.str('l2-rpc-user'),
l2RpcProviderPassword: config.str('l2-rpc-password'),
l2ChainId: config.uint('l2-chain-id'), l2ChainId: config.uint('l2-chain-id'),
syncFromL1: config.bool('sync-from-l1', true), syncFromL1: config.bool('sync-from-l1', true),
syncFromL2: config.bool('sync-from-l2', false), syncFromL2: config.bool('sync-from-l2', false),
......
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