optimism icon indicating copy to clipboard operation
optimism copied to clipboard

batcher: keep blocks, channels and frames in strict order & simplify reorg handling

Open geoknee opened this issue 1 year ago • 0 comments

Closes https://github.com/ethereum-optimism/optimism/issues/12123

Design doc https://www.notion.so/oplabs/op-batcher-re-architecture-114f153ee162803d943ff4628ab6578f?pvs=4

Changes (at the reviewer's request I could split this PR up):

  1. Use the op-service/queue type in a couple more places in the batcher
  2. Introduce cursors and reduce the amount of queue operations so that we can be sure things stay in order
  3. Simplify reorg handling (it was causing the channel queue to be spliced up which is contrary to the aims of (2))

From the issue:

We should check

  • [x] normal operation always enqueues blocks inside in order {This was already the case, but now we only ever enqueue and dequeue, never prepend blocks).
  • [x] keeps channels in the channel queue in order (We now only ever enqueue, dequeue or delete from the back of the queue in a way which preserves the order -- by rewinding the block cursor)
  • [x] sends transactions in order (This was already true, the txmgr has a queue which we add txs to in order)
  • [x] also frames within blob transactions in order (This was already true, frames are appended to the transaction in order)
  • [x] reorg case (We were already clearing out the batcher's state and starting again when detecting this. Continuing to do that, only now we don't bother finishing any tx submission work before doing so)
  • [x] re-queueing case when a channel fails to submit in time -> need to preserver order across channels (also future pending) (When this happens, we now clear out the channel queue and rewind the block cursor to point at the first block of the timed out channel).
  • [x] re-queueing case when da-type changes (This was already OK, but now simplified to make it clear we only ever operate with a single channel, the current channel). Again we rewind the block cursor so that the blocks can be reprocessed).

geoknee avatar Oct 09 '24 14:10 geoknee