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 ws;
32pub use ws::{WsConnect, WsFlashBlockStream};
33
34/// Receiver of the most recent [`PendingFlashBlock`] built out of [`FlashBlock`]s.
35///
36/// [`FlashBlock`]: crate::FlashBlock
37pub type PendingBlockRx<N> = tokio::sync::watch::Receiver<Option<PendingFlashBlock<N>>>;
38
39/// Receiver of the sequences of [`FlashBlock`]s built.
40///
41/// [`FlashBlock`]: crate::FlashBlock
42pub type FlashBlockCompleteSequenceRx =
43    tokio::sync::broadcast::Receiver<FlashBlockCompleteSequence>;
44
45/// Receiver of received [`FlashBlock`]s from the (websocket) subscription.
46///
47/// [`FlashBlock`]: crate::FlashBlock
48pub type FlashBlockRx = tokio::sync::broadcast::Receiver<Arc<FlashBlock>>;
49
50/// Receiver that signals whether a [`FlashBlock`] is currently being built.
51pub type InProgressFlashBlockRx = tokio::sync::watch::Receiver<Option<FlashBlockBuildInfo>>;
52
53/// Container for all flashblocks-related listeners.
54///
55/// Groups together the channels for flashblock-related updates.
56#[derive(Debug)]
57pub struct FlashblocksListeners<N: NodePrimitives> {
58    /// Receiver of the most recent executed [`PendingFlashBlock`] built out of [`FlashBlock`]s.
59    pub pending_block_rx: PendingBlockRx<N>,
60    /// Subscription channel of the complete sequences of [`FlashBlock`]s built.
61    pub flashblocks_sequence: tokio::sync::broadcast::Sender<FlashBlockCompleteSequence>,
62    /// Receiver that signals whether a [`FlashBlock`] is currently being built.
63    pub in_progress_rx: InProgressFlashBlockRx,
64    /// Subscription channel for received flashblocks from the (websocket) connection.
65    pub received_flashblocks: tokio::sync::broadcast::Sender<Arc<FlashBlock>>,
66}
67
68impl<N: NodePrimitives> FlashblocksListeners<N> {
69    /// Creates a new [`FlashblocksListeners`] with the given channels.
70    pub const fn new(
71        pending_block_rx: PendingBlockRx<N>,
72        flashblocks_sequence: tokio::sync::broadcast::Sender<FlashBlockCompleteSequence>,
73        in_progress_rx: InProgressFlashBlockRx,
74        received_flashblocks: tokio::sync::broadcast::Sender<Arc<FlashBlock>>,
75    ) -> Self {
76        Self { pending_block_rx, flashblocks_sequence, in_progress_rx, received_flashblocks }
77    }
78}