Skip to content

feat(dash-spv)!: make the storage private and add header queries to DashSpvClient - #1176

Merged
xdustinface merged 1 commit into
devfrom
feat/spv-private-storage
Oct 16, 2026
Merged

xdustinface merged 1 commit into
devfrom
feat/spv-private-storage

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Platform reads headers through the storage internals (client.storage() → block_headers()). This makes the storage internal and gives the client the queries it needs.

  • dash_spv::storage is no longer exported, and DashSpvClient<W, N> is no longer generic over the storage.
  • DashSpvClient::new no longer takes a storage: it opens a DiskStorageManager at config.storage_path.
  • storage() is replaced by tip_header(), header_at(height) and header_height(&BlockHash). A missing header is Ok(None), distinct from a read error.
  • Integration tests and the storage bench reach the storage types through test_utils (test-utils feature).

Breaking: dash_spv::storage is private, DashSpvClient loses its storage type parameter, and DashSpvClient::new and storage() change as above.

Closes #1173

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added access to the current tip header, header lookup by height, and height lookup by block hash.
  • Improvements
    • Client setup now opens disk storage automatically; callers no longer create or pass a storage manager.
    • Storage is no longer exposed through the public storage module or client accessor. The client uses internal disk storage rather than allowing callers to select a storage backend.

PR Hygiene · 8965f47

  • Bots — coderabbitai ✓
  • Self-review — address xdustinface requested changes, then post /self-reviewed
  • Build running
  • Approvals
    • files with no dedicated owner (dash-spv-bench/src/main.rs, dash-spv-ffi/src/client.rs) — QuantumExplorer or xdustinface
    • dash-spv (dash-spv/CLAUDE.md, dash-spv/README.md, dash-spv/benches/storage.rs and 19 more) — QuantumExplorer or xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: dashpay/rust-dashcore/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e21a6043-ed87-432e-b886-b8ba4cebd94a
📥 Commits

Reviewing files that changed from the base of the PR and between 15bdb45 and 8965f47.

📒 Files selected for processing: 9
  • dash-spv/CLAUDE.md
  • dash-spv/README.md
  • dash-spv/src/client/core.rs
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/client/mod.rs
  • dash-spv/src/client/sync_coordinator.rs
  • dash-spv/src/lib.rs
  • dash-spv/tests/dashd_sync/tests_fork.rs
  • dash-spv/tests/dashd_sync/tests_restart.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

DashSpvClient now creates its DiskStorageManager from the client configuration. The client type no longer has a storage-manager parameter or public storage accessor. It adds methods to query the tip header and stored headers. Application entry points, examples, tests, and benchmarks use the updated interface.

Changes: Client storage and header API

