diff --git a/Cargo.lock b/Cargo.lock index acfb8041c80..83991ad18a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3713,6 +3713,18 @@ dependencies = [ "tracing", ] +[[package]] +name = "external-proofs" +version = "0.1.0" +dependencies = [ + "eyre", + "futures-util", + "reth-exex", + "reth-node-api", + "reth-node-types", + "reth-provider", +] + [[package]] name = "eyre" version = "0.6.12" diff --git a/Cargo.toml b/Cargo.toml index b6518707a9f..ab1a985bfd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ members = [ "crates/exex/exex/", "crates/exex/test-utils/", "crates/exex/types/", + "crates/exex/external-proofs/", "crates/metrics/", "crates/net/banlist/", "crates/net/discv4/", diff --git a/crates/exex/external-proofs/Cargo.toml b/crates/exex/external-proofs/Cargo.toml new file mode 100644 index 00000000000..2c01227110c --- /dev/null +++ b/crates/exex/external-proofs/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "external-proofs" +version = "0.1.0" +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +description = "ExEx to save and serve trie nodes to make proofs faster." + +[lints] +workspace = true + +[dependencies] +reth-exex.workspace = true + +# reth +reth-provider.workspace = true +reth-node-types.workspace = true +reth-node-api.workspace = true + +# misc +eyre.workspace = true +futures-util.workspace = true diff --git a/crates/exex/external-proofs/src/lib.rs b/crates/exex/external-proofs/src/lib.rs new file mode 100644 index 00000000000..0ef60d0d1e2 --- /dev/null +++ b/crates/exex/external-proofs/src/lib.rs @@ -0,0 +1,48 @@ +//! External Proofs ExEx - processes blocks and tracks state changes + +use futures_util::TryStreamExt; +use reth_node_api::{FullNodeComponents, NodePrimitives}; +use reth_node_types::NodeTypes; +use reth_provider::StateReader; + +use reth_exex::{ExExContext, ExExEvent}; + +/// Saves and serves trie nodes to make proofs faster. This handles the process of +/// saving the current state, new blocks as they're added, and serving proof RPCs +/// based on the saved data. +#[derive(Debug)] +pub struct ExternalProofExEx +where + Node: FullNodeComponents, + Node::Provider: StateReader, +{ + ctx: ExExContext, +} + +impl ExternalProofExEx +where + Node: FullNodeComponents>, + Primitives: NodePrimitives, +{ + /// Create a new `ExternalProofExEx` instance + pub const fn new(ctx: ExExContext) -> Self { + Self { ctx } + } + + /// Main execution loop for the ExEx + pub async fn run(mut self) -> eyre::Result<()> { + while let Some(notification) = self.ctx.notifications.try_next().await? { + // match ¬ification { + // _ => {} + // }; + + if let Some(committed_chain) = notification.committed_chain() { + self.ctx + .events + .send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?; + } + } + + Ok(()) + } +}