Expand description
§kona-engine
An extensible implementation of the OP Stack rollup node engine client.
§Overview
The kona-engine crate provides a task-based engine client for interacting with Ethereum execution layers. It implements the Engine API specification and manages the execution layer state through a priority-driven task queue system.
§Key Components
Engine- Main task queue processor that executes engine operations atomicallyEngineClient- HTTP client for Engine API communication with JWT authenticationEngineState- Tracks the current state of the execution layer- Task Types - Specialized tasks for different engine operations:
InsertTask- Insert new payloads into the execution engineBuildTask- Build new payloads with automatic forkchoice synchronizationConsolidateTask- Consolidate unsafe payloads to advance the safe chainFinalizeTask- Finalize safe payloads on L1 confirmationSynchronizeTask- Internal task for execution layer forkchoice synchronization
§Architecture
The engine implements a task-driven architecture where forkchoice synchronization is handled automatically:
- Automatic Forkchoice Handling: The
BuildTaskautomatically performs forkchoice updates during block building, eliminating the need for explicit forkchoice management in user code. - Internal Synchronization:
SynchronizeTaskhandles internal execution layer synchronization and is primarily used by other tasks rather than directly by users. - Priority-Based Execution: Tasks are executed in priority order to ensure optimal sequencer performance and block processing efficiency.
§Usage
use kona_engine::{Engine, EngineClient, EngineState};
use kona_genesis::RollupConfig;
use alloy_rpc_types_engine::JwtSecret;
use url::Url;
use std::sync::Arc;
// Create an engine client
let engine_url = Url::parse("http://localhost:8551")?;
let l1_url = Url::parse("http://localhost:8545")?;
let config = Arc::new(RollupConfig::default());
let jwt = JwtSecret::from_hex("0xabcd")?;
let client = EngineClient::new_http(engine_url, l1_url, config, jwt);
// Initialize engine state
let state = EngineState::default();
// Create task queue watchers
let (state_sender, _) = tokio::sync::watch::channel(state);
let (queue_sender, _) = tokio::sync::watch::channel(0);
// Create the engine
let engine = Engine::new(state, state_sender, queue_sender);§Engine API Compatibility
The crate supports multiple Engine API versions with automatic version selection based on the rollup configuration:
- Engine Forkchoice Updated: V2, V3
- Engine New Payload: V2, V3, V4
- Engine Get Payload: V2, V3, V4
Version selection follows Optimism hardfork activation times (Bedrock, Canyon, Delta, Ecotone, Isthmus).
§Features
metrics- Enable Prometheus metrics collection (optional)
§Architecture
The engine operates as a task-driven system where operations are queued and executed atomically:
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Engine │◄───┤ Task Queue │◄───┤ Engine │
│ Client │ │ (Priority) │ │ Tasks │
└─────────────┘ └──────────────┘ └─────────────┘
│ │ │
▼ ▼ ▼
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Engine API │ │ Engine State │ │ Rollup │
│ (HTTP/JWT) │ │ Updates │ │ Config │
└─────────────┘ └──────────────┘ └─────────────┘§Module Organization
- Task Queue - Core engine task queue and execution logic via
Engine - Client - HTTP client for Engine API communication via
EngineClient - State - Engine state management and synchronization via
EngineState - Versions - Engine API version selection via
EngineForkchoiceVersion,EngineNewPayloadVersion,EngineGetPayloadVersion - Attributes - Payload attribute validation via
AttributesMatch - Kinds - Engine client type identification via
EngineKind - Query - Engine query interface via
EngineQueries - Metrics - Optional Prometheus metrics collection via
Metrics
Structs§
- Build
Task - Task for building new blocks with automatic forkchoice synchronization.
- Consolidate
Task - The
ConsolidateTaskattempts to consolidate the engine state using the specified payload attributes and the oldest unsafe head. - Engine
- The
Enginetask queue. - Engine
Client - An Engine API client that provides authenticated HTTP communication with an execution layer.
- Engine
State - The chain state viewed by the engine controller.
- Engine
Sync State - The synchronization state of the execution layer across different safety levels.
- Engine
Sync State Update - Specifies how to update the sync state of the engine.
- Finalize
Task - The
FinalizeTaskfetches theL2BlockInfoatblock_number, updates theEngineState, and dispatches a forkchoice update to finalize the block. - Insert
Task - The task to insert a payload into the execution engine.
- Metrics
- Metrics container with constants for Prometheus metric collection.
- Synchronize
Task - Internal task for execution layer forkchoice synchronization.
Enums§
- Attributes
Match - Result of validating payload attributes against an execution layer block.
- Attributes
Mismatch - An enum over the type of mismatch between
OpAttributesWithParentand aBlock. - Build
Task Error - An error that occurs when running the crate::SynchronizeTask.
- Consolidate
Task Error - An error that occurs when running the
crate::ConsolidateTask. - Engine
Build Error - An error that occurs during payload building within the engine.
- Engine
Client Error - An error that occurred in the
EngineClient. - Engine
Forkchoice Version - Engine API version for
engine_forkchoiceUpdatedmethod calls. - Engine
GetPayload Version - Engine API version for
engine_getPayloadmethod calls. - Engine
Kind - Identifies the type of execution layer client for behavior customization.
- Engine
NewPayload Version - Engine API version for
engine_newPayloadmethod calls. - Engine
Queries - Query types supported by the engine for external communication.
- Engine
Queries Error - An error that can occur when querying the engine.
- Engine
Reset Error - An error occurred while attempting to reset the
Engine. - Engine
Task - Tasks that may be inserted into and executed by the
Engine. - Engine
Task Error Severity - The severity of an engine task error.
- Engine
Task Errors - An error that may occur during an
EngineTask’s execution. - Finalize
Task Error - An error that occurs when running the crate::FinalizeTask.
- Insert
Task Error - An error that occurs when running the InsertTask.
- Synchronize
Task Error - An error that occurs when running the crate::SynchronizeTask.
Traits§
- Engine
Task Error - The interface for an engine task error.
- Engine
Task Ext - The interface for an engine task.
Type Aliases§
- Engine
Query Sender - Channel sender for submitting
EngineQueriesto the engine.