reth_optimism_flashblocks/
lib.rs

1//! A downstream integration of Flashblocks.
2
3#![doc(
4    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
5    html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
6    issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
7)]
8#![cfg_attr(docsrs, feature(doc_cfg))]
9#![cfg_attr(not(test), warn(unused_crate_dependencies))]
10
11use reth_primitives_traits::NodePrimitives;
12use std::sync::Arc;
13
14// Included to enable serde feature for OpReceipt type used transitively
15use reth_optimism_primitives as _;
16
17mod consensus;
18pub use consensus::FlashBlockConsensusClient;
19
20mod payload;
21pub use payload::{FlashBlock, PendingFlashBlock};
22
23mod sequence;
24pub use sequence::{FlashBlockCompleteSequence, FlashBlockPendingSequence};
25
26mod service;
27pub use service::{FlashBlockBuildInfo, FlashBlockService};
28
29mod worker;
30
31mod cache;
32
33#[cfg(test)]
34mod test_utils;
35
36mod ws;
37pub use ws::{WsConnect, WsFlashBlockStream};
38
39/// Receiver of the most recent [`PendingFlashBlock`] built out of [`FlashBlock`]s.
40///
41/// [`FlashBlock`]: crate::FlashBlock
42pub type PendingBlockRx<N> = tokio::sync::watch::Receiver<Option<PendingFlashBlock<N>>>;
43
44/// Receiver of the sequences of [`FlashBlock`]s built.
45///
46/// [`FlashBlock`]: crate::FlashBlock
47pub type FlashBlockCompleteSequenceRx =
48    tokio::sync::broadcast::Receiver<FlashBlockCompleteSequence>;
49
50/// Receiver of received [`FlashBlock`]s from the (websocket) subscription.
51///
52/// [`FlashBlock`]: crate::FlashBlock
53pub type FlashBlockRx = tokio::sync::broadcast::Receiver<Arc<FlashBlock>>;
54
55/// Receiver that signals whether a [`FlashBlock`] is currently being built.
56pub type InProgressFlashBlockRx = tokio::sync::watch::Receiver<Option<FlashBlockBuildInfo>>;
57
58/// Container for all flashblocks-related listeners.
59///
60/// Groups together the channels for flashblock-related updates.
61#[derive(Debug)]
62pub struct FlashblocksListeners<N: NodePrimitives> {
63    /// Receiver of the most recent executed [`PendingFlashBlock`] built out of [`FlashBlock`]s.
64    pub pending_block_rx: PendingBlockRx<N>,
65    /// Subscription channel of the complete sequences of [`FlashBlock`]s built.
66    pub flashblocks_sequence: tokio::sync::broadcast::Sender<FlashBlockCompleteSequence>,
67    /// Receiver that signals whether a [`FlashBlock`] is currently being built.
68    pub in_progress_rx: InProgressFlashBlockRx,
69    /// Subscription channel for received flashblocks from the (websocket) connection.
70    pub received_flashblocks: tokio::sync::broadcast::Sender<Arc<FlashBlock>>,
71}
72
73impl<N: NodePrimitives> FlashblocksListeners<N> {
74    /// Creates a new [`FlashblocksListeners`] with the given channels.
75    pub const fn new(
76        pending_block_rx: PendingBlockRx<N>,
77        flashblocks_sequence: tokio::sync::broadcast::Sender<FlashBlockCompleteSequence>,
78        in_progress_rx: InProgressFlashBlockRx,
79        received_flashblocks: tokio::sync::broadcast::Sender<Arc<FlashBlock>>,
80    ) -> Self {
81        Self { pending_block_rx, flashblocks_sequence, in_progress_rx, received_flashblocks }
82    }
83}