Skip to content

Conversation

@anshalshukla
Copy link
Collaborator

Closes #312

Introduces a new async event loop system that handles events from different threads using async signalling, replacing the previous event handling approach across the network and node layers.

Previously, there was no synchronization mechanism between threads, so the event loop state was not updated when events arrived from other threads. This caused the loop to continue executing on stale state, and events from other threads were not being scheduled.

Copilot AI review requested due to automatic review settings October 23, 2025 12:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an async event loop system to synchronize events from different threads, replacing the previous unsynchronized event handling approach. Previously, events from other threads were not being scheduled because there was no mechanism to update the loop state when they arrived.

Key changes:

  • Implements EventLoop with async notification system for cross-thread event scheduling
  • Replaces direct xev.Loop usage with wrapped EventLoop across network and node layers
  • Removes the boolean scheduleOnLoop parameter from gossip handling

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkgs/utils/src/lib.zig Exports new EventLoop type from utils package
pkgs/utils/src/event_loop.zig New async event loop implementation with mutex-protected work queue and comprehensive tests
pkgs/node/src/utils.zig Removes old EventLoop implementation that lacked thread synchronization
pkgs/node/src/node.zig Updates test to use new EventLoop wrapper
pkgs/node/src/clock.zig Replaces direct loop reference with EventLoop, removes redundant loop.run() call
pkgs/network/src/mock.zig Updates to use EventLoop and removes scheduleOnLoop parameter
pkgs/network/src/interface.zig Refactors gossip handling to use work queue instead of timer-based scheduling
pkgs/network/src/ethlibp2p.zig Updates to use EventLoop and removes scheduleOnLoop parameter
pkgs/cli/src/node.zig Manages EventLoop lifecycle with proper initialization and cleanup
pkgs/cli/src/main.zig Updates all command handlers to use new EventLoop
build.zig Adds xev dependency to utils module

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

/// This method signals the event loop to stop, sends a notification for pending work,
/// and attempts to process it immediately with a best-effort loop run.
/// Should be called before deinit().
pub fn stop(self: *Self) void {
Copy link
Member

Choose a reason for hiding this comment

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

pub const Node = struct {
loop: xev.Loop,
loop: *xev.Loop,
event_loop: *zeam_utils.EventLoop,
Copy link
Member

Choose a reason for hiding this comment

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

shall we just keep event_loop since it already has the loop inside?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, I'll make event_loop the owner of loop

@GrapeBaBa
Copy link
Member

Almost good, just some small suggestion

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.

Make scheduleOnLoop works

3 participants