feat(exex): add Pool to ExExContext (#7573)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Alexey Shekhirin
2024-04-12 17:34:18 +01:00
committed by GitHub
parent 7918759b2f
commit 2dcc01210c
6 changed files with 23 additions and 16 deletions

View File

@ -1,4 +1,4 @@
use reth_node_api::FullNodeTypes; use reth_node_api::FullNodeComponents;
use reth_node_core::{ use reth_node_core::{
dirs::{ChainPath, DataDirPath}, dirs::{ChainPath, DataDirPath},
node_config::NodeConfig, node_config::NodeConfig,
@ -12,7 +12,7 @@ use crate::ExExEvent;
/// Captures the context that an ExEx has access to. /// Captures the context that an ExEx has access to.
#[derive(Debug)] #[derive(Debug)]
pub struct ExExContext<Node: FullNodeTypes> { pub struct ExExContext<Node: FullNodeComponents> {
/// The current head of the blockchain at launch. /// The current head of the blockchain at launch.
pub head: Head, pub head: Head,
/// The configured provider to interact with the blockchain. /// The configured provider to interact with the blockchain.
@ -25,6 +25,8 @@ pub struct ExExContext<Node: FullNodeTypes> {
pub config: NodeConfig, pub config: NodeConfig,
/// The loaded node config /// The loaded node config
pub reth_config: reth_config::Config, pub reth_config: reth_config::Config,
/// The transaction pool of the node.
pub pool: Node::Pool,
/// Channel used to send [`ExExEvent`]s to the rest of the node. /// Channel used to send [`ExExEvent`]s to the rest of the node.
/// ///
/// # Important /// # Important

View File

@ -610,6 +610,7 @@ where
data_dir: data_dir.clone(), data_dir: data_dir.clone(),
config: config.clone(), config: config.clone(),
reth_config: reth_config.clone(), reth_config: reth_config.clone(),
pool: transaction_pool.clone(),
events, events,
notifications, notifications,
}; };

View File

@ -1,11 +1,11 @@
//! Types for launching execution extensions (ExEx). //! Types for launching execution extensions (ExEx).
use crate::FullNodeTypes;
use futures::{future::BoxFuture, FutureExt}; use futures::{future::BoxFuture, FutureExt};
use reth_exex::ExExContext; use reth_exex::ExExContext;
use reth_node_api::FullNodeComponents;
use std::future::Future; use std::future::Future;
/// A trait for launching an ExEx. /// A trait for launching an ExEx.
trait LaunchExEx<Node: FullNodeTypes>: Send { trait LaunchExEx<Node: FullNodeComponents>: Send {
/// Launches the ExEx. /// Launches the ExEx.
/// ///
/// The ExEx should be able to run independently and emit events on the channels provided in /// The ExEx should be able to run independently and emit events on the channels provided in
@ -19,7 +19,7 @@ trait LaunchExEx<Node: FullNodeTypes>: Send {
type BoxExEx = BoxFuture<'static, eyre::Result<()>>; type BoxExEx = BoxFuture<'static, eyre::Result<()>>;
/// A version of [LaunchExEx] that returns a boxed future. Makes the trait object-safe. /// A version of [LaunchExEx] that returns a boxed future. Makes the trait object-safe.
pub(crate) trait BoxedLaunchExEx<Node: FullNodeTypes>: Send { pub(crate) trait BoxedLaunchExEx<Node: FullNodeComponents>: Send {
fn launch(self: Box<Self>, ctx: ExExContext<Node>) fn launch(self: Box<Self>, ctx: ExExContext<Node>)
-> BoxFuture<'static, eyre::Result<BoxExEx>>; -> BoxFuture<'static, eyre::Result<BoxExEx>>;
} }
@ -30,7 +30,7 @@ pub(crate) trait BoxedLaunchExEx<Node: FullNodeTypes>: Send {
impl<E, Node> BoxedLaunchExEx<Node> for E impl<E, Node> BoxedLaunchExEx<Node> for E
where where
E: LaunchExEx<Node> + Send + 'static, E: LaunchExEx<Node> + Send + 'static,
Node: FullNodeTypes, Node: FullNodeComponents,
{ {
fn launch( fn launch(
self: Box<Self>, self: Box<Self>,
@ -48,7 +48,7 @@ where
/// resolving to an ExEx. /// resolving to an ExEx.
impl<Node, F, Fut, E> LaunchExEx<Node> for F impl<Node, F, Fut, E> LaunchExEx<Node> for F
where where
Node: FullNodeTypes, Node: FullNodeComponents,
F: FnOnce(ExExContext<Node>) -> Fut + Send, F: FnOnce(ExExContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<E>> + Send, Fut: Future<Output = eyre::Result<E>> + Send,
E: Future<Output = eyre::Result<()>> + Send, E: Future<Output = eyre::Result<()>> + Send,

View File

@ -1,7 +1,8 @@
use futures::future; use futures::future;
use reth_db::test_utils::create_test_rw_db; use reth_db::test_utils::create_test_rw_db;
use reth_exex::ExExContext; use reth_exex::ExExContext;
use reth_node_builder::{FullNodeTypes, NodeBuilder, NodeConfig}; use reth_node_api::FullNodeComponents;
use reth_node_builder::{NodeBuilder, NodeConfig};
use reth_node_ethereum::EthereumNode; use reth_node_ethereum::EthereumNode;
use std::{ use std::{
future::Future, future::Future,
@ -9,11 +10,14 @@ use std::{
task::{Context, Poll}, task::{Context, Poll},
}; };
struct DummyExEx<Node: FullNodeTypes> { struct DummyExEx<Node: FullNodeComponents> {
_ctx: ExExContext<Node>, _ctx: ExExContext<Node>,
} }
impl<Node: FullNodeTypes> Future for DummyExEx<Node> { impl<Node> Future for DummyExEx<Node>
where
Node: FullNodeComponents,
{
type Output = eyre::Result<()>; type Output = eyre::Result<()>;
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {

View File

@ -1,6 +1,6 @@
use futures::Future; use futures::Future;
use reth::builder::FullNodeTypes;
use reth_exex::ExExContext; use reth_exex::ExExContext;
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode; use reth_node_ethereum::EthereumNode;
use reth_provider::CanonStateNotification; use reth_provider::CanonStateNotification;
@ -8,7 +8,7 @@ use reth_provider::CanonStateNotification;
/// ///
/// During initialization you can wait for resources you need to be up for the ExEx to function, /// During initialization you can wait for resources you need to be up for the ExEx to function,
/// like a database connection. /// like a database connection.
async fn exex_init<Node: FullNodeTypes>( async fn exex_init<Node: FullNodeComponents>(
ctx: ExExContext<Node>, ctx: ExExContext<Node>,
) -> eyre::Result<impl Future<Output = eyre::Result<()>>> { ) -> eyre::Result<impl Future<Output = eyre::Result<()>>> {
Ok(exex(ctx)) Ok(exex(ctx))
@ -18,7 +18,7 @@ async fn exex_init<Node: FullNodeTypes>(
/// ///
/// This ExEx just prints out whenever a state transition happens, either a new chain segment being /// This ExEx just prints out whenever a state transition happens, either a new chain segment being
/// added, or a chain segment being re-orged. /// added, or a chain segment being re-orged.
async fn exex<Node: FullNodeTypes>(mut ctx: ExExContext<Node>) -> eyre::Result<()> { async fn exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.recv().await { while let Some(notification) = ctx.notifications.recv().await {
match &notification { match &notification {
CanonStateNotification::Commit { new } => { CanonStateNotification::Commit { new } => {

View File

@ -1,7 +1,7 @@
use alloy_sol_types::{sol, SolEventInterface}; use alloy_sol_types::{sol, SolEventInterface};
use futures::Future; use futures::Future;
use reth::builder::FullNodeTypes;
use reth_exex::{ExExContext, ExExEvent}; use reth_exex::{ExExContext, ExExEvent};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode; use reth_node_ethereum::EthereumNode;
use reth_primitives::{Log, SealedBlockWithSenders, TransactionSigned}; use reth_primitives::{Log, SealedBlockWithSenders, TransactionSigned};
use reth_provider::Chain; use reth_provider::Chain;
@ -14,7 +14,7 @@ use crate::L1StandardBridge::{ETHBridgeFinalized, ETHBridgeInitiated, L1Standard
/// Initializes the ExEx. /// Initializes the ExEx.
/// ///
/// Opens up a SQLite database and creates the tables (if they don't exist). /// Opens up a SQLite database and creates the tables (if they don't exist).
async fn init<Node: FullNodeTypes>( async fn init<Node: FullNodeComponents>(
ctx: ExExContext<Node>, ctx: ExExContext<Node>,
mut connection: Connection, mut connection: Connection,
) -> eyre::Result<impl Future<Output = eyre::Result<()>>> { ) -> eyre::Result<impl Future<Output = eyre::Result<()>>> {
@ -88,7 +88,7 @@ fn create_tables(connection: &mut Connection) -> rusqlite::Result<()> {
/// An example of ExEx that listens to ETH bridging events from OP Stack chains /// An example of ExEx that listens to ETH bridging events from OP Stack chains
/// and stores deposits and withdrawals in a SQLite database. /// and stores deposits and withdrawals in a SQLite database.
async fn op_bridge_exex<Node: FullNodeTypes>( async fn op_bridge_exex<Node: FullNodeComponents>(
mut ctx: ExExContext<Node>, mut ctx: ExExContext<Node>,
connection: Connection, connection: Connection,
) -> eyre::Result<()> { ) -> eyre::Result<()> {