From 5c5ef74c73d7458e6fac78c903dacbc2dfbe068c Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Thu, 10 Apr 2025 09:08:02 +0200 Subject: [PATCH] Add aggregator --- sz-poc-offsite-2025/Cargo.toml | 4 +- sz-poc-offsite-2025/evm/aggregator/Cargo.toml | 6 +++ sz-poc-offsite-2025/evm/aggregator/src/lib.rs | 15 ++++++++ .../evm/sequencer-node/Cargo.toml | 4 ++ .../evm/sequencer-node/src/main.rs | 38 +++++++++++-------- 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 sz-poc-offsite-2025/evm/aggregator/Cargo.toml create mode 100644 sz-poc-offsite-2025/evm/aggregator/src/lib.rs diff --git a/sz-poc-offsite-2025/Cargo.toml b/sz-poc-offsite-2025/Cargo.toml index 759223f..9e9d834 100644 --- a/sz-poc-offsite-2025/Cargo.toml +++ b/sz-poc-offsite-2025/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["evm/sequencer-node"] +members = ["evm/aggregator", "evm/sequencer-node"] resolver = "3" [workspace.package] @@ -7,6 +7,7 @@ edition = "2024" [workspace.dependencies] # Internal +evm-aggregator = { path = "evm/aggregator" } evm-sequencer-node = { path = "evm/sequencer-node" } # External @@ -14,4 +15,5 @@ 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..41a5d8f --- /dev/null +++ b/sz-poc-offsite-2025/evm/aggregator/src/lib.rs @@ -0,0 +1,15 @@ +// 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. +#[derive(Default)] +pub struct Aggregator { + unprocessed_blocks: Vec, +} + +impl Aggregator +where + Block: reth_ethereum::primitives::Block, +{ + 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 index 2fd69f3..e76b274 100644 --- a/sz-poc-offsite-2025/evm/sequencer-node/Cargo.toml +++ b/sz-poc-offsite-2025/evm/sequencer-node/Cargo.toml @@ -3,8 +3,12 @@ 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 index 692447d..7c6ae7f 100644 --- a/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs +++ b/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs @@ -1,27 +1,34 @@ +use evm_aggregator::Aggregator; use futures::TryStreamExt as _; -use reth::cli::Cli; +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 push_block_to_da( +pub type Block = + <<::Types as NodeTypes>::Primitives as NodePrimitives>::Block; + +async fn aggregate_block_txs( mut ctx: ExExContext, + mut aggregator: Aggregator>, ) -> eyre::Result<()> { while let Some(notification) = ctx.notifications.try_next().await? { - match ¬ification { - ExExNotification::ChainCommitted { new } => { - // TODO: Push range of finalized blocks to DA, and interact with prover to generate a proof over the range. - info!(committed_chain = ?new.range(), "Received commit"); - } - ExExNotification::ChainReorged { old, new } => { - info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg"); - } - ExExNotification::ChainReverted { old } => { - info!(reverted_chain = ?old.range(), "Received revert"); - } + 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), + ); if let Some(committed_chain) = notification.committed_chain() { ctx.events @@ -36,11 +43,12 @@ async fn push_block_to_da( fn main() -> eyre::Result<()> { Cli::parse_args().run(|builder, _| { Box::pin(async move { + let aggregator = Aggregator::default(); let handle = Box::pin( builder .node(EthereumNode::default()) - .install_exex("push-block-to-da", async move |ctx| { - Ok(push_block_to_da(ctx)) + .install_exex("aggregate-block-txs", async move |ctx| { + Ok(aggregate_block_txs(ctx, aggregator)) }) .launch(), )