Skip to main content

reth_exex/
dyn_context.rs

1//! Mirrored version of [`ExExContext`](`crate::ExExContext`)
2//! without generic abstraction over [Node](`reth_node_api::FullNodeComponents`)
3
4use alloy_eips::BlockNumHash;
5use reth_chainspec::EthChainSpec;
6use reth_ethereum_primitives::EthPrimitives;
7use reth_node_api::{FullNodeComponents, HeaderTy, NodePrimitives, PrimitivesTy};
8use reth_node_core::node_config::NodeConfig;
9use std::fmt::Debug;
10use tokio::sync::mpsc;
11
12use crate::{ExExContext, ExExEvent, ExExNotificationsStream};
13
14// TODO(0xurb) - add `node` after abstractions
15/// Captures the context that an `ExEx` has access to.
16pub struct ExExContextDyn<N: NodePrimitives = EthPrimitives> {
17    /// The current head of the blockchain at launch.
18    pub head: BlockNumHash,
19    /// The config of the node
20    pub config: NodeConfig<Box<dyn EthChainSpec<Header = N::BlockHeader> + 'static>>,
21    /// The loaded node config
22    pub reth_config: reth_config::Config,
23    /// Channel used to send [`ExExEvent`]s to the rest of the node.
24    ///
25    /// # Important
26    ///
27    /// The exex should emit a `FinishedHeight` whenever a processed block is safe to prune.
28    /// Additionally, the exex can preemptively emit a `FinishedHeight` event to specify what
29    /// blocks to receive notifications for.
30    pub events: mpsc::UnboundedSender<ExExEvent>,
31    /// Channel to receive [`ExExNotification`](crate::ExExNotification)s.
32    ///
33    /// # Important
34    ///
35    /// Once an [`ExExNotification`](crate::ExExNotification) is sent over the channel, it is
36    /// considered delivered by the node.
37    pub notifications: Box<dyn ExExNotificationsStream<N>>,
38}
39
40impl<N: NodePrimitives> Debug for ExExContextDyn<N> {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        f.debug_struct("ExExContext")
43            .field("head", &self.head)
44            .field("config", &self.config)
45            .field("reth_config", &self.reth_config)
46            .field("events", &self.events)
47            .field("notifications", &"...")
48            .finish()
49    }
50}
51
52impl<Node> From<ExExContext<Node>> for ExExContextDyn<PrimitivesTy<Node::Types>>
53where
54    Node: FullNodeComponents,
55{
56    fn from(ctx: ExExContext<Node>) -> Self {
57        let config = ctx.config.map_chainspec(|chainspec| {
58            Box::new(chainspec) as Box<dyn EthChainSpec<Header = HeaderTy<Node::Types>>>
59        });
60        let notifications = Box::new(ctx.notifications) as Box<_>;
61
62        Self {
63            head: ctx.head,
64            config,
65            reth_config: ctx.reth_config,
66            events: ctx.events,
67            notifications,
68        }
69    }
70}