Skip to content

Conversation

NumberFour8
Copy link
Contributor

  • Adds a fast-sync progress tracking, which then follows with the normal RPC sync.
  • Adds new hopr_indexer_data_source metric which contains the current source of on-chain data: fast-sync or rpc

Closes #6780
Closes #6781

- Adds a fast-sync progress tracking, which then follows with the normal RPC sync.

- Adds new `hopr_indexer_data_source` metric which contains the current `source` of on-chain data: `fast-sync` or `rpc`

Closes #6780
Closes #6781
@NumberFour8 NumberFour8 self-assigned this Jan 19, 2025
@NumberFour8 NumberFour8 marked this pull request as ready for review January 19, 2025 14:48
Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the HOPR indexer's synchronization process and metrics tracking. The changes include the addition of a new metric hopr_indexer_data_source to monitor the current data source of the Indexer and the refinement of synchronization logic through the introduction of a FastSyncMode enum. These modifications aim to improve visibility into the indexing process, especially during fast sync scenarios, and enhance the accuracy of sync progress tracking.

Changes

File Change Summary
METRICS.md Added new metric hopr_indexer_data_source to track Indexer's data source
chain/indexer/src/block.rs - Introduced METRIC_INDEXER_SYNC_SOURCE MultiGauge metric
- Added FastSyncMode enum for sync state management
- Updated calculate_sync_process method signature and logic

Assessment against linked issues

Objective Addressed Explanation
Provide sync process metrics during fast sync [#6780]
Expose information about sync mode (fast/normal) [#6781]

Possibly related PRs

  • Update sea orm and sea query #6509: The changes in this PR involve updates to the Cargo.toml file, which may indirectly affect the metrics and synchronization logic in the main PR by altering dependencies related to database operations, but there is no direct code-level connection to the specific metrics or synchronization changes made in the main PR.

Suggested labels

dependencies

Suggested reviewers

  • tolbrino

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.

@NumberFour8 NumberFour8 requested a review from a team January 19, 2025 14:48
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 (3)
chain/indexer/src/block.rs (3)

167-172: Consider moving FastSyncMode enum to the module level for better code organization.

The FastSyncMode enum is currently defined within the start method. If you plan to use FastSyncMode elsewhere or want to improve code clarity, consider moving it to the module level.


506-520: Update function documentation to match parameter changes in calculate_sync_process.

The documentation for calculate_sync_process refers to parameters that may not align with the updated function signature. Please update the doc comments to reflect the current parameters current_block and start_block for clarity.


208-212: Refactor duplicate metric updates for METRIC_INDEXER_SYNC_SOURCE.

The code for updating METRIC_INDEXER_SYNC_SOURCE is duplicated in both the fast-sync and RPC sync sections. Consider extracting this logic into a helper function to reduce duplication and enhance maintainability.

Apply this diff to refactor the code:

-                {
-                    METRIC_INDEXER_SYNC_SOURCE.set(&["fast-sync"], 1.0);
-                    METRIC_INDEXER_SYNC_SOURCE.set(&["rpc"], 0.0);
-                }
+                Self::update_sync_source_metrics("fast-sync");

And define the helper function outside the methods:

fn update_sync_source_metrics(source: &str) {
    #[cfg(all(feature = "prometheus", not(test)))]
    {
        METRIC_INDEXER_SYNC_SOURCE.set(&["fast-sync"], if source == "fast-sync" { 1.0 } else { 0.0 });
        METRIC_INDEXER_SYNC_SOURCE.set(&["rpc"], if source == "rpc" { 1.0 } else { 0.0 });
    }
}

Also applies to: 258-262

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9bb870 and 0c51017.

📒 Files selected for processing (2)
  • METRICS.md (1 hunks)
  • chain/indexer/src/block.rs (7 hunks)
🧰 Additional context used
🪛 LanguageTool
METRICS.md

[uncategorized] ~69-~69: Loose punctuation mark.
Context: ...r checksum. - hopr_indexer_data_source: Current data source of the Indexer, key...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ 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-smoke-websocket
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-smart-contracts
  • GitHub Check: Linter
  • GitHub Check: tests-unit

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

🧹 Nitpick comments (2)
chain/indexer/src/block.rs (2)

202-231: Enhance error handling in fast sync logic.

While the implementation is thorough, consider improving error handling:

  1. Add error handling for database operations that could fail
  2. Ensure metrics are updated even if operations fail
  3. Consider using a cleanup pattern to reset metrics on failure
 if FastSyncMode::None != will_perform_fast_sync {
+    let _metrics_guard = scopeguard::guard((), |_| {
+        #[cfg(all(feature = "prometheus", not(test)))]
+        {
+            METRIC_INDEXER_SYNC_SOURCE.set(&["fast-sync"], 0.0);
+            METRIC_INDEXER_SYNC_SOURCE.set(&["rpc"], 0.0);
+        }
+    });
+
     #[cfg(all(feature = "prometheus", not(test)))]
     {
         METRIC_INDEXER_SYNC_SOURCE.set(&["fast-sync"], 1.0);
         METRIC_INDEXER_SYNC_SOURCE.set(&["rpc"], 0.0);
     }

530-546: Guard against potential overflow in progress calculation.

The block difference calculation and progress computation could overflow for very large block numbers. Consider using checked arithmetic operations.

-            let mut block_difference = head.saturating_sub(start_block);
+            let mut block_difference = match head.checked_sub(start_block) {
+                Some(diff) => diff,
+                None => {
+                    error!("Invalid block range: head {} < start_block {}", head, start_block);
+                    return;
+                }
+            };

-                (current_block - start_block) as f64 / block_difference as f64
+                match current_block.checked_sub(start_block) {
+                    Some(progress) => progress as f64 / block_difference as f64,
+                    None => {
+                        error!("Invalid progress calculation: current {} < start {}", current_block, start_block);
+                        return;
+                    }
+                }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c51017 and 173f0e5.

📒 Files selected for processing (1)
  • chain/indexer/src/block.rs (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-unit
  • GitHub Check: tests-smoke-websocket
  • GitHub Check: Linter
🔇 Additional comments (3)
chain/indexer/src/block.rs (3)

23-44: Well-structured metrics implementation!

The metrics are properly defined with clear descriptions and appropriate types. The new METRIC_INDEXER_SYNC_SOURCE metric effectively tracks the data source using labels, which aligns with the PR objectives.


167-172: Well-designed FastSyncMode enum!

The enum effectively models the different sync states and provides clear semantics for the sync process.


1069-1069: Comprehensive test coverage!

The test suite thoroughly covers different sync scenarios, edge cases, and failure modes. The test structure is clear and maintainable.

@NumberFour8 NumberFour8 merged commit 519e063 into release/singapore Jan 22, 2025
28 of 29 checks passed
@NumberFour8 NumberFour8 deleted the feature/sync-progress-and-source-metric branch January 22, 2025 09:00
NumberFour8 added a commit that referenced this pull request Jan 31, 2025
…6835)

Co-authored-by: ausias-armesto <ausiasarmesto@gmail.com>
Co-authored-by: QYuQianchen <10935300+QYuQianchen@users.noreply.github.com>
Co-authored-by: Tibor <9529609+Teebor-Choka@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants