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

Dispatch uTP listener events to overlay protocol #337

Merged
merged 3 commits into from
Jun 9, 2022

Conversation

ogenev
Copy link
Member

@ogenev ogenev commented May 30, 2022

Subtask of #313.

What was wrong?

In a previous PR, we implemented an uTP listener architecture that allows us to emit global uTP listener events when a uTP stream is closed.

To be able to process those events in the overlay layer, we need a way to handle them.

How was it fixed?

The current design decision is to handle the uTP listener events in the global portal event handler and dispatch them to the overlay network handlers.

To-Do

  • Add entry to the release notes (may forgo for trivial changes)
  • Clean up commit history

@ogenev ogenev force-pushed the dispatch-utp-listener-events branch from fdfdba5 to 23faa61 Compare May 30, 2022 14:08
@ogenev ogenev changed the title Dispatch uTP listener eventsto overlay protocol Dispatch uTP listener events to overlay protocol May 30, 2022
@ogenev ogenev force-pushed the dispatch-utp-listener-events branch 3 times, most recently from 17816eb to c98ae9d Compare June 6, 2022 09:20
@ogenev ogenev marked this pull request as ready for review June 6, 2022 09:23
@ogenev ogenev force-pushed the dispatch-utp-listener-events branch from c98ae9d to 5f28053 Compare June 7, 2022 11:09
Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

Mostly formatting issues. (did cargo fmt not pick those up?). And a general thought about improving how we pass around overlay network specific channels - I'd be curious to hear if anyone has suggestions on how we can improve that

history_network_task,
history_event_tx,
history_utp_tx,
history_jsonrpc_tx,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not so much a comment to fix in this pr, but just thinking out loud that it would be nice if we come up with a nice abstraction to wrap up all these channels in. With the header oracle in #331, we'll have yet another object to pass around. And when considering the other overlay networks to be implemented, this pattern seems like it's only going to continue to get messier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe we should open an issue and try to refactor this at some point...

loop {
tokio::select! {
Some(talk_request) = self.event_rx.recv() => {
let reply = match self
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit shouldn't this block be indented once more

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like cargo fmt doesn't know how to handle select! properly? The other select was funky too.

One way to avoid the issue is by doing:

Some(talk_request) = self.event_rx.recv() => self.handle_history_talk_request(talk_request),

trin-state/src/events.rs Outdated Show resolved Hide resolved
trin-core/src/portalnet/events.rs Outdated Show resolved Hide resolved
@carver
Copy link
Collaborator

carver commented Jun 7, 2022

did cargo fmt not pick those up?

Apparently not, or CI should have complained.

Copy link
Collaborator

@carver carver left a comment

Choose a reason for hiding this comment

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

I'll probably want to take another look at the refactored select!, but I'd rather not block your forward progress, so I'll give a 👍🏻 with an understanding of maybe suggesting some rework on it in a followup PR.

Comment on lines 65 to 66
Some(event) = self.protocol_receiver.recv() => {
let request = match event {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another spot where it seems like there ought to be an indent. Weird that fmt isn't catching these...

Suggested change
Some(event) = self.protocol_receiver.recv() => {
let request = match event {
Some(event) = self.protocol_receiver.recv() => {
let request = match event {

/// Main loop to dispatch `Discv5` and `UtpListener` events to overlay networks
pub async fn start(mut self) {
loop {
tokio::select! {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This select is huge. I expect it to be much easier to read if it calls some functions here at each of the branches. Even some of the branches seem large enough to break down into a couple functions.

I don't feel confident about having reviewed this section until that happens.

Copy link
Member Author

@ogenev ogenev Jun 9, 2022

Choose a reason for hiding this comment

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

Refactored this a bit, it should be more readable now. It seems extracting the select! logic into smaller methods solves also the ident issues.

@@ -174,6 +174,15 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
self.send_overlay_request(request, direction).await
}

/// Process overlay uTP listener event
pub fn process_utp_event(&self, event: UtpListenerEvent) {
// TODO: Handle overlay uTP events
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally I would say to move this into an issue. But if you already have the PR up in draft form, I am fine leaving an in-code todo comment. 👍🏻

loop {
tokio::select! {
Some(talk_request) = self.event_rx.recv() => {
let reply = match self
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like cargo fmt doesn't know how to handle select! properly? The other select was funky too.

One way to avoid the issue is by doing:

Some(talk_request) = self.event_rx.recv() => self.handle_history_talk_request(talk_request),

@ogenev ogenev force-pushed the dispatch-utp-listener-events branch from 5f28053 to 4b50f97 Compare June 9, 2022 09:48
@ogenev ogenev merged commit 95d128b into ethereum:master Jun 9, 2022
@ogenev ogenev deleted the dispatch-utp-listener-events branch June 21, 2022 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants