Skip to content

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Jan 15, 2026

Introduces get_tip() -> Option<HashesBlockHeader> in BlockHeaderStorage. This consolidates two-step pattern of get_tip_height() followed by get_header(tip_height) into a single get_tip() call. I didn't adjust any of the other places (except for one) where it's currently possible to be used since they are in the "old" sync code and this PR here is more like a preparation to be used by the sync rewrite.

Based on:

Summary by CodeRabbit

  • Refactor
    • Optimized block tip hash retrieval by eliminating intermediate lookups, reducing computational overhead and improving query responsiveness
    • Enhanced block storage interface with streamlined access to current block header tip information
    • Simplified internal control flow while maintaining complete backward compatibility with existing APIs

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

The changes refactor the tip hash retrieval mechanism by introducing a new get_tip() method on the storage API that returns a BlockHeaderTip struct containing height, header, and hash. This simplifies client-side code by eliminating sequential height and header lookups, replacing them with a single storage call.

Changes

Cohort / File(s) Summary
Storage API Enhancement
dash-spv/src/storage/blocks.rs, dash-spv/src/storage/mod.rs
Added new public BlockHeaderTip struct with height, header, and hash fields. Extended BlockHeaderStorage trait with async get_tip() method. Implemented get_tip() in PersistentBlockHeaderStorage to retrieve current tip and construct BlockHeaderTip. Exposed BlockHeaderTip in storage module imports. Includes test validation.
Client Refactoring
dash-spv/src/client/core.rs
Updated tip_hash() implementation to directly call storage.get_tip() instead of fetching tip height then header separately. Preserves return type and API contract while streamlining internal logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A simpler path, the storage gleams,
No more chasing height-header dreams!
BlockHeaderTip hops into sight,
One call replaces three—what delight! 🐰✨
The client code now runs so light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing a new BlockHeaderStorage.get_tip helper method that consolidates tip retrieval logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Base automatically changed from refactor/test-utils-modules to v0.42-dev January 16, 2026 22:49
Introduces `get_tip() -> Option<BlockHeaderTip>` in `BlockHeaderStorage`. This consolidates two-step pattern of `get_tip_height()` followed by `get_header(tip_height)` into a single `get_tip()` call. I didn't adjust any of the other places (except for one) where it's currently possible to be used since they are in the "old" sync code and this PR here is more like a preparation to be used by the sync rewrite.
@xdustinface xdustinface force-pushed the feat/header-storage-get-tip branch from 4eb3e3d to a5c50dd Compare January 16, 2026 22:59
@xdustinface xdustinface marked this pull request as ready for review January 16, 2026 23:21
@xdustinface xdustinface merged commit 831b889 into v0.42-dev Jan 17, 2026
53 checks passed
@xdustinface xdustinface deleted the feat/header-storage-get-tip branch January 17, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants