diff --git a/.gitignore b/.gitignore index 1e7caa9..8b98abd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Cargo.lock target/ +.vscode \ No newline at end of file diff --git a/sz-poc-offsite-2025/Cargo.toml b/sz-poc-offsite-2025/Cargo.toml new file mode 100644 index 0000000..9e9d834 --- /dev/null +++ b/sz-poc-offsite-2025/Cargo.toml @@ -0,0 +1,19 @@ +[workspace] +members = ["evm/aggregator", "evm/sequencer-node"] +resolver = "3" + +[workspace.package] +edition = "2024" + +[workspace.dependencies] +# Internal +evm-aggregator = { path = "evm/aggregator" } +evm-sequencer-node = { path = "evm/sequencer-node" } + +# External +eyre = { version = "0.6" } +futures = { version = "0.3" } +reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.8" } +reth-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.8" } +reth-ethereum-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.8" } +reth-tracing = { git = "https://github.com/paradigmxyz/reth", tag = "v1.3.8" } diff --git a/sz-poc-offsite-2025/evm/aggregator/Cargo.toml b/sz-poc-offsite-2025/evm/aggregator/Cargo.toml new file mode 100644 index 0000000..4cf5bf8 --- /dev/null +++ b/sz-poc-offsite-2025/evm/aggregator/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "evm-aggregator" +edition = { workspace = true } + +[dependencies] +reth-ethereum = { workspace = true } diff --git a/sz-poc-offsite-2025/evm/aggregator/src/lib.rs b/sz-poc-offsite-2025/evm/aggregator/src/lib.rs new file mode 100644 index 0000000..27bc9f4 --- /dev/null +++ b/sz-poc-offsite-2025/evm/aggregator/src/lib.rs @@ -0,0 +1,14 @@ +use reth_ethereum::Block; + +// TODO: The logic to batch multiple of these blocks (or the transactions within them) and send them to DA and generate proofs is still missing. It will have to be added at the offsite. +// This type does not support any recovery mechanism, so if the node is stopped, the state DB should be cleaned before starting again. The folder is specified by the `--datadir` option in the binary. +#[derive(Default)] +pub struct Aggregator { + unprocessed_blocks: Vec, +} + +impl Aggregator { + pub fn process_blocks(&mut self, new_blocks: impl Iterator) { + self.unprocessed_blocks.extend(new_blocks); + } +} diff --git a/sz-poc-offsite-2025/evm/sequencer-node/Cargo.toml b/sz-poc-offsite-2025/evm/sequencer-node/Cargo.toml new file mode 100644 index 0000000..e76b274 --- /dev/null +++ b/sz-poc-offsite-2025/evm/sequencer-node/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "evm-sequencer-node" +edition = { workspace = true } + +[dependencies] + +evm-aggregator = { workspace = true } + +eyre = { workspace = true } +futures = { workspace = true } +reth = { workspace = true } +reth-ethereum = { workspace = true, features = ["full"] } +reth-ethereum-primitives = { workspace = true } +reth-tracing = { workspace = true } diff --git a/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs b/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs new file mode 100644 index 0000000..2de08b5 --- /dev/null +++ b/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs @@ -0,0 +1,68 @@ +use evm_aggregator::Aggregator; +use futures::TryStreamExt as _; +use reth::{ + api::{FullNodeTypes, NodePrimitives, NodeTypes}, + cli::Cli, +}; +use reth_ethereum::{ + exex::{ExExContext, ExExEvent, ExExNotification}, + node::{EthereumNode, api::FullNodeComponents}, +}; +use reth_tracing::tracing::info; + +async fn aggregate_block_txs( + mut ctx: ExExContext, + mut aggregator: Aggregator, +) -> eyre::Result<()> +where + <::Types as NodeTypes>::Primitives: + NodePrimitives, +{ + while let Some(notification) = ctx.notifications.try_next().await? { + let ExExNotification::ChainCommitted { new } = ¬ification else { + continue; + }; + info!(committed_chain = ?new.range(), "Received commit"); + aggregator.process_blocks( + new.inner() + .0 + .clone() + .into_blocks() + .map(reth_ethereum::primitives::RecoveredBlock::into_block), + ); + + ctx.events + .send(ExExEvent::FinishedHeight(new.tip().num_hash())) + .unwrap(); + } + + Ok(()) +} + +fn main() -> eyre::Result<()> { + Cli::try_parse_args_from([ + "reth", + "node", + "--datadir=/tmp/reth-dev/", + "--dev", + "--dev.block-time=2s", + "--http.addr=0.0.0.0", + ]) + .unwrap() + .run(|builder, _| { + Box::pin(async move { + let aggregator = Aggregator::default(); + let handle = Box::pin( + builder + .node(EthereumNode::default()) + .install_exex("aggregate-block-txs", async move |ctx| { + Ok(aggregate_block_txs(ctx, aggregator)) + }) + .launch(), + ) + .await?; + + handle.wait_for_node_exit().await + }) + }) +}