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

fix(deposit): synchronized failedBlocks between multiple goroutines #1472

Closed
wants to merge 4 commits into from

Conversation

htiennv
Copy link
Contributor

@htiennv htiennv commented Jun 14, 2024

Summary by CodeRabbit

  • Refactor
    • Improved the retry mechanism for failed block processing in the deposit service by switching from a map to a channel, enhancing efficiency and reliability.

Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

The update transitions the failedBlocks data structure in the deposit service from a map to a channel, enabling more efficient and streamlined retry processing of failed blocks. Additionally, changes to the depositCatchupFetcher function reflect this transition, moving away from a ticker-driven approach to a channel-based mechanism for handling failed blocks individually.

Changes

File Change Summary
mod/execution/pkg/deposit/service.go Converted failedBlocks from a map to a channel in the Service struct; updated initialization.
mod/execution/pkg/deposit/sync.go Replaced the ticker mechanism with a channel-based approach for processing failed blocks.

Sequence Diagram(s)

Old Flow with Ticker

sequenceDiagram
    participant Ticker
    participant Service
    participant Fetcher

    Ticker-->>Service: Trigger retry every interval
    Service->>Fetcher: Process failed blocks
    Fetcher-->>Service: Failed block processing results
Loading

New Flow with Channel

sequenceDiagram
    participant Service
    participant Channel as FailedBlocks(Channel)
    participant Fetcher as DepositFetcher

    Service-)Channel: Push failed block
    Channel->>Fetcher: Retrieve failed block
    Fetcher-->>Service: Process and retry failed block
Loading

Poem

Through channels now our blocks do flow,
Retry the ones that once did go,
More swift, more clear in data's dance,
Our service grows with each new chance.
In streams of code we find delight,
Efficiency in every byte.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a38c3ec and 6ead64a.

Files selected for processing (2)
  • mod/execution/pkg/deposit/service.go (2 hunks)
  • mod/execution/pkg/deposit/sync.go (4 hunks)
Additional comments not posted (3)
mod/execution/pkg/deposit/sync.go (2)

64-70: The changes to use a channel (failedBlocks) for managing retries of failed blocks look well-integrated. Ensure that the channel is always properly drained and closed to avoid goroutine leaks.


83-83: The retry logic by re-enqueuing the block number into the failedBlocks channel upon failure is clear and straightforward. However, ensure there are safeguards against infinite retry loops which could occur if the same block consistently fails.

Consider implementing a maximum retry limit or a back-off mechanism to handle persistent failures gracefully.

Also applies to: 96-96

mod/execution/pkg/deposit/service.go (1)

63-65: The initialization of failedBlocks as a channel with a buffer size of 100 in the Service struct and NewService function is appropriate for handling retry operations asynchronously. Ensure that the buffer size aligns with the expected volume of failed blocks to prevent blocking on channel operations.

Also applies to: 108-108

Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 6ead64a and db756d7.

Files selected for processing (1)
  • mod/execution/pkg/deposit/service.go (3 hunks)
Additional comments not posted (2)
mod/execution/pkg/deposit/service.go (2)

66-68: Switching failedBlocks from a map to a channel is a significant change to ensure thread-safe operations across multiple goroutines. This change should help in managing failed blocks more effectively by leveraging Go's built-in concurrency features like channels.


111-111: Initializing failedBlocks with a buffer size of defaultChannelCap (100) is a good practice as it allows the channel to hold multiple items before blocking, facilitating smoother asynchronous processing.

Copy link
Contributor

@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 UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between db756d7 and 665219c.

Files selected for processing (1)
  • mod/execution/pkg/deposit/service.go (3 hunks)
Additional comments not posted (2)
mod/execution/pkg/deposit/service.go (2)

Line range hint 123-125: Starting of goroutines in Start method looks good.

Ensure that the failedBlocks channel is properly integrated and utilized within the goroutines to handle retries effectively.

Verification successful

The initial attempt to verify the integration of the failedBlocks channel within the depositFetcher and depositCatchupFetcher goroutines failed due to a directory not found error. This indicates that either the directory path was incorrect or the files are located elsewhere.

To proceed, we need to refine our search to locate the correct directory and files where these goroutines are implemented. Let's use fd to find the relevant files and then search within them for the usage of failedBlocks.


The recent script execution revealed that the failedBlocks channel is indeed used within the codebase, specifically in mod/execution/pkg/deposit/sync.go and mod/execution/pkg/deposit/service.go.

Here are the relevant lines:

  • mod/execution/pkg/deposit/sync.go
    • case blockNum := <-s.failedBlocks:
    • s.failedBlocks <- blockNum
    • s.failedBlocks <- blockNum
  • mod/execution/pkg/deposit/service.go
    • // failedBlocks is a channel of blocks that failed to be processed to be
    • failedBlocks chan math.U64
    • failedBlocks: make(chan math.U64, defaultChannelCap)

This confirms that the failedBlocks channel is properly integrated and utilized within the relevant goroutines for handling retries.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify proper integration of `failedBlocks` channel in goroutines.
# Expectation: `failedBlocks` channel should be actively used without errors.

# Test: Review the implementation of `depositFetcher` and `depositCatchupFetcher` for channel usage.
rg --type go "failedBlocks" src/mod/execution/pkg/deposit/

Length of output: 129



Script:

#!/bin/bash
# Description: Locate files related to depositFetcher and depositCatchupFetcher implementations and verify the usage of failedBlocks channel.

# Step 1: Locate files potentially containing depositFetcher and depositCatchupFetcher implementations.
fd -e go "deposit" src/

# Step 2: Search for the usage of failedBlocks within the located files.
fd -e go "deposit" src/ | xargs rg "failedBlocks"

Length of output: 727


68-68: Change from map to channel for failedBlocks is approved.

Please verify if the buffer size of 100 is adequate based on expected traffic and retry rates.

@@ -105,7 +108,7 @@ func NewService[
metrics: newMetrics(telemetrySink),
dc: dc,
ds: ds,
failedBlocks: make(map[math.Slot]struct{}),
failedBlocks: make(chan math.U64, defaultChannelCap),
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization of failedBlocks with defaultChannelCap is well-implemented.

Consider adding documentation on how the buffer size was determined to be 100, to aid future maintainability.

@itsdevbear
Copy link
Member

hi @htiennv I agree with this change, but this piece of the code base needs a broader re-architecture overall

your logic here (much like our not so great existing solution) will result in infinite number of go-routines being spun up

@htiennv
Copy link
Contributor Author

htiennv commented Jun 15, 2024

hi @htiennv I agree with this change, but this piece of the code base needs a broader re-architecture overall

your logic here (much like our not so great existing solution) will result in infinite number of go-routines being spun up

thanks for your response, i'll close this PR

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.

2 participants