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

refactor: split NetworkEventListenerProvider #12972

Merged

Conversation

lean-apple
Copy link
Contributor

@lean-apple lean-apple commented Nov 28, 2024

Closes #12861.

TODO:

  • update network.md

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 looks great already.

will take a closer look once rfr, but this is exactly what we wanted.

I hope you didn't encounter too many conflicts while working on this -.-

@lean-apple
Copy link
Contributor Author

this looks great already.

will take a closer look once rfr, but this is exactly what we wanted.

I hope you didn't encounter too many conflicts while working on this -.-

Thanks but I wonder if we can remove SessionEstablished from PeerEvent, and only have ActivePeerSession in NetworkEvent, otherwise there is always this double case if both events are emitted, and it can result in doing the same action, or do we need both ?

@lean-apple lean-apple marked this pull request as ready for review November 29, 2024 15:49
@mattsse mattsse added the A-networking Related to networking in general label Dec 2, 2024
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.

Thanks but I wonder if we can remove SessionEstablished from PeerEvent, and only have ActivePeerSession in NetworkEvent

I think this is fine because we can easily a NetworkEvent into a PeerEvent

otherwise there is always this double case if both events are emitted, and it can result in doing the same action, or do we need both ?

but I think I get your point that this currently requires a another peer_events_sender channel?

since we can extract PeerEvent from NetworkEvent, we can avoid this if we change the Stream type that NetworkPeersEvents::event_listener returns.

we can introduce a helper wrapper type that holds Pin<Box<Stream Item = PeerEvent> + Send + Sync>

this way we can use the generic EventStream<NetworkEvent<R>>; but convert the NetworkEvent to PeerEvent, erasing the generic

Comment on lines 447 to 448
/// Sender for basic peer lifecycle events.
peer_events_sender: EventSender<PeerEvent>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I think this is likely not necessary because peerEvent is a subset of of NetworkEvent now, so we can use the same event channel if we change the stream type

#[auto_impl::auto_impl(&, Arc)]
pub trait NetworkPeersEvents: Send + Sync {
/// Creates a new [`PeerEvent`] listener channel.
fn peer_events(&self) -> EventStream<PeerEvent>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of EventStream this could return a static BoxStream (or ideally a newtype wrapper) of EventStream<NetworkEvent>.map(Into)

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!

cc @Rjected this unblocks more progress on txmanager

Comment on lines +1054 to +1059
/// Handles session establishment and peer transactions initialization.
fn handle_peer_session(
&mut self,
info: SessionInfo,
messages: PeerRequestSender<PeerRequest<N>>,
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool, nice additional cleanup

@mattsse mattsse added this pull request to the merge queue Dec 4, 2024
Merged via the queue into paradigmxyz:main with commit fbd2d6e Dec 4, 2024
42 checks passed
@lean-apple lean-apple deleted the network-event-listener-provider-split branch December 5, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Related to networking in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split NetworkEventListenerProvider into two
2 participants