1use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
2use reth_exex_types::ExExHead;
3use reth_node_api::{FullNodeComponents, NodePrimitives, NodeTypes};
4use reth_node_core::node_config::NodeConfig;
5use reth_primitives::Head;
6use reth_provider::BlockReader;
7use reth_tasks::TaskExecutor;
8use std::fmt::Debug;
9use tokio::sync::mpsc::UnboundedSender;
10
11pub struct ExExContext<Node: FullNodeComponents> {
13 pub head: Head,
15 pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
17 pub reth_config: reth_config::Config,
19 pub events: UnboundedSender<ExExEvent>,
27 pub notifications: ExExNotifications<Node::Provider, Node::Executor>,
34
35 pub components: Node,
37}
38
39impl<Node> Debug for ExExContext<Node>
40where
41 Node: FullNodeComponents,
42 Node::Provider: Debug,
43 Node::Executor: Debug,
44{
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 f.debug_struct("ExExContext")
47 .field("head", &self.head)
48 .field("config", &self.config)
49 .field("reth_config", &self.reth_config)
50 .field("events", &self.events)
51 .field("notifications", &self.notifications)
52 .field("components", &"...")
53 .finish()
54 }
55}
56
57impl<Node> ExExContext<Node>
58where
59 Node: FullNodeComponents,
60 Node::Provider: Debug + BlockReader,
61 Node::Executor: Debug,
62 Node::Types: NodeTypes<Primitives: NodePrimitives>,
63{
64 pub fn into_dyn(self) -> ExExContextDyn<<Node::Types as NodeTypes>::Primitives> {
66 ExExContextDyn::from(self)
67 }
68}
69
70impl<Node> ExExContext<Node>
71where
72 Node: FullNodeComponents,
73 Node::Types: NodeTypes<Primitives: NodePrimitives>,
74{
75 pub fn pool(&self) -> &Node::Pool {
77 self.components.pool()
78 }
79
80 pub fn evm_config(&self) -> &Node::Evm {
82 self.components.evm_config()
83 }
84
85 pub fn block_executor(&self) -> &Node::Executor {
87 self.components.block_executor()
88 }
89
90 pub fn provider(&self) -> &Node::Provider {
92 self.components.provider()
93 }
94
95 pub fn network(&self) -> &Node::Network {
97 self.components.network()
98 }
99
100 pub fn payload_builder(&self) -> &Node::PayloadBuilder {
102 self.components.payload_builder()
103 }
104
105 pub fn task_executor(&self) -> &TaskExecutor {
107 self.components.task_executor()
108 }
109
110 pub fn set_notifications_without_head(&mut self) {
113 self.notifications.set_without_head();
114 }
115
116 pub fn set_notifications_with_head(&mut self, head: ExExHead) {
119 self.notifications.set_with_head(head);
120 }
121}
122
123#[cfg(test)]
124mod tests {
125 use reth_exex_types::ExExHead;
126 use reth_node_api::FullNodeComponents;
127 use reth_provider::BlockReader;
128
129 use crate::ExExContext;
130
131 #[test]
133 const fn issue_12054() {
134 #[allow(dead_code)]
135 struct ExEx<Node: FullNodeComponents> {
136 ctx: ExExContext<Node>,
137 }
138
139 impl<Node: FullNodeComponents> ExEx<Node>
140 where
141 Node::Provider: BlockReader,
142 {
143 async fn _test_bounds(mut self) -> eyre::Result<()> {
144 self.ctx.pool();
145 self.ctx.block_executor();
146 self.ctx.provider();
147 self.ctx.network();
148 self.ctx.payload_builder();
149 self.ctx.task_executor();
150 self.ctx.set_notifications_without_head();
151 self.ctx.set_notifications_with_head(ExExHead { block: Default::default() });
152 Ok(())
153 }
154 }
155 }
156}