Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(minimal): remove head tracking #29

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions minimal/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures::{Future, StreamExt};
use reth::primitives::BlockNumHash;
use reth_exex::{ExExContext, ExExEvent, ExExHead, ExExNotification};
use futures::{Future, TryStreamExt};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;
Expand All @@ -19,32 +18,20 @@ async fn exex_init<Node: FullNodeComponents>(
///
/// This ExEx just prints out whenever either a new chain of blocks being added, or a chain of
/// blocks being re-orged. After processing the chain, emits an [ExExEvent::FinishedHeight] event.
async fn exex<Node: FullNodeComponents>(ctx: ExExContext<Node>) -> eyre::Result<()> {
let head: BlockNumHash = if std::fs::exists("exex_head.json")? {
serde_json::from_str(&std::fs::read_to_string("exex_head.json")?)?
} else {
(ctx.head.number, ctx.head.hash).into()
};

let mut notifications = ctx.notifications.with_head(ExExHead { block: head });
while let Some(notification) = notifications.next().await.transpose()? {
let exex_head: BlockNumHash = match &notification {
async fn 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");
new.tip().num_hash()
}
ExExNotification::ChainReorged { old, new } => {
info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg");
new.tip().num_hash()
}
ExExNotification::ChainReverted { old } => {
info!(reverted_chain = ?old.range(), "Received revert");
(old.first().number - 1, old.first().parent_hash).into()
}
};

std::fs::write("exex_head.json", serde_json::to_string(&exex_head)?)?;

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