Expand description
Execution extensions (ExEx
).
An execution extension is a task that listens to state changes of the node.
Some examples of such state derives are rollups, bridges, and indexers.
An ExEx
is a Future
resolving to a Result<()>
that is run indefinitely alongside the
node.
ExEx
’s are initialized using an async closure that resolves to the ExEx
; this closure gets
passed an ExExContext
where it is possible to spawn additional tasks and modify Reth.
Most ExEx
’s will want to derive their state from the CanonStateNotification
channel given
in ExExContext
. A new notification is emitted whenever blocks are executed in live and
historical sync.
§Pruning
ExEx
’s SHOULD emit an ExExEvent::FinishedHeight
event to signify what blocks have been
processed. This event is used by Reth to determine what state can be pruned.
An ExEx
will only receive notifications for blocks greater than the block emitted in the
event. To clarify: if the ExEx
emits ExExEvent::FinishedHeight(0)
it will receive
notifications for any block_number > 0
.
§Examples, Assumptions, and Invariants
§Examples
§Simple Indexer ExEx
use alloy_consensus::BlockHeader;
use futures::StreamExt;
use reth_exex::ExExContext;
use reth_node_api::FullNodeComponents;
use reth_provider::CanonStateNotification;
async fn my_indexer<N: FullNodeComponents>(
mut ctx: ExExContext<N>,
) -> Result<(), Box<dyn std::error::Error>> {
// Subscribe to canonical state notifications
while let Some(Ok(notification)) = ctx.notifications.next().await {
if let Some(committed) = notification.committed_chain() {
for block in committed.blocks_iter() {
// Index or process block data
println!("Processed block: {}", block.number());
}
// Signal completion for pruning
ctx.send_finished_height(committed.tip().num_hash());
}
}
Ok(())
}
§Assumptions
ExExs
run indefinitely alongside RethExExs
receive canonical state notifications for block executionExExs
should handle potential network or database errors gracefullyExExs
must emitFinishedHeight
events for proper state pruning
§Invariants
- An ExEx must not block the main Reth execution
- Notifications are processed in canonical order
ExExs
should be able to recover from temporary failures- Memory and resource usage must be controlled
§Performance Considerations
- Minimize blocking operations
- Use efficient data structures for state tracking
- Implement proper error handling and logging
- Consider batching operations for better performance
Modules§
- serde_
bincode_ compat serde
andserde-bincode-compat
- Bincode-compatible serde implementations for commonly used ExEx types.
Structs§
- Backfill
Job - Backfill job started for a specific range.
- Backfill
JobFactory - Factory for creating new backfill jobs.
- Block
Cache - The block cache of the WAL.
- ExEx
Context - Captures the context that an
ExEx
has access to. - ExEx
Context Dyn - Captures the context that an
ExEx
has access to. - ExEx
Handle - A handle to an
ExEx
used by theExExManager
to communicate withExEx
’s. - ExEx
Head - A head of the ExEx. It contains the highest host block committed to the internal ExEx state. I.e. the latest block that the ExEx has fully processed.
- ExEx
Manager - The execution extension manager.
- ExEx
Manager Handle - A handle to communicate with the
ExExManager
. - ExEx
Manager Metrics - Metrics for the
ExEx
manager. - ExEx
Notifications - A stream of
ExExNotification
s. The stream will emit notifications for all blocks. If the stream is configured with a head viaExExNotifications::set_with_head
orExExNotifications::with_head
, it will run backfill jobs to catch up to the node head. - ExEx
Notifications With Head - A stream of
ExExNotification
s. The stream will only emit notifications for blocks that are committed or reverted after the given head. The head is the ExEx’s latest view of the host chain. - ExEx
Notifications Without Head - A stream of
ExExNotification
s. The stream will emit notifications for all blocks. - Single
Block Backfill Job - Single block Backfill job started for a specific range.
- Storage
- The underlying WAL storage backed by a directory of files.
- Stream
Backfill Job - Stream for processing backfill jobs asynchronously.
- Wal
- WAL is a write-ahead log (WAL) that stores the notifications sent to ExExes.
- WalHandle
- A read-only handle to the WAL that can be shared.
Enums§
- ExEx
Event - Events emitted by an
ExEx
. - ExEx
Notification - Notifications sent to an
ExEx
. - ExEx
Notification Source - The source of the notification.
- Finished
ExEx Height - The finished height of all
ExEx
’s. - WalError
- Wal Error types
Constants§
- DEFAULT_
EXEX_ MANAGER_ CAPACITY - Default max size of the internal state notifications buffer.
- WAL_
BLOCKS_ WARNING - The maximum number of blocks allowed in the WAL before emitting a warning.
Traits§
- ExEx
Notifications Stream - A trait, that represents a stream of
ExExNotification
s. The stream will emit notifications for all blocks. If the stream is configured with a head viaExExNotifications::set_with_head
orExExNotifications::with_head
, it will run backfill jobs to catch up to the node head.
Type Aliases§
- WalResult
- Wal Result type.