Layer / File(s) Summary
Internal storage and header query API
dash-spv/src/client/core.rs, dash-spv/src/client/lifecycle.rs, dash-spv/src/client/events.rs, dash-spv/src/client/queries.rs, dash-spv/src/client/sync_coordinator.rs, dash-spv/src/client/transactions.rs, dash-spv/src/lib.rs
DashSpvClient now uses DiskStorageManager internally and no longer has a storage type parameter or storage() accessor. It adds tip_header(), header_at(), and header_height(). The storage module is private.
Application and public API call sites
dash-spv/src/main.rs, dash-spv-ffi/src/client.rs, dash-spv-bench/src/main.rs, dash-spv/examples/*
The CLI, FFI, benchmark executable, and examples construct the client without passing a storage manager.
Test utilities, validation, and documentation
dash-spv/src/test_utils/mod.rs, dash-spv/src/client/mod.rs, dash-spv/benches/storage.rs, dash-spv/tests/*, dash-spv/README.md, dash-spv/CLAUDE.md
Test utilities re-export storage types. Unit tests and integration-test setup use the updated client type and constructor. Header-query tests use the tip header, and documentation describes storage as internal disk storage.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Suggested reviewers: xdustinface

Merge Risk: ⚪ Minimal · up to 8965f

The change makes storage internal and adds header queries to the client. The supplied evidence shows no concrete merge-blocking problem.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue [#1173] requires DashSpvClient::tip_header() to return Option<HashedBlockHeader>. The current method returns Option<BlockHeaderTip>. BlockHeaderTip stores separate height, BlockHeader,… Change tip_header() to return Option<HashedBlockHeader>. Preserve None for an empty header store. Add or update automated client tests for the required tip and missing-header behavior.
Docstring Coverage Warning Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 22 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: making storage private and adding header queries to DashSpvClient.
Out of Scope Changes check Passed The reviewed changes support the storage encapsulation and public header-query migration in [#1173]. They update client construction, call sites, tests, examples, benchmarks, documentation, and test-o…
Full details: Out of Scope Changes check

Explanation

The reviewed changes support the storage encapsulation and public header-query migration in [#1173]. They update client construction, call sites, tests, examples, benchmarks, documentation, and test-only storage exports. No demonstrated unrelated product change is present.

Full details: Linked Issues check

Explanation

Issue [#1173] requires DashSpvClient::tip_header() to return Option&lt;HashedBlockHeader&gt;. The current method returns Option&lt;BlockHeaderTip&gt;. BlockHeaderTip stores separate height, BlockHeader, and hash fields, so it is not the required HashedBlockHeader type. header_at and header_height have the required Result&lt;Option&lt;_&gt;&gt; shapes and the storage module is private.

Resolution

Change tip_header() to return Option&lt;HashedBlockHeader&gt;. Preserve None for an empty header store. Add or update automated client tests for the required tip and missing-header behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 64.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 22 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ZocoLini
ZocoLini force-pushed the feat/spv-private-storage branch from a6de8d8 to 15bdb45 Compare October 14, 2026 21:01
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 14, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: address xdustinface requested changes, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.87%. Comparing base (c4535d4) to head (8965f47).

Files with missing lines Patch % Lines
dash-spv/src/main.rs 0.00% 11 Missing ⚠️
dash-spv/src/client/core.rs 42.85% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1176   +/-   ##
=======================================
  Coverage   78.86%   78.87%           
=======================================
  Files         304      304           
  Lines       81410    81381   -29     
=======================================
- Hits        64202    64187   -15     
+ Misses      17208    17194   -14     
Flag Coverage Δ
core 77.59% <ø> (ø)
ffi 50.68% <100.00%> (-0.12%) ⬇️
rpc 52.05% <ø> (ø)
spv 92.82% <53.12%> (+0.07%) ⬆️
wallet 82.19% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv-ffi/src/client.rs 42.28% <100.00%> (-2.64%) ⬇️
dash-spv/src/client/events.rs 100.00% <ø> (ø)
dash-spv/src/client/lifecycle.rs 91.37% <100.00%> (ø)
dash-spv/src/client/mod.rs 100.00% <100.00%> (ø)
dash-spv/src/client/queries.rs 43.54% <ø> (ø)
dash-spv/src/client/sync_coordinator.rs 80.83% <ø> (ø)
dash-spv/src/client/transactions.rs 80.00% <ø> (ø)
dash-spv/src/lib.rs 46.66% <ø> (ø)
dash-spv/src/client/core.rs 58.82% <42.85%> (-6.57%) ⬇️
dash-spv/src/main.rs 57.14% <0.00%> (+1.65%) ⬆️

... and 6 files with indirect coverage changes

@xdustinface xdustinface left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Direction looks right. A few things before merge:

1. Platform's offline storage wipe

Platform's offline clear_storage (spv/runtime.rs) opens its own DiskStorageManager, which no longer compiles. It only exists because Platform drops the client on stop() and builds a new one per start. Keeping one client across stop/start and clearing through it would remove it. Is that the plan for the Platform side? If dropping on stop is deliberate (e.g. memory while backgrounded), a client-free DashSpvClient::clear_storage_at(&ClientConfig) would be the alternative.

update_config should also reject a changed storage_path now that the client opens its storage from it.

2. Stale DashSpvClient docs

The doc comment in client/core.rs still describes the S: StorageManager parameter, swappable storage backends, and DiskStorageManager as a third type argument in the examples.

3. No tests for the new queries

anchored_tip / birth_height_anchors_chain_to_nearest_checkpoint in client/mod.rs could assert tip_header(), header_at and header_height against the 200 000 checkpoint, including the Ok(None) cases.

Non-blocking

  • tip_header returns Option and get_tip drops read errors, unlike the other two. get_tip_height + get_header(tip) would give Result<Option<_>>.
  • pub mod sync still exports managers generic over storage traits that are no longer nameable outside the crate. Follow-up to make them pub(crate)?

…ashSpvClient

The storage module is no longer exported, and `DashSpvClient` is no longer
generic over the storage: `new` opens a `DiskStorageManager` at
`config.storage_path` itself. `storage()` is replaced by `tip_header`,
`header_at` and `header_height`. Tests and benches reach the storage types
through `test_utils`.

Closes #1173

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@xdustinface

1 - I talked with them, we already have a method in the SPV CLient to clear the storage, there is no point on exposing the entire storage. About the update config method, I think is not even tested and a lot of stuff cant be really changed runtime, I would drop that feature entirely and force everyone to create a new client if they want to change the configuration, avoiding possible issues. No body uses the method here or in platform

2 - Done

3 - I dont really see the point on having a test for a facade without logic, can you explain why you think they are important to have here??

About pub mod sync, I will take care of them in a different PR, no point on having them exposed I think but it is out of the scope of this one, just in case I have to adjust something different else

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: address xdustinface requested changes, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 16, 2026
@xdustinface
xdustinface merged commit d35a8d6 into dev Oct 16, 2026
44 of 45 checks passed
@xdustinface
xdustinface deleted the feat/spv-private-storage branch October 16, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dash-spv: public header queries on DashSpvClient

2 participants