Skip to content

Conversation

@LeanSerra
Copy link
Contributor

@LeanSerra LeanSerra commented Sep 15, 2025

Motivation

Currently the proof_coordinator Genserver can only handle a single cast message Listen { listener: Arc<TcpListener> } as the handler for this messages starts an infinite loop that prevents other cast messages to be handled. This PR fixes that issue by moving the tcp loop into its own task.

Description

  • Move tcp listening loop to spawned spawn_listener task
  • Remove ConnectionHandler genserver
  • Now the spawn_listener task will send a cast message to the proof_coordinator genserver, which will process the request and send the response.

Closes #3316

@LeanSerra LeanSerra self-assigned this Sep 15, 2025
@LeanSerra LeanSerra added the L2 Rollup client label Sep 15, 2025
@LeanSerra LeanSerra moved this to In Progress in ethrex_l2 Sep 15, 2025
@github-actions
Copy link

github-actions bot commented Sep 15, 2025

Lines of code report

Total lines added: 0
Total lines removed: 58
Total lines changed: 58

Detailed view
+-------------------------------------------------+-------+------+
| File                                            | Lines | Diff |
+-------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/proof_coordinator.rs | 517   | -58  |
+-------------------------------------------------+-------+------+

@LeanSerra LeanSerra marked this pull request as ready for review September 15, 2025 19:40
@LeanSerra LeanSerra requested a review from a team as a code owner September 15, 2025 19:40
@LeanSerra LeanSerra moved this from In Progress to In Review in ethrex_l2 Sep 15, 2025
MegaRedHand
MegaRedHand previously approved these changes Sep 15, 2025
Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

Choose a reason for hiding this comment

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

LGTM

.ok()?;

serde_json::from_slice(&buffer)
.map(|data| ProofCordInMessage::Request(data, Arc::new(stream)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to wrap the stream in an Arc here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically because ProofCordInMessage needs to implement Clone and TcpStream is not clonable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right. After the question I checked in spawned and GenServer messages need to be Clone 😅
Well, at least until lambdaclass/spawned#56 is merged 😎

Copy link
Contributor

Choose a reason for hiding this comment

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

And are we sure there are no good reasons for that to not be Clone? A TCP stream is not a datagram oriented socket, meaning you could race to read and write if accessing from several tasks or interleaved inside a task.
I suspect we just want the ProofCoordinator to spawn a task per connection instead. That task would do the infinite loop for as long as the connection is alive, while the ProofCoordinator is free to handle the next cast message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! I made some changes in this commit.

Now we spawn a task that loops doing listener.accept().await. When it successfully accepts a connection it deserializes the request and then passes it and the stream over to the genserver to handle the response.
Right now I still need to wrap it in an Arc but, if the Clone requirements are removed from spawned, we can be 100% sure that only one task can have ownership of the stream at a given time so we have no races.

@MegaRedHand MegaRedHand dismissed their stale review September 15, 2025 21:00

It might be better to spawn a new task per connection, each doing the deserializing of the request, and sending those requests to the genserver.

@LeanSerra LeanSerra marked this pull request as draft September 16, 2025 12:15
@LeanSerra LeanSerra marked this pull request as ready for review September 17, 2025 16:03
Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

Choose a reason for hiding this comment

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

Looks better now

@MegaRedHand MegaRedHand requested a review from Oppen September 17, 2025 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

L2: refactor proof_coordinator

4 participants