Skip to content

Conversation

tolbrino
Copy link
Contributor

@tolbrino tolbrino commented Jan 8, 2025

Sunsets existing indexer checksum info in the API's node info endpoint and adds additional values which reflect the new log implementation.

Fixes #6659

@tolbrino tolbrino added this to the 2.2.0-rc.1 milestone Jan 8, 2025
@tolbrino tolbrino requested review from NumberFour8 and a team January 8, 2025 12:52
@tolbrino tolbrino self-assigned this Jan 8, 2025
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

📝 Walkthrough

Walkthrough

The pull request introduces changes to the indexer state management across multiple files in the Hopr project. The modifications primarily focus on updating the type constraints for database operations, refactoring the IndexerStateInfo struct, and modifying how indexer state information is retrieved and set. The changes aim to improve the tracking and reporting of block indexing progress, specifically addressing issues with block and checksum reporting in the API's information route.

Changes

File Change Summary
chain/indexer/src/block.rs - Updated Db type constraints to include HoprDbInfoOperations and HoprDbLogOperations
- Added state update logic in process_block method to set indexer state info
db/sql/src/info.rs - Replaced DescribedBlock with IndexerStateInfo struct
- Added get_indexer_state_info and set_indexer_state_info methods to HoprDbInfoOperations trait
hopr/hopr-lib/src/lib.rs - Modified get_indexer_state method to return IndexerStateInfo
- Updated return type and implementation to provide more comprehensive state information
hoprd/rest-api/src/node.rs - Updated NodeInfoResponse struct fields
- Modified info function to use new IndexerStateInfo for retrieving and reporting indexer state
chain/indexer/Cargo.toml - Updated package version from "0.6.0" to "0.6.1"
db/sql/Cargo.toml - Updated package version from "0.10.0" to "0.11.0"
hoprd/rest-api/Cargo.toml - Updated package version from "3.9.1" to "3.9.2"

Assessment against linked issues

