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

RFQ: failed rebalance does not block chain listener #2430

Merged
merged 7 commits into from
Apr 2, 2024
Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Apr 2, 2024

Description
If we encounter an error when rebalancing, we should only log the error instead of returning it, since a bubbled-up error results in reprocessing a log range.

Summary by CodeRabbit

  • Refactor

    • Enhanced error handling and logging in the blockchain event listener.
    • Improved clarity and efficiency in blockchain event processing.
  • Bug Fixes

    • Corrected typos in error messages for improved user understanding.
    • Reordered imports and updated package references for better organization.
    • Renamed a package reference for consistency.

Copy link
Contributor

coderabbitai bot commented Apr 2, 2024

Walkthrough

The recent changes involve reordering imports, updating package references, setting endBlock as a variable, enhancing context attribute handling, and refining error messages across the codebase. These modifications aim to streamline code structure, improve variable management, and enhance error handling for better code quality.

Changes

Files Change Summary
ethergo/listener/listener.go Reordered imports, updated package references, adjusted logic by setting endBlock as a variable, enhancing context attribute handling, fixing a typo in an error message related to block handling. Renamed a package reference.

"In the realm of code, where logic intertwines,
A rabbit hopped, fixing lines,
With a gentle touch and a keen eye,
Errors fled, and bugs did shy.
🐇💻✨
In whispers of silicon, it danced,
Leaving behind a trail, enhanced."

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/coderabbit-overrides.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.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Apr 2, 2024
Copy link

cloudflare-workers-and-pages bot commented Apr 2, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: b8f6b6f
Status:⚡️  Build in progress...

View logs

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: 2

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between f46285e and 7f308e8.
Files selected for processing (2)
  • ethergo/listener/listener.go (4 hunks)
  • services/rfq/relayer/service/chainindexer.go (1 hunks)
Additional comments not posted (2)
ethergo/listener/listener.go (2)

112-118: Ensure proper error handling and backoff strategy.
The current implementation correctly sets the pollInterval based on the backoff strategy after handling errors. This is a good practice for managing retry logic in case of transient failures. However, ensure that the backoff configuration (newBackoffConfig()) is appropriately tuned for your use case to avoid excessive retries or long delays.


164-164: Ensure error handling is comprehensive and consistent.
The error message "could not put latest block" is clear and includes the wrapped error. This is a good practice for error handling as it provides context for debugging. Ensure that similar error handling practices are applied consistently throughout the application.

