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: add helper stream type for finalized notifications #14111

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hoank101
Copy link
Contributor

Closes #14063

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great start

left a few suggestions

crates/chain-state/src/notifications.rs Outdated Show resolved Hide resolved
crates/chain-state/src/notifications.rs Show resolved Hide resolved
crates/chain-state/Cargo.toml Outdated Show resolved Hide resolved
@hoank101 hoank101 requested a review from mattsse January 31, 2025 14:27
@hoank101 hoank101 marked this pull request as ready for review January 31, 2025 14:38
@emhane emhane added the A-sdk Related to reth's use as a library label Feb 4, 2025
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, this lgtm!

only need to take a final closer look

@mattsse mattsse added the C-enhancement New feature or request label Feb 4, 2025
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, I have a few smol suggestions

#[pin]
canon_stream: CanonStateNotificationStream<N>,
#[pin]
finalized_stream: ForkChoiceStream<SealedHeader<alloy_consensus::Header>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to replace the concrete header types with

Suggested change
finalized_stream: ForkChoiceStream<SealedHeader<alloy_consensus::Header>>,
finalized_stream: ForkChoiceStream<SealedHeaderFor<N>>,

Comment on lines +233 to +244
fn try_match(
buffered_notification: &Option<CanonStateNotification<N>>,
buffered_finalization: &Option<SealedHeader<alloy_consensus::Header>>,
) -> Option<CanonStateNotification<N>> {
match (buffered_notification, buffered_finalization) {
(Some(notification), Some(finalized_header))
if notification.tip().hash() == finalized_header.hash() =>
{
Some(notification.clone())
}
_ => None,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to inline this function so that we can .take the notification instead.

so we can move this inside the poll fn

Poll::Ready(None) => return Poll::Ready(None),
Poll::Pending => {}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a check here that breaks if one Option is none


// Check if we have a matching pair using the projected fields
if let Some(notification) =
Self::try_match(this.buffered_notification, this.buffered_finalization)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check can be simplified by checking

buffered.as_ref.map(|n|n.tip) == header.as_ref.map() {
   header.take();
   return buffered.take()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sdk Related to reth's use as a library C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add helper stream type for finalized notifications
3 participants