-
Notifications
You must be signed in to change notification settings - Fork 98
Allow tracking fast-sync progress and Indexer data source #6789
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
Allow tracking fast-sync progress and Indexer data source #6789
Conversation
📝 WalkthroughWalkthroughThis pull request introduces enhancements to the HOPR indexer's synchronization process and metrics tracking. The changes include the addition of a new metric Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
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: 1
🧹 Nitpick comments (3)
chain/indexer/src/block.rs (3)
167-172
: Consider movingFastSyncMode
enum to the module level for better code organization.The
FastSyncMode
enum is currently defined within thestart
method. If you plan to useFastSyncMode
elsewhere or want to improve code clarity, consider moving it to the module level.
506-520
: Update function documentation to match parameter changes incalculate_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 parameterscurrent_block
andstart_block
for clarity.
208-212
: Refactor duplicate metric updates forMETRIC_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
📒 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
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
🧹 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:
- Add error handling for database operations that could fail
- Ensure metrics are updated even if operations fail
- 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
📒 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.
hopr_indexer_data_source
metric which contains the currentsource
of on-chain data:fast-sync
orrpc
Closes #6780
Closes #6781