Add aggregator

This commit is contained in:
Antonio Antonino 2025-04-10 09:08:02 +02:00
parent cbccdd52f0
commit 5c5ef74c73
No known key found for this signature in database
GPG Key ID: 70CC1DF6BCF7E76D
5 changed files with 51 additions and 16 deletions

View File

@ -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" }

View File

@ -0,0 +1,6 @@
[package]
name = "evm-aggregator"
edition = { workspace = true }
[dependencies]
reth-ethereum = { workspace = true }

View File

@ -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<Block> {
unprocessed_blocks: Vec<Block>,
}
impl<Block> Aggregator<Block>
where
Block: reth_ethereum::primitives::Block,
{
pub fn process_blocks(&mut self, new_blocks: impl Iterator<Item = Block>) {
self.unprocessed_blocks.extend(new_blocks);
}
}

View File

@ -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 }

View File

@ -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<Node: FullNodeComponents>(
pub type Block<Node> =
<<<Node as FullNodeTypes>::Types as NodeTypes>::Primitives as NodePrimitives>::Block;
async fn aggregate_block_txs<Node: FullNodeComponents>(
mut ctx: ExExContext<Node>,
mut aggregator: Aggregator<Block<Node>>,
) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.try_next().await? {
match &notification {
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 } = &notification 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<Node: FullNodeComponents>(
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(),
)