Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/five-penguins-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@eth-optimism/builder': patch
'@eth-optimism/batch-submitter': patch
'@eth-optimism/core-utils': patch
'@eth-optimism/data-transport-layer': patch
'@eth-optimism/message-relayer': patch
'@eth-optimism/replica-healthcheck': patch
---

Add 'User-Agent' to the http headers for ethers providers
23 changes: 12 additions & 11 deletions packages/batch-submitter/src/exec/run-batch-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ export const run = async () => {
)

const getSequencerSigner = async (): Promise<Signer> => {
const l1Provider = new StaticJsonRpcProvider(
requiredEnvVars.L1_NODE_WEB3_URL
)
const l1Provider = new StaticJsonRpcProvider({
url: requiredEnvVars.L1_NODE_WEB3_URL,
headers: { 'User-Agent': 'batch-submitter' },
})

if (useHardhat) {
if (!DEBUG_IMPERSONATE_SEQUENCER_ADDRESS) {
Expand All @@ -166,9 +167,10 @@ export const run = async () => {
}

const getProposerSigner = async (): Promise<Signer> => {
const l1Provider = new StaticJsonRpcProvider(
requiredEnvVars.L1_NODE_WEB3_URL
)
const l1Provider = new StaticJsonRpcProvider({
url: requiredEnvVars.L1_NODE_WEB3_URL,
headers: { 'User-Agent': 'batch-submitter' },
})

if (useHardhat) {
if (!DEBUG_IMPERSONATE_PROPOSER_ADDRESS) {
Expand Down Expand Up @@ -205,10 +207,6 @@ export const run = async () => {
'min-gas-price-in-gwei',
parseInt(env.MIN_GAS_PRICE_IN_GWEI, 10) || 0
)
const MAX_GAS_PRICE_IN_GWEI = config.uint(
'max-gas-price-in-gwei',
parseInt(env.MAX_GAS_PRICE_IN_GWEI, 10) || 70
)
const GAS_RETRY_INCREMENT = config.uint(
'gas-retry-increment',
parseInt(env.GAS_RETRY_INCREMENT, 10) || 5
Expand Down Expand Up @@ -348,7 +346,10 @@ export const run = async () => {
const clearPendingTxs = requiredEnvVars.CLEAR_PENDING_TXS

const l2Provider = injectL2Context(
new StaticJsonRpcProvider(requiredEnvVars.L2_NODE_WEB3_URL)
new StaticJsonRpcProvider({
url: requiredEnvVars.L2_NODE_WEB3_URL,
headers: { 'User-Agent': 'batch-submitter' },
})
)

const sequencerSigner: Signer = await getSequencerSigner()
Expand Down
1 change: 1 addition & 0 deletions packages/core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@ethersproject/abstract-provider": "^5.4.1",
"@ethersproject/bytes": "^5.5.0",
"@ethersproject/providers": "^5.4.5",
"@ethersproject/web": "^5.5.0",
"chai": "^4.3.4",
"ethers": "^5.4.5",
"lodash": "^4.17.21"
Expand Down
18 changes: 16 additions & 2 deletions packages/core-utils/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import { ethers } from 'ethers'
import { Provider } from '@ethersproject/providers'
import { ConnectionInfo } from '@ethersproject/web'

export interface HttpHeaders {
[key: string]: string
}

// Copied from @ethersproject/providers since it is not
// currently exported
Expand All @@ -24,17 +29,26 @@ export interface FallbackProviderConfig {
weight?: number
}

export const FallbackProvider = (config: string | FallbackProviderConfig[]) => {
export const FallbackProvider = (
config: string | FallbackProviderConfig[],
headers?: HttpHeaders
) => {
const configs = []
// Handle the case of a string of comma delimited urls
if (typeof config === 'string') {
const urls = config.split(',')
for (const [i, url] of urls.entries()) {
const connectionInfo: ConnectionInfo = { url }
if (typeof headers === 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this if statement protect against?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It lets you not pass in the headers object without assigning undefined to the object, its more of a safety thing but i suppose the code is the same without it

connectionInfo.headers = headers
}
configs.push({
priority: i,
provider: new ethers.providers.StaticJsonRpcProvider(url),
provider: new ethers.providers.StaticJsonRpcProvider(connectionInfo),
})
}
return new ethers.providers.FallbackProvider(configs)
}

return new ethers.providers.FallbackProvider(config)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Imports: External */
import { fromHexString, FallbackProvider } from '@eth-optimism/core-utils'
import { BaseService, Metrics } from '@eth-optimism/common-ts'
import { StaticJsonRpcProvider, BaseProvider } from '@ethersproject/providers'
import { BaseProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup'
import { ethers, constants } from 'ethers'
import { constants } from 'ethers'
import { Gauge, Counter } from 'prom-client'

/* Imports: Internal */
Expand All @@ -20,7 +20,7 @@ import { handleEventsTransactionEnqueued } from './handlers/transaction-enqueued
import { handleEventsSequencerBatchAppended } from './handlers/sequencer-batch-appended'
import { handleEventsStateBatchAppended } from './handlers/state-batch-appended'
import { L1DataTransportServiceOptions } from '../main/service'
import { MissingElementError, EventName } from './handlers/errors'
import { MissingElementError } from './handlers/errors'

interface L1IngestionMetrics {
highestSyncedL1Block: Gauge<string>
Expand Down Expand Up @@ -108,7 +108,9 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.l1IngestionMetrics = registerMetrics(this.metrics)

if (typeof this.options.l1RpcProvider === 'string') {
this.state.l1RpcProvider = FallbackProvider(this.options.l1RpcProvider)
this.state.l1RpcProvider = FallbackProvider(this.options.l1RpcProvider, {
'User-Agent': 'data-transport-layer',
})
} else {
this.state.l1RpcProvider = this.options.l1RpcProvider
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export class L2IngestionService extends BaseService<L2IngestionServiceOptions> {

this.state.l2RpcProvider =
typeof this.options.l2RpcProvider === 'string'
? new StaticJsonRpcProvider(this.options.l2RpcProvider)
? new StaticJsonRpcProvider({
url: this.options.l2RpcProvider,
headers: { 'User-Agent': 'data-transport-layer' },
})
: this.options.l2RpcProvider
}

Expand Down
10 changes: 8 additions & 2 deletions packages/message-relayer/src/exec/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ const main = async () => {
throw new Error('Must pass L2_NODE_WEB3_URL')
}

const l2Provider = new providers.StaticJsonRpcProvider(L2_NODE_WEB3_URL)
const l1Provider = new providers.StaticJsonRpcProvider(L1_NODE_WEB3_URL)
const l2Provider = new providers.StaticJsonRpcProvider({
url: L2_NODE_WEB3_URL,
headers: { 'User-Agent': 'message-relayer' },
})
const l1Provider = new providers.StaticJsonRpcProvider({
url: L1_NODE_WEB3_URL,
headers: { 'User-Agent': 'message-relayer' },
})

let wallet: Wallet
if (L1_WALLET_KEY) {
Expand Down
10 changes: 8 additions & 2 deletions packages/replica-healthcheck/src/healthcheck-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class HealthcheckServer {
this.metrics = this.initMetrics()
this.server = this.initServer()
this.replicaProvider = injectL2Context(
new providers.StaticJsonRpcProvider(this.options.replicaRpcProvider)
new providers.StaticJsonRpcProvider({
url: this.options.replicaRpcProvider,
headers: { 'User-Agent': 'replica-healthcheck' },
})
)
if (this.options.checkTxWriteLatency) {
this.initTxLatencyCheck()
Expand Down Expand Up @@ -177,7 +180,10 @@ export class HealthcheckServer {

runSyncCheck = async () => {
const sequencerProvider = injectL2Context(
new providers.StaticJsonRpcProvider(this.options.sequencerRpcProvider)
new providers.StaticJsonRpcProvider({
url: this.options.sequencerRpcProvider,
headers: { 'User-Agent': 'replica-healthcheck' },
})
)

// Continuously loop while replica runs
Expand Down