Skip to content

Commit

Permalink
sync book/sources/exex
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp committed Oct 30, 2024
1 parent 672670a commit b1feb68
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions book/sources/exex/hello-world/src/bin/1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use reth_node_ethereum::EthereumNode;

fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let handle = builder.node(EthereumNode::default()).launch().await?;

handle.wait_for_node_exit().await
})
}
20 changes: 20 additions & 0 deletions book/sources/exex/hello-world/src/bin/2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use reth::api::FullNodeComponents;
use reth_exex::ExExContext;
use reth_node_ethereum::EthereumNode;

async fn my_exex<Node: FullNodeComponents>(mut _ctx: ExExContext<Node>) -> eyre::Result<()> {
#[allow(clippy::empty_loop)]
loop {}
}

fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let handle = builder
.node(EthereumNode::default())
.install_exex("my-exex", |ctx| async move { Ok(my_exex(ctx)) })
.launch()
.await?;

handle.wait_for_node_exit().await
})
}
39 changes: 39 additions & 0 deletions book/sources/exex/hello-world/src/bin/3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use futures_util::TryStreamExt;
use reth::api::FullNodeComponents;
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;

async fn my_exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.try_next().await? {
match &notification {
ExExNotification::ChainCommitted { new } => {
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");
}
};

if let Some(committed_chain) = notification.committed_chain() {
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
}
}

Ok(())
}

fn main() -> eyre::Result<()> {
reth::cli::Cli::parse_args().run(|builder, _| async move {
let handle = builder
.node(EthereumNode::default())
.install_exex("my-exex", |ctx| async move { Ok(my_exex(ctx)) })
.launch()
.await?;

handle.wait_for_node_exit().await
})
}

0 comments on commit b1feb68

Please sign in to comment.