Skip to content

feat(dash-spv): add --birth-height CLI flag#849

Open
xdustinface wants to merge 1 commit into
devfrom
feat/birth-height-cli
Open

feat(dash-spv): add --birth-height CLI flag#849
xdustinface wants to merge 1 commit into
devfrom
feat/birth-height-cli

Conversation

@xdustinface

@xdustinface xdustinface commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Let the SPV CLI set the wallet birth height so header, filter-header and filter sync anchor at the nearest checkpoint at or before it instead of syncing the whole chain from genesis. now/latest resolves to the highest bundled checkpoint, the right anchor for a brand-new wallet with no prior history. An unspecified value keeps the previous full-scan default of genesis.

Based on:

Summary by CodeRabbit

  • New Features
    • Added an optional --birth-height CLI option to set the wallet’s initial anchoring height.
    • Supports genesis, the latest checkpoint, or a specified numeric block height.
    • Invalid height values are rejected with clear input validation.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The SPV CLI adds an optional --birth-height argument. It resolves omitted, numeric, now, and latest values into a concrete height, then passes that height to wallet creation. Unit tests cover the resolution behavior and invalid input handling.

Changes

Birth height CLI flow

Layer / File(s) Summary
Birth-height input and resolution
dash-spv/src/main.rs
Adds --birth-height and resolves omitted values to genesis, aliases to the latest network checkpoint, numeric strings directly, and invalid strings to errors.
Wallet initialization and validation
dash-spv/src/main.rs
Passes the resolved height into wallet creation and tests all supported resolution cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant resolve_birth_height
  participant CheckpointManager
  participant Wallet
  CLI->>resolve_birth_height: birth-height argument and network
  resolve_birth_height->>CheckpointManager: resolve now/latest
  CheckpointManager-->>resolve_birth_height: latest checkpoint height
  resolve_birth_height-->>CLI: concrete birth height
  CLI->>Wallet: create wallet with birth height
Loading

Possibly related PRs

Suggested labels: ready-for-review

Suggested reviewers: zocolini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the --birth-height CLI flag to dash-spv.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/birth-height-cli

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.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.29%. Comparing base (b536179) to head (9b1e709).

Files with missing lines Patch % Lines
dash-spv/src/main.rs 92.85% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #849      +/-   ##
==========================================
- Coverage   74.29%   74.29%   -0.01%     
==========================================
  Files         325      325              
  Lines       73910    73938      +28     
==========================================
+ Hits        54911    54931      +20     
- Misses      18999    19007       +8     
Flag Coverage Δ
core 77.08% <ø> (ø)
ffi 51.12% <ø> (-0.02%) ⬇️
rpc 20.00% <ø> (ø)
spv 91.07% <92.85%> (-0.03%) ⬇️
wallet 73.47% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/main.rs 57.39% <92.85%> (+3.13%) ⬆️

... and 6 files with indirect coverage changes

@xdustinface xdustinface force-pushed the feat/anchor-to-checkpoint branch 2 times, most recently from 02850d4 to efef0e9 Compare July 9, 2026 06:47
@xdustinface xdustinface force-pushed the feat/birth-height-cli branch from 3728bec to 72f89de Compare July 9, 2026 06:48
Base automatically changed from feat/anchor-to-checkpoint to dev July 9, 2026 13:13
Let the SPV CLI set the wallet birth height so header, filter-header and filter sync anchor at the nearest checkpoint at or before it instead of syncing the whole chain from genesis. `now`/`latest` resolves to the highest bundled checkpoint, the right anchor for a brand-new wallet with no prior history. An unspecified value keeps the previous full-scan default of genesis.
@xdustinface xdustinface force-pushed the feat/birth-height-cli branch from 72f89de to 9b1e709 Compare July 13, 2026 02:55
@xdustinface xdustinface marked this pull request as ready for review July 13, 2026 02:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
dash-spv/src/main.rs (2)

118-128: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inconsistent "now" semantics between --start-height and --birth-height.

--start-height now resolves to u32::MAX (lines 349-350) while --birth-height now resolves to the latest checkpoint height. Additionally, --start-height doesn't accept "latest" while --birth-height does. Users using both flags may expect the same keyword to behave consistently. Consider aligning the keyword handling or documenting the difference in the CLI help text.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash-spv/src/main.rs` around lines 118 - 128, Align the keyword handling for
start_height and birth_height so “now” and “latest” have consistent semantics
when both options are used. Update the parsing logic associated with
start_height and birth_height to accept the same keywords and resolve them to
the same latest-checkpoint behavior, or explicitly document any intentional
difference in both CLI help descriptions.

472-500: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add test coverage for checkpointless networks.

The test covers Mainnet only. For devnet/regtest, CheckpointManager::for_network has no checkpoints, so "now"/"latest" resolve to 0 (or an error, if the suggested fix is applied). Adding this edge case would prevent regressions.

🧪 Suggested test additions
         // Non-numeric junk is rejected.
         assert!(resolve_birth_height(&Some("abc".to_string()), Network::Mainnet).is_err());
+
+        // Devnet has no bundled checkpoints, so "now" resolves to genesis.
+        assert_eq!(
+            resolve_birth_height(&Some("now".to_string()), Network::Devnet).unwrap(),
+            0
+        );
+        assert_eq!(
+            resolve_birth_height(&None, Network::Regtest).unwrap(),
+            0
+        );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash-spv/src/main.rs` around lines 472 - 500, Extend
birth_height_resolves_none_now_and_numeric to cover a checkpointless network
such as Devnet or Regtest: verify how resolve_birth_height handles both "now"
and "latest" when CheckpointManager::for_network(...).last_checkpoint() is
absent, expecting the defined result of 0 or the appropriate error behavior.
Keep the existing Mainnet assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dash-spv/src/main.rs`:
- Around line 304-308: Update the “now”/“latest” branch in the checkpoint-height
parsing logic to avoid silently converting a missing checkpoint into height 0.
When CheckpointManager::for_network(network).last_checkpoint() returns None,
return an explicit error for checkpointless networks; preserve the existing
checkpoint height result when a checkpoint is available.

---

Nitpick comments:
In `@dash-spv/src/main.rs`:
- Around line 118-128: Align the keyword handling for start_height and
birth_height so “now” and “latest” have consistent semantics when both options
are used. Update the parsing logic associated with start_height and birth_height
to accept the same keywords and resolve them to the same latest-checkpoint
behavior, or explicitly document any intentional difference in both CLI help
descriptions.
- Around line 472-500: Extend birth_height_resolves_none_now_and_numeric to
cover a checkpointless network such as Devnet or Regtest: verify how
resolve_birth_height handles both "now" and "latest" when
CheckpointManager::for_network(...).last_checkpoint() is absent, expecting the
defined result of 0 or the appropriate error behavior. Keep the existing Mainnet
assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 78c4a853-140c-410b-a577-91b194d565da

📥 Commits

Reviewing files that changed from the base of the PR and between b536179 and 9b1e709.

📒 Files selected for processing (1)
  • dash-spv/src/main.rs

Comment thread dash-spv/src/main.rs
@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant