-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
WalkthroughThe recent updates enhance the Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this 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
Where(fmt.Sprintf("%s = ?", chainIDFieldName), chainID). | ||
Where(fmt.Sprintf("%s = ?", listenerNameFieldName), s.listenerName). |
There was a problem hiding this comment.
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
There was a problem hiding this 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
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
, andblockNumberFieldName
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
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Deploying sanguine-fe with Cloudflare Pages
|
There was a problem hiding this 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
There was a problem hiding this 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
andchainIDB
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
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 indb_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.
Summary by CodeRabbit
New Features
LatestBlockForChain
method with support for multiple chain IDs.Bug Fixes