Documentation for Worker Loop in the EigenLayer-AVS system.
The Worker Loop is the central operational component of the EigenLayer-AVS Operator. It manages the continuous monitoring of trigger conditions, communicates with the Aggregator service, and handles task notifications. This document explains the Worker Loop's architecture, initialization process, and primary operational flows.
For information about the Operator's registration process with EigenLayer, see Registration and Aliasing. For details on specific trigger implementations, see Trigger Engines.
Sources:
The Worker Loop coordinates several interconnected components to enable operators to monitor events and notify the Aggregator when tasks need to be executed. Below is the high-level architecture:
The Worker Loop consists of these key components:
runWorkLoop): Orchestrates all activities and processes trigger events.StreamMessages): Maintains a gRPC connection to receive task updates.PingServer): Periodically checks in with the Aggregator.Sources:
When the Operator starts, the Worker Loop initializes all necessary components:
Key initialization steps:
PingServer task to run every 5 seconds.The event trigger is optional and only started if explicitly enabled in the configuration.
Sources:
The StreamMessages function establishes and maintains a persistent gRPC connection with the Aggregator to receive task updates:
The streaming process involves:
SyncMessages gRPC stream with the Aggregator.When processing messages, the function handles different operations based on the MessageOp type:
CancelTask/DeleteTask: Removes the task from monitoringMonitorTaskTrigger: Adds the task to the appropriate trigger engine based on its typeSources:
The main work loop continuously monitors the trigger channels and notifies the Aggregator when trigger conditions are met:
Each trigger type has specific data associated with it:
Time Trigger: Monitors time-based conditions (cron expressions or fixed times)
TriggerReason_Cron typeBlock Trigger: Monitors for specific blockchain blocks
TriggerReason_Block typeEvent Trigger: Monitors for specific smart contract events
TriggerReason_Event typeWhen a trigger condition is met, the Worker Loop sends a NotifyTriggers RPC call to the Aggregator with the task ID and relevant trigger information.
Sources:
The Worker Loop schedules a periodic ping to the Aggregator to maintain connection and report status:
The ping operation:
Metrics Update: Increments loop counter and adds uptime metrics
Authentication: Generates a BLS signature for request authentication
Status Report: Sends status information including:
Metrics Collection: Records ping success/failure and duration
The ping serves as both a heartbeat and a status reporting mechanism, allowing the Aggregator to track operator health and progress.
Sources:
The Worker Loop implements robust error handling to maintain continuous operation:
| Scenario | Handling Mechanism | Location |
|---|---|---|
| Initial connection failure | Retry with 15-second delay | operator/worker_loop.go161-166 |
| Stream disconnection | Return to connection loop with 15-second delay | operator/worker_loop.go174-177 |
| Trigger notification failure | Log error but continue operation | operator/worker_loop.go94-96 110-112 129-131 |
| Metrics server error | Fatal error (exits application) | operator/worker_loop.go132-134 |
The reconnection process uses the retryConnect method from the Operator to re-establish the gRPC connection with appropriate authentication credentials.
Sources:
The Worker Loop integrates with three types of trigger engines, each monitoring different conditions:
Key integration points:
The specific implementation of each trigger engine is detailed in the Trigger Engines documentation.
Sources:
The Worker Loop is designed with performance in mind:
StreamMessages function runs in a separate goroutine to avoid blocking the main loop.When implementing or modifying the Worker Loop, consider these performance aspects to maintain efficient operation.
Sources:
Feature this wiki to auto refresh weekly