kona-derive crate is integrated and used within the kona-node architecture.
Overview
The derivation subsystem in kona-node is built around the DerivationActor, which manages the derivation pipeline lifecycle and coordinates with other node components. The actor uses the trait-abstractedkona-derive pipeline to continuously process L1 data and produce L2 payload attributes.
Key Components
- DerivationActor: The main actor responsible for running the derivation pipeline
- OnlinePipeline: A concrete implementation of the derivation pipeline using online providers
- PipelineBuilder: Trait for constructing derivation pipelines with different configurations
- DerivationState: Manages pipeline state and stepping logic
- Signal System: Handles pipeline resets, hardfork activations, and error conditions
Architecture
DerivationActor
TheDerivationActor is a NodeActor that runs as part of the node service. It receives messages from other actors and steps the derivation pipeline forward to produce new payload attributes.
- Engine Actor: Receives payload attributes for execution and sends safe head updates
- P2P Actors: Receives L1 head updates from the network
- RPC Actors: May trigger pipeline resets or provide status information
Pipeline Construction
The derivation pipeline is constructed using theDerivationBuilder which implements the PipelineBuilder trait:
OnlinePipeline which can operate in two modes:
- Polled Mode: Uses
PollingTraversalfor L1 block traversal - Indexed Mode: Uses
IndexedTraversalfor more efficient L1 block handling
Provider Configuration
The node uses caching providers to optimize performance:- AlloyChainProvider: Provides L1 blockchain data with configurable cache size
- AlloyL2ChainProvider: Provides L2 blockchain data and system configuration
- OnlineBlobProvider: Retrieves blob data from the beacon chain for post-4844 transactions
Pipeline Operation
Main Processing Loop
The derivation actor runs a continuous loop that handles various events:- Shutdown signals: Graceful shutdown when cancellation token is triggered
- L1 head updates: Triggers derivation when new L1 blocks are available
- Safe head updates: Triggers derivation when the L2 safe head advances
- Pipeline signals: Handles resets, hardfork activations, and channel flushes
Stepping Logic
The core derivation logic is implemented inproduce_next_attributes():
- Step the pipeline with the current L2 safe head
- Handle step results:
PreparedAttributes: Attributes are ready to be consumedAdvancedOrigin: Pipeline advanced to next L1 blockOriginAdvanceErr/StepFailed: Handle various error conditions
- Return attributes when available
Error Handling
The derivation actor handles three categories of pipeline errors:Temporary Errors
PipelineError::NotEnoughData: Continue stepping, more data may become availablePipelineError::Eof: Yield and wait for more L1 data
Reset Errors
ResetError::HoloceneActivation: SendActivationSignalto handle hardforkResetError::ReorgDetected: Send reset request to engine (if not in interop mode)- Other reset errors: Wait for external signal before continuing
Critical Errors
- Unrecoverable errors that terminate the derivation process
- Increment metrics counter and propagate error up
Signal Handling
The pipeline supports several signal types for coordination:- ResetSignal: Resets pipeline state with new L1 origin and system config
- ActivationSignal: Handles hardfork activations (e.g., Holocene)
- FlushChannel: Invalidates current channel data for deposit-only blocks
Configuration
Rollup Configuration
The derivation pipeline requires aRollupConfig that defines:
- Chain parameters (chain ID, block time, etc.)
- Hardfork activation heights
- System configuration addresses
- Batch and channel parameters
Runtime Configuration
Runtime configuration includes:- Provider cache sizes
- Polling intervals for L1 data
- Interop mode selection
- Metrics collection settings
Integration Patterns
With Engine Actor
The derivation actor producesOpAttributesWithParent that are sent to the engine actor for execution:
With P2P Layer
The derivation actor receives L1 head updates from the P2P layer, which indicate when new L1 data is available for processing:With RPC Layer
The RPC layer can query derivation status and potentially trigger pipeline operations through the standard node RPC interface.Metrics and Observability
The derivation actor exposes several metrics for monitoring:DERIVATION_L1_ORIGIN: Current L1 origin block numberDERIVATION_CRITICAL_ERROR: Count of critical derivation errorsL1_REORG_COUNT: Count of detected L1 reorganizations