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

feat(listener): listener safe, finalized, latest block numbers #2762

Merged
merged 5 commits into from
Jun 21, 2024

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Jun 21, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Introduced options to set finality mode and block wait for enhanced block number fetching.
  • Bug Fixes

    • Improved block number fetching mechanism to ensure accurate results based on finality mode and block wait settings.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2024

Warning

Rate limit exceeded

@golangisfun123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 53 minutes and 45 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 1ec0562 and 888792f.

Walkthrough

The updates to the ethergo package introduce enhanced block fetching with finality modes and block wait parameters in the chainListener struct. Changes include new options for configuring finality mode and block wait, restructured block number retrieval for better compatibility, and refactored test cases to validate the new functionalities.

Changes

File Change Summary
ethergo/listener/listener.go Added finalityMode and blockWait to chainListener, updated NewChainListener, replaced block fetch calls, and added getBlockNumber method.
ethergo/listener/listener_test.go Reordered imports, updated TestListenForEvents function, refactored NewChainListener calls, added event handling, and block comparisons.
ethergo/listener/options.go Introduced WithFinalityMode and WithBlockWait functions to set finality mode and block wait options in chainListener.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ChainListener
    Client->>ChainListener: NewChainListener(opts...)
    ChainListener->>ChainListener: set finalityMode, blockWait
    Note right of ChainListener: Initialize chainListener with options
    Client->>ChainListener: Start listening for events
    ChainListener->>ChainListener: doPoll method
    ChainListener->>ChainListener: getBlockNumber()
    Note right of ChainListener: Retrieve block number considering finalityMode and blockWait
Loading

Poem

Changes blown by winds of code,
In the chains where blocks erode,
Options bloom, new paths are shown,
Finality waits, our seeds are sown.
With each poll, we fetch and see,
The future of our blockchain be.


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.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Jun 21, 2024
@trajan0x trajan0x marked this pull request as ready for review June 21, 2024 00:00
@trajan0x trajan0x self-requested a review as a code owner June 21, 2024 00:00
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Introduced finalityMode and blockWait parameters to chainListener
  • Added getBlockNumber method for enhanced block retrieval
  • Updated tests to cover new finality modes (safe, finalized)
  • Added options for setting finality mode and block wait time

3 file(s) reviewed, no comment(s)

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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ac826a and 1ec0562.

Files selected for processing (3)
  • ethergo/listener/listener.go (5 hunks)
  • ethergo/listener/listener_test.go (3 hunks)
  • ethergo/listener/options.go (2 hunks)
Additional comments not posted (7)
ethergo/listener/options.go (2)

30-42: LGTM!

The WithFinalityMode function is implemented correctly and handles different modes appropriately.


44-49: LGTM!

The WithBlockWait function is implemented correctly and sets the blockWait field appropriately.

ethergo/listener/listener_test.go (1)

Line range hint 41-118: Well-structured test for new configurations.

The adjustments in the TestListenForEvents function are well-implemented. It correctly tests the new WithFinalityMode and WithBlockWait options, ensuring different configurations lead to expected differences in behavior.

ethergo/listener/listener.go (4)

52-53: Struct modifications are appropriate and well-integrated.

The addition of finalityMode and blockWait fields to the chainListener struct is well-executed. These fields are crucial for the new functionality related to block number handling.


72-73: Proper use of functional options pattern in constructor.

The changes to the NewChainListener function to incorporate functional options for setting finalityMode and blockWait are correctly implemented and follow best practices in Go.


140-140: Good abstraction of block number fetching.

The modification in the doPoll method to use the getBlockNumber method for fetching the block number enhances modularity and maintainability.


191-204: Correct implementation of block number fetching logic.

The getBlockNumber method is well-implemented, correctly handling different finality modes and adjusting the block number based on the blockWait. This method is crucial for the new functionality related to block number handling.

Copy link

codecov bot commented Jun 21, 2024

Codecov Report

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

Project coverage is 26.20226%. Comparing base (3eccadb) to head (888792f).
Report is 2 commits behind head on master.

Files Patch % Lines
ethergo/listener/listener.go 57.14286% 4 Missing and 2 partials ⚠️
ethergo/listener/options.go 84.61538% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2762         +/-   ##
===================================================
+ Coverage   25.94208%   26.20226%   +0.26017%     
===================================================
  Files            737         737                 
  Lines          52729       52755         +26     
  Branches          80          80                 
===================================================
+ Hits           13679       13823        +144     
+ Misses         37639       37522        -117     
+ Partials        1411        1410          -1     
Flag Coverage Δ
agents 34.20858% <ø> (+0.03697%) ⬆️
cctp-relayer 31.93780% <ø> (ø)
ethergo 48.97669% <70.37037%> (+1.78696%) ⬆️
explorer 4.97877% <ø> (ø)
omnirpc 33.31747% <ø> (ø)
promexporter 9.86717% <ø> (ø)
rfq 26.69195% <ø> (ø)
scribe 18.17597% <ø> (+0.06437%) ⬆️
tools 30.55118% <ø> (ø)

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.

Copy link

cloudflare-workers-and-pages bot commented Jun 21, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 888792f
Status: ✅  Deploy successful!
Preview URL: https://654cf5d5.sanguine-fe.pages.dev
Branch Preview URL: https://feat-listener-finality.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced finalityMode and blockWait fields in chainListener struct
  • Enhanced block number fetching mechanism considering finality and block wait settings
  • Improved error handling in getBlockNumber method for better clarity

1 file(s) reviewed, no comment(s)

@golangisfun123 golangisfun123 merged commit f25026c into master Jun 21, 2024
45 checks passed
@golangisfun123 golangisfun123 deleted the feat/listener-finality branch June 21, 2024 16:05
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.

1 participant