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(katana): separate node service task #2413

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Sep 11, 2024

small refactor/optimisation separating the NodeService task which currently encapsulates both the messaging and block production task.

this PR separate it into two different tasks. easier to reason about the scope of each task and allowing them to be scheduled by Tokio on different worker threads (parallelized)

Summary by CodeRabbit

  • New Features
    • Introduced MessagingTask for improved asynchronous messaging handling.
    • Added BlockProductionTask to streamline block production processes.
  • Bug Fixes
    • Enhanced error handling in CriticalTaskBuilder to prioritize task cancellation on panic.
  • Documentation
    • Updated documentation for the shutdown method in TaskManager for clarity.
  • Refactor
    • Simplified the architecture by removing ServiceMetrics and focusing on BlockProducerMetrics.
    • Refined task management for both messaging and block production services.

Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

Ohayo, sensei! The pull request introduces several structural changes to the Katana framework, including the addition of the MessagingTask for asynchronous message handling, the removal of the ServiceMetrics struct in favor of BlockProducerMetrics, and the renaming of NodeService to BlockProductionTask. These modifications streamline task management and refactor the messaging and block production services for improved organization and clarity.

Changes

Files Change Summary
crates/katana/core/src/service/messaging/mod.rs Added MessagingTask struct and its Future implementation for asynchronous messaging operations.
crates/katana/core/src/service/metrics.rs Removed ServiceMetrics struct; introduced BlockProducerMetrics struct for block production metrics.
crates/katana/core/src/service/mod.rs Renamed NodeService to BlockProductionTask, removed messaging logic, and updated metrics usage.
crates/katana/node/src/lib.rs Refactored messaging and block production service management using MessagingTask and BlockProductionTask.
crates/katana/tasks/src/manager.rs Minor documentation updates for the shutdown method in TaskManager.
crates/katana/tasks/src/task.rs Modified error handling logic in CriticalTaskBuilder to prioritize task cancellation on panic.

Possibly related PRs


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3727ac and 9e1d9bb.

Files selected for processing (6)
  • crates/katana/core/src/service/messaging/mod.rs (2 hunks)
  • crates/katana/core/src/service/metrics.rs (1 hunks)
  • crates/katana/core/src/service/mod.rs (2 hunks)
  • crates/katana/node/src/lib.rs (3 hunks)
  • crates/katana/tasks/src/manager.rs (1 hunks)
  • crates/katana/tasks/src/task.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • crates/katana/core/src/service/metrics.rs
  • crates/katana/tasks/src/manager.rs
Additional comments not posted (12)
crates/katana/core/src/service/mod.rs (3)

34-34: LGTM sensei!

The renaming of the NodeService struct to BlockProductionTask and the change in the metrics field type from ServiceMetrics to BlockProducerMetrics align well with the refactoring goal of separating the block production task from the messaging task.

Also applies to: 42-42


45-52: Looks good sensei!

The removal of the messaging field initialization from the new constructor aligns with the refactoring goal of separating the block production task from the messaging task.


Line range hint 55-91: Ohayo sensei! The changes look great.

The removal of the messaging related polling logic and the updates to the metrics and error logging in the Future trait implementation for the BlockProductionTask struct align well with the refactoring goal of separating the block production task from the messaging task.

crates/katana/tasks/src/task.rs (1)

136-136: Ohayo, sensei! The change in error handling logic looks good to me.

The modification ensures that the task is cancelled immediately when a panic occurs, before logging the error. This prioritizes task cancellation and may affect the relative timing of cancellation and error reporting. However, the overall control flow remains intact.

crates/katana/core/src/service/messaging/mod.rs (4)

40-43: Ohayo sensei! The imports look good to me.

The imports are necessary for implementing the Future trait for MessagingTask.


50-51: Ohayo sensei! The imports are spot-on.

The StreamExt trait is likely used for working with asynchronous streams in the MessagingTask implementation, and the ExecutorFactory trait is used as a generic parameter for the MessagingTask struct.


210-221: Ohayo sensei! The MessagingTask struct looks good.

The struct is parameterized by a generic type EF that must implement the ExecutorFactory trait, and it has a constructor that takes a MessagingService<EF> as an argument. This struct is likely used to represent an asynchronous task for handling messaging operations using the MessagingService.


223-243: Ohayo sensei! The Future implementation for MessagingTask looks solid.

The poll method continuously polls the MessagingService for outcomes using a while let loop, handling two specific cases of MessagingOutcome: Gather and Send. It logs the number of messages collected or sent, respectively. If no messages are ready, the method returns Poll::Pending.

This implementation allows MessagingTask to be used in asynchronous contexts, continuously polling the MessagingService for outcomes and handling them accordingly.

crates/katana/node/src/lib.rs (4)

22-23: Ohayo sensei! The new imports look good to me.

The imports are necessary for the subsequent changes in the file.


Line range hint 176-186: Ohayo sensei! The block producer setup looks good to me.

The code segment correctly builds the block producer based on the sequencer configuration.


213-224: Ohayo sensei! The messaging task setup looks good to me.

The code segment correctly creates a TaskManager and builds and spawns the messaging task if the messaging configuration is provided.


228-231: Ohayo sensei! The block production task setup looks good to me.

The code segment correctly builds and spawns the block production task.

Comment on lines +1 to +2
// TODO: remove the messaging feature flag
// TODO: move the tasks to a separate module
Copy link

Choose a reason for hiding this comment

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

Ohayo sensei! Noted the TODO comments.

The TODO comments indicate that the messaging feature flag should be removed and the tasks should be moved to a separate module.

Do you want me to open a GitHub issue to track these refactoring tasks?

@kariy kariy merged commit 80d1827 into main Sep 11, 2024
13 checks passed
@kariy kariy deleted the katana/service-task-separation branch September 11, 2024 18:16
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 43.75000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 67.92%. Comparing base (a3727ac) to head (9e1d9bb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/core/src/service/messaging/mod.rs 0.00% 13 Missing ⚠️
crates/katana/node/src/lib.rs 66.66% 3 Missing ⚠️
crates/katana/core/src/service/mod.rs 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2413      +/-   ##
==========================================
- Coverage   67.94%   67.92%   -0.03%     
==========================================
  Files         364      364              
  Lines       47770    47760      -10     
==========================================
- Hits        32459    32440      -19     
- Misses      15311    15320       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant