Skip to content

Commit

Permalink
dtl: config for starting L1 block number
Browse files Browse the repository at this point in the history
Adds the config option `DATA_TRANSPORT_LAYER_STARTING_L1_BLOCK_NUMBER`
or `--starting-l1-blocknumber` that allows for the user to specify
the L1 blocknumber to begin syncing from. This prevents users from
syncing old batches from a previous regenesis.
  • Loading branch information
tynes committed Oct 27, 2021
1 parent 0b89338 commit d83daf9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-coins-poke.md
@@ -0,0 +1,5 @@
---
'@eth-optimism/data-transport-layer': patch
---

Add config for L1 start height to allow for syncing specifically after a regenesis. Using the auto detect method will not work with the regenesis scheme of using the same AddressManager
35 changes: 23 additions & 12 deletions packages/data-transport-layer/src/services/l1-ingestion/service.ts
Expand Up @@ -152,21 +152,32 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.options.addressManager
)

const startingL1BlockNumber = await this.state.db.getStartingL1Block()
if (startingL1BlockNumber) {
this.state.startingL1BlockNumber = startingL1BlockNumber
} else {
this.logger.info(
'Attempting to find an appropriate L1 block height to begin sync...'
)
this.state.startingL1BlockNumber = await this._findStartingL1BlockNumber()
this.logger.info('Starting sync', {
startingL1BlockNumber: this.state.startingL1BlockNumber,
})
// Look up in the database for an indexed starting L1 block
let startingL1BlockNumber = await this.state.db.getStartingL1Block()
// If there isn't an indexed starting L1 block, that means we should pull it
// from config and then fallback to discovering it
if (startingL1BlockNumber === null || startingL1BlockNumber === undefined) {
if (this.options.l1StartHeight !== null && this.options.l1StartHeight !== undefined) {
startingL1BlockNumber = this.options.l1StartHeight
} else {
this.logger.info(
'Attempting to find an appropriate L1 block height to begin sync...'
)
startingL1BlockNumber = await this._findStartingL1BlockNumber()
}
}

await this.state.db.setStartingL1Block(this.state.startingL1BlockNumber)
if (!startingL1BlockNumber) {
throw new Error('Cannot find starting L1 block number')
}

this.logger.info('Starting sync', {
startingL1BlockNumber,
})

this.state.startingL1BlockNumber = startingL1BlockNumber
await this.state.db.setStartingL1Block(this.state.startingL1BlockNumber)

// Store the total number of submitted transactions so the server can tell clients if we're
// done syncing or not
const totalElements =
Expand Down
1 change: 1 addition & 0 deletions packages/data-transport-layer/src/services/main/service.ts
Expand Up @@ -35,6 +35,7 @@ export interface L1DataTransportServiceOptions {
sentryTraceRate?: number
defaultBackend: string
l1GasPriceBackend: string
l1StartHeight?: number
}

const optionSettings = {
Expand Down
1 change: 1 addition & 0 deletions packages/data-transport-layer/src/services/run.ts
Expand Up @@ -47,6 +47,7 @@ type ethNetwork = 'mainnet' | 'kovan' | 'goerli'
),
defaultBackend: config.str('default-backend', 'l1'),
l1GasPriceBackend: config.str('l1-gas-price-backend', 'l1'),
l1StartHeight: config.uint('l1-start-height'),
useSentry: config.bool('use-sentry', false),
sentryDsn: config.str('sentry-dsn'),
sentryTraceRate: config.ufloat('sentry-trace-rate', 0.05),
Expand Down

0 comments on commit d83daf9

Please sign in to comment.