1use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
2use alloy_eips::BlockNumHash;
3use reth_exex_types::ExExHead;
4use reth_node_api::{FullNodeComponents, NodeTypes, PrimitivesTy};
5use reth_node_core::node_config::NodeConfig;
6use reth_payload_builder::PayloadBuilderHandle;
7use reth_tasks::TaskExecutor;
8use std::fmt::Debug;
9use tokio::sync::mpsc::{error::SendError, UnboundedSender};
10
11pub struct ExExContext<Node: FullNodeComponents> {
15 pub head: BlockNumHash,
17 pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
19 pub reth_config: reth_config::Config,
21 pub events: UnboundedSender<ExExEvent>,
30 pub notifications: ExExNotifications<Node::Provider, Node::Evm>,
37
38 pub components: Node,
40}
41
42impl<Node> Debug for ExExContext<Node>
43where
44 Node: FullNodeComponents,
45{
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.debug_struct("ExExContext")
48 .field("head", &self.head)
49 .field("config", &self.config)
50 .field("reth_config", &self.reth_config)
51 .field("events", &self.events)
52 .field("notifications", &self.notifications)
53 .field("components", &"...")
54 .finish()
55 }
56}
57
58impl<Node> ExExContext<Node>
59where
60 Node: FullNodeComponents,
61{
62 pub fn into_dyn(self) -> ExExContextDyn<PrimitivesTy<Node::Types>> {
64 ExExContextDyn::from(self)
65 }
66}
67
68impl<Node> ExExContext<Node>
69where
70 Node: FullNodeComponents,
71{
72 pub fn pool(&self) -> &Node::Pool {
74 self.components.pool()
75 }
76
77 pub fn evm_config(&self) -> &Node::Evm {
79 self.components.evm_config()
80 }
81
82 pub fn provider(&self) -> &Node::Provider {
84 self.components.provider()
85 }
86
87 pub fn network(&self) -> &Node::Network {
89 self.components.network()
90 }
91
92 pub fn payload_builder_handle(
94 &self,
95 ) -> &PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload> {
96 self.components.payload_builder_handle()
97 }
98
99 pub fn task_executor(&self) -> &TaskExecutor {
103 self.components.task_executor()
104 }
105
106 pub fn set_notifications_without_head(&mut self) {
109 self.notifications.set_without_head();
110 }
111
112 pub fn set_notifications_with_head(&mut self, head: ExExHead) {
115 self.notifications.set_with_head(head);
116 }
117
118 pub fn catch_up_notifications_with_head(&mut self, head: ExExHead) -> eyre::Result<()> {
121 self.notifications.catch_up_with_head(head)
122 }
123
124 pub fn send_finished_height(
129 &self,
130 height: BlockNumHash,
131 ) -> Result<(), SendError<BlockNumHash>> {
132 self.events.send(ExExEvent::FinishedHeight(height)).map_err(|_| SendError(height))
133 }
134}
135
136#[cfg(test)]
137mod tests {
138 use crate::ExExContext;
139 use reth_exex_types::ExExHead;
140 use reth_node_api::FullNodeComponents;
141
142 #[test]
144 const fn issue_12054() {
145 #[expect(dead_code)]
146 struct ExEx<Node: FullNodeComponents> {
147 ctx: ExExContext<Node>,
148 }
149
150 impl<Node: FullNodeComponents> ExEx<Node> {
151 async fn _test_bounds(mut self) -> eyre::Result<()> {
152 self.ctx.pool();
153 self.ctx.evm_config();
154 self.ctx.provider();
155 self.ctx.network();
156 self.ctx.payload_builder_handle();
157 self.ctx.task_executor();
158 self.ctx.set_notifications_without_head();
159 self.ctx.set_notifications_with_head(ExExHead { block: Default::default() });
160 Ok(())
161 }
162 }
163 }
164}