@@ -205,7 +205,7 @@ type decimalsRes struct {
func (r *Relayer) handleDepositClaimed(ctx context.Context, event *fastbridge.FastBridgeBridgeDepositClaimed, chainID int) error {
err := r.inventory.Rebalance(ctx, chainID, event.Token)
if err != nil {
return fmt.Errorf("could not rebalance: %w", err)
logger.Errorf("could not rebalance: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace the %w verb with %v when logging errors.

- logger.Errorf("could not rebalance: %w", err)
+ logger.Errorf("could not rebalance: %v", err)

The %w verb is used for wrapping errors when using fmt.Errorf to allow errors to be unwrapped later. For logging purposes, %v or %s should be used instead, as wrapping is not necessary.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
logger.Errorf("could not rebalance: %w", err)
logger.Errorf("could not rebalance: %v", err)

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 46.94045%. Comparing base (f46285e) to head (fccc667).
Report is 2 commits behind head on master.

❗ Current head fccc667 differs from pull request most recent head b8f6b6f. Consider uploading reports for the commit b8f6b6f to get more accurate results

Files Patch % Lines
ethergo/listener/listener.go 77.41935% 5 Missing and 2 partials ⚠️
services/rfq/relayer/service/chainindexer.go 0.00000% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2430         +/-   ##
===================================================
- Coverage   46.94871%   46.94045%   -0.00826%     
===================================================
  Files            400         383         -17     
  Lines          30610       29269       -1341     
  Branches          83          83                 
===================================================
- Hits           14371       13739        -632     
+ Misses         14707       14069        -638     
+ Partials        1532        1461         -71     
Flag Coverage Δ
cctp-relayer ?
committee 62.90550% <ø> (ø)
promexporter ?
rfq 28.97609% <0.00000%> (-0.12099%) ⬇️
sin-executor 63.05419% <ø> (-0.73892%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@github-actions github-actions bot added size/s and removed size/xs labels Apr 2, 2024
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: 2

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 7f308e8 and e398414.
Files selected for processing (1)
  • ethergo/listener/listener.go (7 hunks)
Additional Context Used
GitHub Check Runs (1)
Lint (ethergo) failure (4)

ethergo/listener/listener.go: [failure] 209-209:
Comment should end in a period (godot)

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: 3

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between e398414 and fccc667.
Files selected for processing (1)
  • ethergo/listener/listener.go (9 hunks)
Additional Context Used
GitHub Check Runs (2)
codecov/patch success (4)

ethergo/listener/listener.go: [warning] 190-191: ethergo/listener/listener.go#L190-L191
Added lines #L190 - L191 were not covered by tests


ethergo/listener/listener.go: [warning] 196-196: ethergo/listener/listener.go#L196
Added line #L196 was not covered by tests


ethergo/listener/listener.go: [warning] 218-219: ethergo/listener/listener.go#L218-L219
Added lines #L218 - L219 were not covered by tests

Lint (ethergo) failure (4)

ethergo/listener/listener.go: [failure] 209-209:
Comment should end in a period (godot)

Additional comments not posted (2)
ethergo/listener/listener.go (2)

10-11: The reordering of imports and updating of package references appear to be done for clarity and consistency.


108-120: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [111-139]

Introducing endBlock as a variable and its subsequent usage in the log processing logic is a positive change. It enhances the flexibility and accuracy of block range handling.

@@ -130,7 +136,7 @@

// Handle if the listener is more than one get logs range behind the head
// Note: this does not cover the edge case of a reorg that includes a new tx
endBlock := c.latestBlock
endBlock = c.latestBlock
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the edge case where c.startBlock + maxGetLogsRange exceeds the maximum value of uint64 to prevent overflow.

- endBlock = c.startBlock + maxGetLogsRange
+ if c.startBlock > math.MaxUint64 - maxGetLogsRange {
+     endBlock = math.MaxUint64
+ } else {
+     endBlock = c.startBlock + maxGetLogsRange
+ }

This change ensures that the calculation of endBlock does not overflow, which could potentially cause the application to behave unexpectedly or miss logs.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
endBlock = c.latestBlock
if c.startBlock > math.MaxUint64 - maxGetLogsRange {
endBlock = math.MaxUint64
} else {
endBlock = c.startBlock + maxGetLogsRange
}

@@ -211,6 +205,21 @@
return startBlock, chainID, nil
}

// TODO: consider some kind of backoff here in case rpcs are down at boot.
// this becomes more of an issue as we add more chains
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment should end in a period to follow Go documentation conventions.

- // this becomes more of an issue as we add more chains
+ // This becomes more of an issue as we add more chains.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// this becomes more of an issue as we add more chains
// This becomes more of an issue as we add more chains.

Comment on lines +190 to +191
return 0, 0, fmt.Errorf("could not get chain ID: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The added lines related to error handling and chain ID retrieval were not covered by tests. It's crucial to add unit tests for these changes to ensure the new logic works as expected and does not introduce regressions.

Also applies to: 196-196, 218-219

@trajan0x trajan0x merged commit 9218a0b into master Apr 2, 2024
33 of 34 checks passed
@trajan0x trajan0x deleted the fix/listener branch April 2, 2024 22:53
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 Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between fccc667 and b8f6b6f.
Files selected for processing (1)
  • ethergo/listener/listener.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ethergo/listener/listener.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants