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

op-node: prevent spamming of reqs for blocks triggered by checkForGapInUnsafeQueue #10063

Merged
merged 12 commits into from
Apr 23, 2024

Conversation

bitwiseguy
Copy link
Contributor

@bitwiseguy bitwiseguy commented Apr 8, 2024

Description

Based on this comment, we would like to bail on a batch of block requests when we receive a block not found error from one of the blocks in the range. That will prevent the op-node from spamming its peers with block requests in the event that the sequencer is offline and unsafe blocks cannot be found, meaning the requests are destined-to-fail. This PR adds a rangeRequestId field to the peerRequest struct so that when we detect the aforementioned error, we can set a flag mapped to that rangeRequestId, which allows us to drop all other requests with that same id instead of continuing to send those requests to peers.

Tests

The existing TestMultiPeerSync covers the updated code, as evidenced by the logs generated by that test. I added some checks within that same test to verify that a rangeReq was properly cancelled.

image

Additional context

I considered an alternative approach that attached a shared context and cancel function to the peerRequest struct instead of the rangeRequestId. However, the use of rangeRequestId seemed more straightforward and less prone to errors such as accidentally canceling block requests if the parent context is cancelled.

In the linked issue and associated comment thread, it was also suggested that we consider backing off the altSync timer when a block not found error is produced. In the worst case scenario, with this updated code, we would send a single destined-to-fail request every (2 * blockTime) seconds to each peer before the entire batch of requests is cancelled. This doesn't seem like a very heavy load to put on any given peer so backoff logic is not currently included in this PR.

Metadata

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced peer synchronization capabilities with improved tracking and handling of active range requests.
    • Improved logging for canceled sync requests to aid in debugging and optimization.
    • Modified channel names for better organization.

Copy link
Contributor

coderabbitai bot commented Apr 8, 2024

Walkthrough

Walkthrough

The update enhances the synchronization process in the peer-to-peer network module. It introduces a new rangeReqId field for better tracking of range requests. Changes include adjustments to channel names, the addition of a map to monitor active requests, improved logging for new L2 range requests, and better handling of canceled sync requests.

Changes

File(s) Change Summary
op-node/p2p/sync.go - Added rangeReqId to peerRequest struct.
- Modified channel names.
- Added a map for tracking active range requests.
- Enhanced logging for new L2 range requests.
- Improved handling of canceled sync requests.
op-node/p2p/sync_test.go - Modified error handling in RequestL2Range function calls.
- Adjusted tracking of active range requests for proper synchronization in test scenarios.

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 32651b2 and 863744f.
Files selected for processing (3)
  • op-node/p2p/node.go (1 hunks)
  • op-node/p2p/sync.go (13 hunks)
  • op-node/p2p/sync_test.go (5 hunks)
Files skipped from review as they are similar to previous changes (3)
  • op-node/p2p/node.go
  • op-node/p2p/sync.go
  • op-node/p2p/sync_test.go

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

op-node/p2p/sync.go Outdated Show resolved Hide resolved
op-node/p2p/sync.go Outdated Show resolved Hide resolved
op-node/p2p/sync.go Outdated Show resolved Hide resolved
@bitwiseguy bitwiseguy marked this pull request as ready for review April 9, 2024 01:14
@bitwiseguy bitwiseguy requested a review from a team as a code owner April 9, 2024 01:14
@bitwiseguy bitwiseguy requested a review from tynes April 9, 2024 01:15
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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a3cc8f2 and 201d280.
Files selected for processing (1)
  • op-node/p2p/sync.go (10 hunks)
Additional comments not posted (5)
op-node/p2p/sync.go (5)

101-102: The addition of rangeReqId to peerRequest struct is a good approach for identifying batch requests.


216-219: The introduction of activeRangeRequests map and related channels is well-implemented for managing batch requests efficiently.


398-401: Ensure the use of a secure random number generator for randomReqId.


540-544: Efficiently handling canceled sync requests by checking activeRangeRequests before proceeding is a smart optimization.


557-565: Consider implementing a more nuanced error handling strategy for different types of request failures.

Suggest exploring a strategy that differentiates between transient and permanent errors, potentially incorporating a retry mechanism for the former.

op-node/p2p/sync.go Outdated Show resolved Hide resolved
op-node/p2p/sync.go Outdated Show resolved Hide resolved
Copy link
Contributor

semgrep-app bot commented Apr 9, 2024

Semgrep found 7 sol-style-return-arg-fmt findings:

Named return arguments to functions must be appended with an underscore (_)

Ignore this finding from sol-style-return-arg-fmt.

Semgrep found 2 sol-style-notice-over-dev-natspec findings:

Prefer @notice over @dev in natspec comments

Ignore this finding from sol-style-notice-over-dev-natspec.

Semgrep found 7 sol-style-input-arg-fmt findings:

Inputs to functions must be prepended with an underscore (_)

Ignore this finding from sol-style-input-arg-fmt.

@bitwiseguy bitwiseguy force-pushed the bitwise/cancel-l2-range-request branch from ad4e06f to 5d67d73 Compare April 9, 2024 19:12
op-node/p2p/sync.go Outdated Show resolved Hide resolved
op-node/p2p/sync.go Outdated Show resolved Hide resolved
Copy link
Contributor

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

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

PR lgtm. @protolambda if you have chance I'd appreciate a quick look as weel.

Copy link
Contributor

semgrep-app bot commented Apr 12, 2024

Semgrep found 2 sol-style-return-arg-fmt findings:

Named return arguments to functions must be appended with an underscore (_)

Ignore this finding from sol-style-return-arg-fmt.

op-node/p2p/sync.go Outdated Show resolved Hide resolved
@bitwiseguy bitwiseguy force-pushed the bitwise/cancel-l2-range-request branch from 48962aa to 17667af Compare April 15, 2024 19:21
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

Looks good generally but I'm reasonably confident that we've introduced a race condition with the change from *atomic.Bool to bool because previously the map was only accessed by a single thread and the *atomic.Bool shared, whereas now the map is shared. It is a nice simplification though - I wonder if it's reasonable to add a mutex to protect the map - just need to make sure we don't introduce any deadlocks but as long as the lock is tightly scoped I think it would be fine.

op-node/p2p/sync.go Outdated Show resolved Hide resolved
op-node/p2p/sync.go Outdated Show resolved Hide resolved
@bitwiseguy bitwiseguy requested a review from ajsutton April 16, 2024 21:12
@bitwiseguy bitwiseguy force-pushed the bitwise/cancel-l2-range-request branch from 585c922 to c2e27fd Compare April 16, 2024 21:16
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

LGTM.

op-node/p2p/sync.go Outdated Show resolved Hide resolved
@bitwiseguy bitwiseguy force-pushed the bitwise/cancel-l2-range-request branch from 74bd258 to 863744f Compare April 22, 2024 18:36
@bitwiseguy
Copy link
Contributor Author

Rebased on top of develop to pull in pnpm-lock.yaml update. Was causing test failures without pulling in that update

@bitwiseguy bitwiseguy changed the title Prevent spamming of requests for blocks triggered by checkForGapInUnsafeQueue op-node: prevent spamming of reqs for blocks triggered by checkForGapInUnsafeQueue Apr 23, 2024
@sebastianst sebastianst added this pull request to the merge queue Apr 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2024
@sebastianst sebastianst added this pull request to the merge queue Apr 23, 2024
Merged via the queue into develop with commit 589b1fd Apr 23, 2024
72 checks passed
@sebastianst sebastianst deleted the bitwise/cancel-l2-range-request branch April 23, 2024 14:58
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.

4 participants