Commit 81c1cd99 authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix(dtl): consistency checks for L1 sync (#3356)

Adds consistency checks for L1 syncing nodes in the DTL. One of my
personal nodes seemed to halt with this error, so fixing it.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 5d86ff0e
---
'@eth-optimism/data-transport-layer': patch
---
Adds consistency checks for transaction entries in L1 syncing nodes
...@@ -2,6 +2,7 @@ export type EventName = ...@@ -2,6 +2,7 @@ export type EventName =
| 'TransactionEnqueued' | 'TransactionEnqueued'
| 'SequencerBatchAppended' | 'SequencerBatchAppended'
| 'StateBatchAppended' | 'StateBatchAppended'
| 'SequencerBatchAppendedTransaction'
export class MissingElementError extends Error { export class MissingElementError extends Error {
constructor(public name: EventName) { constructor(public name: EventName) {
......
...@@ -206,6 +206,21 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet< ...@@ -206,6 +206,21 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
} }
} }
// Same consistency checks but for transaction entries.
if (
entry.transactionEntries.length > 0 &&
entry.transactionEntries[0].index > 0
) {
const prevTransactionEntry = await db.getTransactionByIndex(
entry.transactionEntries[0].index - 1
)
// We should *always* have a previous transaction here.
if (prevTransactionEntry === null) {
throw new MissingElementError('SequencerBatchAppendedTransaction')
}
}
await db.putTransactionEntries(entry.transactionEntries) await db.putTransactionEntries(entry.transactionEntries)
// Add an additional field to the enqueued transactions in the database // Add an additional field to the enqueued transactions in the database
......
...@@ -277,6 +277,8 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> { ...@@ -277,6 +277,8 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
const handlers = { const handlers = {
SequencerBatchAppended: SequencerBatchAppended:
this.state.db.getLatestTransactionBatch.bind(this.state.db), this.state.db.getLatestTransactionBatch.bind(this.state.db),
SequencerBatchAppendedTransaction:
this.state.db.getLatestTransaction.bind(this.state.db),
StateBatchAppended: this.state.db.getLatestStateRootBatch.bind( StateBatchAppended: this.state.db.getLatestStateRootBatch.bind(
this.state.db this.state.db
), ),
......
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