The new implementation is event-driven which causes the code not readable. This document is to help understand the codebase and the flow of the code.
[TOC]
The Driver is the entry point of derivation. The core function is eventLoop which is a loop to handle channels, the
external inputs will pass through the channels.
Once any channel is ready, the eventLoop will call the corresponding function to handle the input.
The inputs are actually L1 blocks and L2 unsafe blocks.
OnNewL1Headis to subscribing the latest L1 header.OnNewL1Safeis to polling the latest L1 safe block.OnNewL1Finalizedis to polling the latest L1 finalized block.OnUnsafeL2Payloadis to handle the unsafe L2 block.
Driver use channels to communicate with other components. However, the internal components are communicating with
events. There are several internal drivers to handle different functionalities.
The derivation is the core driver to handle the L1 blocks to derive the L2 blocks. It is a pipeline which consists of several stages. Each stage is a function to handle the L1 block and derive the L2 block.
When PipelineDeriver receives the PipelineStepEvent, it will call the Step function to trigger the pipeline.
But how the PipelineStepEvent is emitted? We go back to the eventLoop function of the Driver to find the answer.
- There is a
reqStepfunction to request a derivation step. It will first emit theStepReqEvent, through theStepSchedulingDeriverto transform the request to theStepAttemptEvent, and eventually to theStepEvent. TheStepSchedulingDeriverwill schedule the step request based on the backoff strategy. - The
StepEventwill be handled by theSyncDeriverwhich responsible for the synchronization of theopNodeandexecution enginestatus which are header, safe, finalized block. It will callSyncStepfunction, first drain the remaining events, then synchronization withexecution engine. Ifexecution engineis ready, it will emit thePendingSafeRequestEventwhich notifyAttributesHandlerto handle. Otherwise, it will triggerResetStepBackoffEventand some error events will be triggered.SyncDeriverwill handle the error events and trigger theStepReqEventagain. - The
EngDeriverwill transform thePendingSafeRequestEventto thePendingSafeUpdateEvent,AttributesHandlerwill handle thePendingSafeUpdateEventand when no attributes are handling, it will emitPipelineStepEvent.
TODO:
https://docs.optimism.io/stack/protocol/outages
-
There is no depositTx in batch,
op-batcherwill filter deposit txs before submitting to L1 -
Both verifier and sequencer get deposit txs from L1 contract.
-
If sequencer downtime is enough long, the verifier will force produce empty batch, and add deposit txs to generate L2 block
-
When sequencer is backup from a long downtime(verifier already create empty batch), it will also catch up verifier first(create empty batch), after that, it can sequence new batch again. If it create new batch before catch up verifier, the verifier will drop these batches.