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.
OnNewL1Head
is to subscribing the latest L1 header.OnNewL1Safe
is to polling the latest L1 safe block.OnNewL1Finalized
is to polling the latest L1 finalized block.OnUnsafeL2Payload
is 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
reqStep
function to request a derivation step. It will first emit theStepReqEvent
, through theStepSchedulingDeriver
to transform the request to theStepAttemptEvent
, and eventually to theStepEvent
. TheStepSchedulingDeriver
will schedule the step request based on the backoff strategy. - The
StepEvent
will be handled by theSyncDeriver
which responsible for the synchronization of theopNode
andexecution engine
status which are header, safe, finalized block. It will callSyncStep
function, first drain the remaining events, then synchronization withexecution engine
. Ifexecution engine
is ready, it will emit thePendingSafeRequestEvent
which notifyAttributesHandler
to handle. Otherwise, it will triggerResetStepBackoffEvent
and some error events will be triggered.SyncDeriver
will handle the error events and trigger theStepReqEvent
again. - The
EngDeriver
will transform thePendingSafeRequestEvent
to thePendingSafeUpdateEvent
,AttributesHandler
will handle thePendingSafeUpdateEvent
and when no attributes are handling, it will emitPipelineStepEvent
.
TODO:
https://docs.optimism.io/stack/protocol/outages
-
There is no depositTx in batch,
op-batcher
will 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.