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(listener): latest block query #3030

Merged
merged 3 commits into from
Aug 19, 2024
Merged

fix(listener): latest block query #3030

merged 3 commits into from
Aug 19, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Improved error handling and clarity in fetching the latest blocks for different chains.
    • Enhanced testing for the LatestBlockForChain method with support for multiple chain IDs.
  • Bug Fixes

    • Addressed issues with error reporting when no latest blocks exist for specified chain IDs.

@dwasse dwasse requested a review from trajan0x as a code owner August 15, 2024 23:14
Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent updates enhance the LatestBlockForChain method in the Store struct, along with improvements to the TestBlock function in the DBSuite test suite. These changes focus on improving error handling, query logic, and test coverage for multiple chains. The implementation now offers clearer queries and more consistent error reporting, ultimately increasing the robustness and reliability of both the method and its associated tests.

Changes

File Change Summary
ethergo/listener/db/store.go Updated LatestBlockForChain method to enhance error handling and query clarity using a transaction variable.
services/rfq/relayer/reldb/db_test.go Modified TestBlock function to support two chain IDs, improving test coverage for the LatestBlockForChain method.

Poem

🐇 In the code where bunnies play,
We fetch the latest block today!
With clearer queries and errors fine,
The method hops like a well-formed line.
Let’s celebrate this joyful dance,
For code that sings, we take a chance! 🌟


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 Configuration 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/xs labels Aug 15, 2024
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

Modified the LatestBlockForChain function in ethergo/listener/db/store.go to improve query performance and accuracy when fetching the latest block for a specific chain ID and listener name.

  • Updated query in LatestBlockForChain to use explicit Where clauses for chainID and listenerName
  • Removed creation of LastIndexed model instance, simplifying the function
  • Improved error handling to maintain consistency with the existing ErrNoLatestBlockForChainID check

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines +49 to +50
Where(fmt.Sprintf("%s = ?", chainIDFieldName), chainID).
Where(fmt.Sprintf("%s = ?", listenerNameFieldName), s.listenerName).
Copy link

Choose a reason for hiding this comment

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

style: Consider using parameterized queries instead of string formatting to prevent SQL injection

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 914d2e2 and 89d7210.

Files selected for processing (1)
  • ethergo/listener/db/store.go (1 hunks)
Additional comments not posted (1)
ethergo/listener/db/store.go (1)

47-58: Enhanced error handling and query logic approved.

The improvements in error handling and query logic are well-implemented. The use of parameterized queries enhances security by preventing SQL injection. The error handling is more robust with specific checks for gorm.ErrRecordNotFound.

Ensure that the field names (chainIDFieldName, listenerNameFieldName) are correctly initialized and used throughout the codebase.

Verification successful

Field names are correctly initialized and used.

The field names chainIDFieldName, listenerNameFieldName, and blockNumberFieldName are properly initialized and consistently used throughout the codebase. This ensures that database queries are constructed with the correct field names.

  • Initialization and usage are confirmed in ethergo/listener/db/store.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and usage of field names.

# Test: Search for the initialization and usage of field names. Expect: Correct initialization and usage.
rg --type go 'chainIDFieldName|listenerNameFieldName|blockNumberFieldName'

Length of output: 2700

Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 20.81468%. Comparing base (914d2e2) to head (7a071bd).
Report is 7 commits behind head on master.

Files Patch % Lines
ethergo/listener/db/store.go 0.00000% 9 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3030         +/-   ##
===================================================
- Coverage   20.81697%   20.81468%   -0.00230%     
===================================================
  Files            551         551                 
  Lines          45338       45343          +5     
  Branches          82          82                 
===================================================
  Hits            9438        9438                 
- Misses         34899       34903          +4     
- Partials        1001        1002          +1     
Flag Coverage Δ
cctp-relayer 31.97848% <ø> (ø)
ethergo 47.81799% <0.00000%> (-0.01909%) ⬇️
omnirpc 33.23904% <ø> (ø)
opbot 0.48900% <ø> (ø)
promexporter 7.66551% <ø> (ø)
rfq 21.79024% <ø> (-0.00564%) ⬇️
scribe 18.24614% <ø> (ø)
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 Aug 15, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7a071bd
Status: ✅  Deploy successful!
Preview URL: https://7247cccf.sanguine-fe.pages.dev
Branch Preview URL: https://fix-listener-name.sanguine-fe.pages.dev

View logs

@github-actions github-actions bot added size/s and removed size/xs labels Aug 15, 2024
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)

This PR enhances the test coverage for the LatestBlockForChain and PutLatestBlock methods in the relayer database. The changes focus on improving the robustness of blockchain data handling across multiple chains.

  • Added test cases in services/rfq/relayer/reldb/db_test.go for multiple chain IDs (chainIDA and chainIDB)
  • Expanded TestBlock function to cover scenarios with no existing blocks, adding new blocks, and updating block heights
  • Improved validation of database operations for multiple chains, ensuring correct behavior of LatestBlockForChain and PutLatestBlock methods

These changes complement the previous modifications to the LatestBlockForChain function, providing more comprehensive testing for multi-chain scenarios and enhancing the overall reliability of the blockchain data management system.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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

Outside diff range, codebase verification and nitpick comments (2)
services/rfq/relayer/reldb/db_test.go (2)

14-15: Introduce meaningful constants for chain IDs.

Consider using more descriptive names for chainIDA and chainIDB to improve readability and maintainability.

-		const chainIDA = 5
-		const chainIDB = 6
+		const chainIDMainnet = 5
+		const chainIDTestnet = 6

24-29: Add assertions to verify database state after insertion.

The test currently checks for errors during block insertion but does not verify the actual state of the database. Consider adding assertions to confirm that the blocks are correctly inserted and stored.

Analysis chain

Confirm successful insertion of latest blocks.

The test verifies that blocks are inserted without errors. Consider adding assertions to check the state of the database after insertion.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the state of the database after block insertion.

# Test: Check for database state assertions. Expect: Assertions confirming the state after insertion.
rg --type go 'PutLatestBlock'

Length of output: 1116

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 89d7210 and 7a071bd.

Files selected for processing (1)
  • services/rfq/relayer/reldb/db_test.go (1 hunks)
Additional comments not posted (3)
services/rfq/relayer/reldb/db_test.go (3)

38-50: Ensure correct increment and verification of block heights.

The test correctly increments block heights and verifies them. This pattern should be consistently applied in other tests involving block height updates.


30-36: Validate retrieval of latest block heights.

The retrieval and verification of the latest block heights for both chains are correctly implemented. Ensure that similar retrieval logic is used across the codebase.

Verification successful

Consistent Retrieval Logic for Latest Block Heights Verified

The retrieval logic for the latest block heights using the LatestBlockForChain function is consistently implemented across the codebase. The function is used in multiple files, and its behavior is tested in db_test.go, confirming its consistent application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Validate retrieval logic for latest block heights.

# Test: Search for retrieval logic. Expect: Consistent retrieval logic for latest block heights.
rg --type go 'LatestBlockForChain'

Length of output: 2148


16-19: Verify error handling for non-existent blocks.

The test correctly checks for ErrNoLatestBlockForChainID when no blocks exist. Ensure that this error is consistently handled in the application code.

@dwasse dwasse merged commit 9dfde6c into master Aug 19, 2024
45 of 47 checks passed
@dwasse dwasse deleted the fix/listener-name branch August 19, 2024 16:49
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