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
196 changes: 0 additions & 196 deletions packages/rollup-core/src/app/data/consumers/block-batch-processor.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/rollup-core/src/app/data/consumers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './block-batch-submitter'
export * from './block-batch-processor'
export * from './l2-batch-creator'
export * from './l2-batch-submitter'
export * from './verifier'
55 changes: 55 additions & 0 deletions packages/rollup-core/src/app/data/consumers/l2-batch-creator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* External Imports */
import { getLogger, logError, ScheduledTask } from '@eth-optimism/core-utils'

/* Internal Imports */
import { DataService, L1BatchRecord } from '../../../types/data'

const log = getLogger('l2-batch-creator')

/**
* Polls the DB to create a batch of L2 Transactions, when one is ready.
*/
export class L2BatchCreator extends ScheduledTask {
constructor(
private readonly dataService: DataService,
periodMilliseconds = 10_000
) {
super(periodMilliseconds)
}

/**
* @inheritDoc
*
* Creates L2 batches from L2 Transactions in the DB, either when:
* 1. Unsubmitted & unverified transactions in the L2 tx DB match the oldest unverified L1 batch in size
* 2. Unsubmitted & unverified transactions in the L2 tx DB have multiple timestamps (multiple batches exist)
*
*/
public async runTask(): Promise<void> {
try {
const l1BatchRecord: L1BatchRecord = await this.dataService.getOldestUnverifiedL1TransactionBatch()
if (!l1BatchRecord) {
const l2OnlyBatchBuilt: number = await this.dataService.tryBuildL2OnlyBatch()
if (l2OnlyBatchBuilt !== undefined && l2OnlyBatchBuilt >= 0) {
log.debug(`L2-only batch with number ${l2OnlyBatchBuilt} was built!`)
}
return
}

const batchBuilt: number = await this.dataService.tryBuildL2BatchToMatchL1(
l1BatchRecord.batchNumber,
l1BatchRecord.batchSize
)
if (batchBuilt !== undefined && batchBuilt >= 0) {
log.debug(
`L2 batch to match L1 batch of size ${l1BatchRecord} was built. Batch number: ${batchBuilt}.`
)
return
}

log.debug(`No L2 batches built... sad.`)
} catch (e) {
logError(log, `Error running L2BatchCreator! Continuing...`, e)
}
}
}
70 changes: 70 additions & 0 deletions packages/rollup-core/src/app/data/consumers/l2-batch-submitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* External Imports */
import {
getLogger,
logError,
ScheduledTask,
} from '@eth-optimism/core-utils/build'

/* Internal Imports */
import { L1DataService } from '../../../types/data'
import { BlockBatches, L2NodeService } from '../../../types'

const log = getLogger('l2-batch-submitter')

/**
* Polls the database for new Rollup Transactions that were submitted to L1 that
* have not yet been processed by L2 and submits them one-by-one to L2.
*/
export class L2BatchSubmitter extends ScheduledTask {
constructor(
private readonly l1DataService: L1DataService,
private readonly l2NodeService: L2NodeService,
periodMilliseconds: number = 10_000
) {
super(periodMilliseconds)
}

/**
* @inheritDoc
*/
public async runTask(): Promise<void> {
let blockBatches: BlockBatches
try {
blockBatches = await this.l1DataService.getNextBatchForL2Submission()
} catch (e) {
logError(log, `Error fetching next batch for L2 submission!`, e)
return
}

if (!blockBatches) {
log.debug(`No batches ready for submission to L2.`)
return
}

try {
await this.l2NodeService.sendBlockBatches(blockBatches)
} catch (e) {
logError(
log,
`Error sending batch to BlockBatchSubmitter! Block Batches: ${JSON.stringify(
blockBatches
)}`,
e
)
return
}

try {
await this.l1DataService.markL1BatchSubmittedToL2(
blockBatches.batchNumber
)
} catch (e) {
logError(
log,
`Error marking L1 Batch as Submitted to L2. L1 Batch Number: ${blockBatches.batchNumber}`,
e
)
return
}
}
}
3 changes: 2 additions & 1 deletion packages/rollup-core/src/app/data/consumers/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
const log = getLogger('verifier')

/**
* Polls the DB for VerificationCandidates to ensure that L1 rollup state roots match L2 state roots.
* Polls the DB for VerificationCandidates to ensure that L1 rollup Txs match L2 Txs.
*
*/
export class Verifier extends ScheduledTask {
private static readonly ALERT_EVERY: number = 6
Expand Down
Loading