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