Objective Addressed Explanation
Correct indexerBlock reporting [#6659]
Accurate indexBlockPrevChecksum reporting [#6659] Requires further verification of the actual block number logic
Consistent indexer state tracking

Possibly related PRs

  • Update sea orm and sea query #6509: The changes in this PR involve updates to the HoprDbInfoOperations trait, which is relevant to the modifications in the main PR that also involve the HoprDbInfoOperations trait and its methods.
  • Ensure consistency of the Logs DB #6755: This PR introduces a new function ensure_logs_origin in the HoprDbLogOperations trait, which is directly related to the changes in the main PR that enhance the functionality of the process_block method and involve database operations.

Suggested labels

crate:hopr-db-api, status:product-backlog

Suggested reviewers

  • NumberFour8
  • Teebor-Choka

Finishing Touches

  • 📝 Generate Docstrings

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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

🧹 Nitpick comments (5)
db/sql/src/info.rs (2)

23-28: Add documentation for new struct fields

Consider adding documentation comments for latest_log_block_number and latest_log_checksum in the IndexerStateInfo struct to enhance code clarity and maintainability.


495-499: Evaluate the logging level

The use of the trace! macro for logging indexer state updates might be too verbose. Consider using debug! or info! for important operational logs to balance verbosity and usefulness.

hoprd/rest-api/src/node.rs (1)

399-402: Add documentation for new response fields

In the NodeInfoResponse struct, consider adding comments or documentation for the new fields indexer_last_log_block and indexer_last_log_checksum to improve code readability and API documentation.

chain/indexer/src/block.rs (1)

Line range hint 85-90: Ensure atomicity in indexer state updates

The comment mentions that indexing and marking logs as processed should be done in a single transaction but is currently difficult due to cross-database operations. Evaluate the possibility of restructuring to ensure atomic updates, which would enhance data integrity and reduce the risk of inconsistent states.

hopr/hopr-lib/src/lib.rs (1)

1112-1128: Implementation looks good but needs documentation.

The implementation correctly combines indexer state info with log information, providing a more comprehensive view of the indexer state. However, since this is a breaking change in the return type, please add documentation to explain the new return type and its fields.

Add documentation for the method:

+    /// Returns the current state of the indexer, combining database state with the latest log information.
+    /// 
+    /// # Returns
+    /// 
+    /// Returns an `IndexerStateInfo` containing:
+    /// - The latest block number from the log
+    /// - The latest log checksum
+    /// - Additional state information from the database
+    /// 
+    /// If no log exists, returns only the database state information.
     pub async fn get_indexer_state(&self) -> errors::Result<IndexerStateInfo> {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1441f19 and 4f5cacd.

📒 Files selected for processing (4)
  • chain/indexer/src/block.rs (4 hunks)
  • db/sql/src/info.rs (4 hunks)
  • hopr/hopr-lib/src/lib.rs (2 hunks)
  • hoprd/rest-api/src/node.rs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: tests-smoke-websocket
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-unit
  • GitHub Check: Linter
🔇 Additional comments (5)
db/sql/src/info.rs (3)

7-7: Import of tracing::trace is necessary

The use tracing::trace; statement is appropriate as the trace! macro is used later in the code for logging purposes.


471-475: Ensure all fields of IndexerStateInfo are initialized

In the get_indexer_state_info method, only latest_block_number is set, while latest_log_block_number and latest_log_checksum are defaulted. Verify if these fields should be initialized with specific values from the database to prevent potential inconsistencies.


481-508: Consider updating all relevant fields in set_indexer_state_info

The set_indexer_state_info method only updates last_indexed_block. Ensure that latest_log_block_number and latest_log_checksum are updated appropriately to maintain consistency in the indexer state.

hoprd/rest-api/src/node.rs (1)

426-428: Verify completeness of IndexerStateInfo data

When calling hopr.get_indexer_state(), ensure that IndexerStateInfo includes valid data for latest_log_block_number and latest_log_checksum. Since these fields might be defaulted, verify that they are correctly retrieved and populated to prevent returning inaccurate information in the API response.

chain/indexer/src/block.rs (1)

61-61: Updated type constraints are appropriate

Extending the Db type constraints to include HoprDbInfoOperations and HoprDbLogOperations is necessary for the new methods used in the indexer.

Copy link
Contributor

@NumberFour8 NumberFour8 left a comment

Choose a reason for hiding this comment

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

Crate version bump missing

@NumberFour8 NumberFour8 disabled auto-merge January 8, 2025 13:22
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jan 8, 2025
@tolbrino tolbrino enabled auto-merge January 9, 2025 08:12
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

🧹 Nitpick comments (1)
db/sql/src/info.rs (1)

493-497: Improve trace logging message

The current trace message could be more descriptive.

Consider updating the trace message:

-        "update block"
+        "updating last indexed block number"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dbcc76 and a3280c1.

📒 Files selected for processing (1)
  • db/sql/src/info.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-smoke-websocket
  • GitHub Check: tests-unit
  • GitHub Check: Linter
  • GitHub Check: tests-smart-contracts
🔇 Additional comments (2)
db/sql/src/info.rs (2)

102-106: LGTM! Method signatures are well-defined.

The new trait methods follow the established pattern of the codebase with proper async and transaction handling.


Line range hint 584-687: Add test coverage for new indexer state methods

The new methods get_indexer_state_info and set_indexer_state_info lack test coverage. Consider adding tests to verify:

  1. Default state after initialization
  2. Setting and retrieving indexer state
  3. Edge cases and error conditions

Would you like me to help generate the test cases?

@tolbrino tolbrino added this pull request to the merge queue Jan 9, 2025
Merged via the queue into master with commit c42b129 Jan 9, 2025
27 of 28 checks passed
@tolbrino tolbrino deleted the tb/20250108-api-block-number branch January 9, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indexerBlock or indexBlockPrevChecksum is wrong in the 2.2.0 API /info/ route
2 participants