Skip to content

feat(dash-spv): floor mainnet sync at HD/BIP39 activation height#877

Merged
QuantumExplorer merged 1 commit into
devfrom
feat/mainnet-hd-wallet-sync-floor
Jul 13, 2026
Merged

feat(dash-spv): floor mainnet sync at HD/BIP39 activation height#877
QuantumExplorer merged 1 commit into
devfrom
feat/mainnet-hd-wallet-sync-floor

Conversation

@xdustinface

@xdustinface xdustinface commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Floor mainnet sync at block 227121, the height from which HD/BIP39 wallets could first exist on chain. No address any HD wallet derives can appear before it, so syncing the pre-HD-wallet chain is wasted work. This matches the entry in DashSync's mainnet_checkpoint_array commented "first sync time (aka BIP39 creation time)", the value the official Dash mobile SPV client uses.

Add MAINNET_HD_ACTIVATION_HEIGHT and a NetworkExt::hd_wallet_sync_floor() method to the dash crate, alongside known_genesis_block_hash where the other per-network chain constants live (mainnet returns the floor, other networks return 0, meaning sync from genesis). When the caller sets no explicit start_from_height, DashSpvClient::new floors the wallet-derived birth height via birth_height.max(config.network.hd_wallet_sync_floor()), so a low or zero birth height can no longer drag mainnet sync back to genesis. Anchoring reuses the existing checkpoint machinery and snaps to the nearest checkpoint at or before the floor (the 200000 checkpoint), a safe undershoot that never skips a block that could hold an HD wallet transaction. An explicit start_from_height is still honored downward, and testnet/regtest/devnet are unaffected.

Summary by CodeRabbit

  • Bug Fixes
    • Improved wallet synchronization starting points on mainnet by preventing scans before the supported HD wallet activation height.
    • Corrected checkpoint selection for wallets with missing, early, or later birth heights.
    • Preserved configured synchronization start heights when explicitly provided.
    • Updated behavior across other networks without introducing a synchronization floor.

Floor mainnet sync at block 227121, the height from which HD/BIP39 wallets could first exist on chain. No address any HD wallet derives can appear before it, so syncing the pre-HD-wallet chain is wasted work. This matches the entry in DashSync's `mainnet_checkpoint_array` commented "first sync time (aka BIP39 creation time)", the value the official Dash mobile SPV client uses.

Add `MAINNET_HD_ACTIVATION_HEIGHT` and a `NetworkExt::hd_wallet_sync_floor()` method to the `dash` crate, alongside `known_genesis_block_hash` where the other per-network chain constants live (mainnet returns the floor, other networks return `0`, meaning sync from genesis). When the caller sets no explicit `start_from_height`, `DashSpvClient::new` floors the wallet-derived birth height via `birth_height.max(config.network.hd_wallet_sync_floor())`, so a low or zero birth height can no longer drag mainnet sync back to genesis. Anchoring reuses the existing checkpoint machinery and snaps to the nearest checkpoint at or before the floor (the 200000 checkpoint), a safe undershoot that never skips a block that could hold an HD wallet transaction. An explicit `start_from_height` is still honored downward, and testnet/regtest/devnet are unaffected.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5c31ee7d-c5d3-4ab3-9034-0c5f544770f2

📥 Commits

Reviewing files that changed from the base of the PR and between b536179 and 202b0a1.

📒 Files selected for processing (3)
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/client/mod.rs
  • dash/src/network/constants.rs

📝 Walkthrough

Walkthrough

The network API now exposes an HD wallet synchronization floor, with a mainnet-specific activation height. DashSpvClient applies this floor to wallet-derived start heights, and checkpoint anchoring tests reflect the updated behavior.

Changes

Wallet sync floor

Layer / File(s) Summary
Network sync-floor contract
dash/src/network/constants.rs
Adds the mainnet HD activation constant, extends NetworkExt with hd_wallet_sync_floor(), implements network-specific values, and tests the results.
Client start-height anchoring
dash-spv/src/client/lifecycle.rs, dash-spv/src/client/mod.rs
Clamps wallet-derived start heights to the network floor and updates checkpoint anchoring expectations while preserving explicit start-height overrides.

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

Sequence Diagram(s)

sequenceDiagram
  participant DashSpvClient
  participant Wallet
  participant NetworkExt
  DashSpvClient->>Wallet: earliest_required_height()
  DashSpvClient->>NetworkExt: hd_wallet_sync_floor()
  DashSpvClient->>DashSpvClient: Clamp start height and select checkpoint
Loading

Possibly related PRs

Suggested labels: ready-for-review

Suggested reviewers: zocolini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: flooring Dash mainnet SPV sync at the HD/BIP39 activation height.
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.
✨ 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/mainnet-hd-wallet-sync-floor

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 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.28%. Comparing base (b536179) to head (202b0a1).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #877      +/-   ##
==========================================
- Coverage   74.29%   74.28%   -0.02%     
==========================================
  Files         325      325              
  Lines       73910    73923      +13     
==========================================
+ Hits        54911    54913       +2     
- Misses      18999    19010      +11     
Flag Coverage Δ
core 77.09% <100.00%> (+0.01%) ⬆️
ffi 51.12% <ø> (-0.02%) ⬇️
rpc 20.00% <ø> (ø)
spv 91.04% <100.00%> (-0.06%) ⬇️
wallet 73.47% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/client/lifecycle.rs 92.26% <100.00%> (+0.04%) ⬆️
dash-spv/src/client/mod.rs 100.00% <100.00%> (ø)
dash/src/network/constants.rs 85.11% <100.00%> (+1.04%) ⬆️

... and 3 files with indirect coverage changes

@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jul 13, 2026
@QuantumExplorer
QuantumExplorer merged commit 0ae8df4 into dev Jul 13, 2026
62 of 63 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/mainnet-hd-wallet-sync-floor branch July 13, 2026 13:22
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.

2 participants