Skip to content

refactor: rename wallet heights to reflect their meaning better#683

Merged
xdustinface merged 2 commits intov0.42-devfrom
refactor/rename-wallet-heights
Apr 24, 2026
Merged

refactor: rename wallet heights to reflect their meaning better#683
xdustinface merged 2 commits intov0.42-devfrom
refactor/rename-wallet-heights

Conversation

@xdustinface
Copy link
Copy Markdown
Collaborator

@xdustinface xdustinface commented Apr 23, 2026

Rename:

  • synced_height -> last_processed_height
  • filter_committed_height -> synced_height

Summary by CodeRabbit

Release Notes

  • Refactor

    • Improved wallet height synchronization logic for more accurate tracking of processed blocks and UTXO confirmation states during transaction building and coin selection.
  • API Changes

    • Updated FFI wallet manager API: renamed height-retrieval function for consistency with internal height tracking semantics.

Rename the wallet-applied chain height from synced_height to last_processed_height across key-wallet, key-wallet-manager, key-wallet-ffi, and dash-spv call sites.

This also updates the FFI symbol managed_wallet_last_processed_height and picks up rename sites introduced by newer v0.42-dev changes. filter_committed_height is left unchanged here so the next commit can rename that concept to synced_height with a clear diff.
Rename the committed filter-scan checkpoint from filter_committed_height to synced_height in the wallet interface, wallet manager, and filter sync manager.

With synced_height already moved to last_processed_height in the previous commit, synced_height now clearly names the durable committed restart point.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

This change systematically refactors block height tracking semantics throughout the wallet codebase, replacing synced_height with last_processed_height as the primary height-tracking concept. The refactoring spans sync managers, wallet interfaces, FFI bindings, and implementation logic, updating both trait definitions and all consuming code to use the new height semantics.

Changes

Cohort / File(s) Summary
Sync Managers
dash-spv/src/sync/blocks/manager.rs, dash-spv/src/sync/filters/manager.rs
Block and filter manager initialization now seed progress from last_processed_height() instead of synced_height() or filter_committed_height(). Commit handling persists heights via updated wallet interface methods.
FFI API Layer
key-wallet-ffi/FFI_API.md, key-wallet-ffi/src/managed_wallet.rs, key-wallet-ffi/src/transaction.rs, key-wallet-ffi/src/utxo.rs, key-wallet-ffi/src/utxo_tests.rs, key-wallet-ffi/src/wallet_manager.rs, key-wallet-ffi/src/wallet_manager_tests.rs
FFI exports and implementations switch from managed_wallet_synced_height to managed_wallet_last_processed_height; all C-FFI callsites that provided height context (coin selection, UTXO confirmation counting) now use last_processed_height().
Wallet Manager Core
key-wallet-manager/src/lib.rs, key-wallet-manager/src/process_block.rs
WalletManager struct field refactoring removes filter_committed_height, renames synced_height to last_processed_height. Block processing now updates last_processed_height while update_synced_height conditionally bumps it when new heights exceed current state.
Wallet Interfaces
key-wallet-manager/src/wallet_interface.rs, key-wallet-manager/src/test_utils/mock_wallet.rs
Trait methods renamed: synced_height()/update_synced_height() become last_processed_height()/update_last_processed_height(); default implementations reworked to provide synced_height() backed by last_processed_height().
Wallet Implementation
key-wallet/src/wallet/metadata.rs, key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs, key-wallet/src/managed_account/mod.rs, key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
WalletMetadata field updated; wallet interface adds get_spendable_utxos() and renames height methods to last_processed_height(); account balance and spendability checks use new height semantics.
Transaction Checking
key-wallet/src/transaction_checking/wallet_checker.rs
Documentation and test logic updated to reference last_processed_height for maturity and coinbase evaluation; height-update calls use new interface methods.
Tests & Examples
key-wallet-manager/tests/integration_test.rs, key-wallet-manager/tests/spv_integration_tests.rs, key-wallet-manager/examples/wallet_creation.rs, key-wallet/src/tests/balance_tests.rs
All test assertions and example code switch from synced_height() to last_processed_height() for querying and from update_synced_height() to update_last_processed_height() for updates.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • ZocoLini

Poem

🐰 A rabbit hops through heights anew,
Trading "synced" for "last processed" too,
From sync to filter, wallets all agree—
Heights refactored, semantically free! 🌾✨

🚥 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 accurately summarizes the main refactoring objective: renaming wallet height fields to better reflect their semantic meaning throughout the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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

✨ 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 refactor/rename-wallet-heights

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.

@xdustinface xdustinface marked this pull request as draft April 23, 2026 22:46
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 69.33333% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.15%. Comparing base (62d7af7) to head (ceb349f).
⚠️ Report is 4 commits behind head on v0.42-dev.

Files with missing lines Patch % Lines
key-wallet-manager/src/process_block.rs 71.42% 6 Missing ⚠️
...allet/managed_wallet_info/wallet_info_interface.rs 53.84% 6 Missing ⚠️
key-wallet-manager/src/wallet_interface.rs 0.00% 5 Missing ⚠️
key-wallet-ffi/src/managed_wallet.rs 0.00% 2 Missing ⚠️
key-wallet-manager/src/lib.rs 60.00% 2 Missing ⚠️
key-wallet-ffi/src/transaction.rs 0.00% 1 Missing ⚠️
key-wallet-ffi/src/utxo.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #683      +/-   ##
=============================================
- Coverage      70.40%   70.15%   -0.26%     
=============================================
  Files            247      319      +72     
  Lines          48029    66692   +18663     
=============================================
+ Hits           33816    46789   +12973     
- Misses         14213    19903    +5690     
Flag Coverage Δ
core 75.81% <ø> (-0.01%) ⬇️
ffi 44.66% <20.00%> (+1.32%) ⬆️
rpc 20.00% <ø> (ø)
spv 86.55% <100.00%> (+0.17%) ⬆️
wallet 68.77% <69.35%> (?)
Files with missing lines Coverage Δ
dash-spv/src/sync/blocks/manager.rs 94.69% <100.00%> (ø)
dash-spv/src/sync/filters/manager.rs 96.65% <100.00%> (-0.30%) ⬇️
key-wallet-ffi/src/wallet_manager.rs 69.39% <100.00%> (+0.60%) ⬆️
key-wallet/src/managed_account/mod.rs 55.05% <100.00%> (ø)
...-wallet/src/transaction_checking/wallet_checker.rs 99.28% <100.00%> (ø)
...c/wallet/managed_wallet_info/asset_lock_builder.rs 79.57% <100.00%> (ø)
key-wallet-ffi/src/transaction.rs 0.00% <0.00%> (ø)
key-wallet-ffi/src/utxo.rs 56.07% <0.00%> (-35.52%) ⬇️
key-wallet-ffi/src/managed_wallet.rs 60.10% <0.00%> (+1.44%) ⬆️
key-wallet-manager/src/lib.rs 61.18% <60.00%> (ø)
... and 3 more

... and 89 files with indirect coverage changes

@xdustinface xdustinface marked this pull request as ready for review April 24, 2026 14:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
key-wallet-ffi/src/wallet_manager_tests.rs (1)

433-464: Nit: stale test name after rename.

The test function is still named test_wallet_manager_synced_height but it now exercises update_last_processed_height and wallet_manager_current_height. Consider renaming to keep intent aligned with the new terminology (e.g., test_wallet_manager_last_processed_height or test_wallet_manager_current_height). Note also that after commit 2 in this PR, synced_height has been repurposed to mean the filter-committed checkpoint, so the current name is now actively misleading.

♻️ Proposed rename
-    fn test_wallet_manager_synced_height() {
+    fn test_wallet_manager_last_processed_height() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@key-wallet-ffi/src/wallet_manager_tests.rs` around lines 433 - 464, Rename
the test function test_wallet_manager_synced_height to a name that matches its
behavior (e.g., test_wallet_manager_last_processed_height) and update any
references; specifically change the fn name and any mentions in comments to
reflect that the test exercises wallet_manager_current_height and the
manager_guard.update_last_processed_height flow (look for
wallet_manager::wallet_manager_create,
wallet_manager::wallet_manager_current_height, and update_last_processed_height
to locate the test).
dash-spv/src/sync/filters/manager.rs (1)

817-820: Prefer setting synced_height directly in these filter-manager tests.

These tests currently set last_processed_height and rely on MockWallet’s default delegation. Setting update_synced_height(...) directly would better encode the contract under test and reduce future fragility if MockWallet decouples the two heights.

Suggested test-intent alignment
-        wallet.update_last_processed_height(50);
+        wallet.update_synced_height(50);
...
-        manager.wallet.write().await.update_last_processed_height(100);
+        manager.wallet.write().await.update_synced_height(100);
...
-        manager.wallet.write().await.update_last_processed_height(100);
+        manager.wallet.write().await.update_synced_height(100);

Also applies to: 1047-1047, 1124-1124

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv/src/sync/filters/manager.rs` around lines 817 - 820, The tests set
the mock wallet's last_processed_height via
MockWallet::update_last_processed_height, but reviewer asks to set the synced
height directly to better express the contract; replace calls to
update_last_processed_height(50) (and similar uses at other test sites) with
MockWallet::update_synced_height(50) while keeping the same
Arc::new(RwLock::new(wallet)) wrapping and MockWallet::new() initialization so
the wallet state used by FilterManager tests reflects synced_height explicitly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@key-wallet-manager/src/lib.rs`:
- Around line 347-349: When importing wallets you currently set birth height
from self.last_processed_height (via
managed_info.set_birth_height(self.last_processed_height)), which can skip the
[self.synced_height, self.last_processed_height) window; change these calls to
use self.synced_height instead (i.e.,
managed_info.set_birth_height(self.synced_height)) so
earliest_required_height()/birth_height logic sees historical blocks. Update the
initial occurrence around T::from_wallet(...) and the other analogous places
where set_birth_height is assigned from self.last_processed_height (the other
two import sites that also call set_first_loaded_at(...)) to use
self.synced_height.

In `@key-wallet-manager/src/wallet_interface.rs`:
- Around line 88-105: Existing external implementors still implement
synced_height and update_synced_height, so restore backward compatibility by
making the old methods default and delegating between old and new names: keep
the new required methods last_processed_height and update_last_processed_height,
but provide default implementations for synced_height() that return
self.last_processed_height() and for update_synced_height(&mut self, h) that
call self.update_last_processed_height(h) (and annotate them #[deprecated] with
a brief message); likewise ensure the new methods have sensible defaults that
call the old ones if present to cover both implementation styles (use the
function symbols last_processed_height, update_last_processed_height,
synced_height, update_synced_height).

In `@key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs`:
- Around line 68-69: The new required methods on the WalletInfoInterface trait
(the newly added get_spendable_utxos() and the renamed last_processed_height
APIs) are a source-breaking change for external implementors; restore
compatibility by providing default implementations on WalletInfoInterface for
get_spendable_utxos() and for the new last_processed_height accessors that
forward to the old methods (or return sensible defaults), and mark the old
methods as deprecated (or keep them as default shims that call the new
implementations) so downstream crates continue to compile until you cut a
breaking release. Ensure you reference the trait name WalletInfoInterface and
the method names get_spendable_utxos and last_processed_height when adding the
defaults and deprecation annotations.

---

Nitpick comments:
In `@dash-spv/src/sync/filters/manager.rs`:
- Around line 817-820: The tests set the mock wallet's last_processed_height via
MockWallet::update_last_processed_height, but reviewer asks to set the synced
height directly to better express the contract; replace calls to
update_last_processed_height(50) (and similar uses at other test sites) with
MockWallet::update_synced_height(50) while keeping the same
Arc::new(RwLock::new(wallet)) wrapping and MockWallet::new() initialization so
the wallet state used by FilterManager tests reflects synced_height explicitly.

In `@key-wallet-ffi/src/wallet_manager_tests.rs`:
- Around line 433-464: Rename the test function
test_wallet_manager_synced_height to a name that matches its behavior (e.g.,
test_wallet_manager_last_processed_height) and update any references;
specifically change the fn name and any mentions in comments to reflect that the
test exercises wallet_manager_current_height and the
manager_guard.update_last_processed_height flow (look for
wallet_manager::wallet_manager_create,
wallet_manager::wallet_manager_current_height, and update_last_processed_height
to locate the test).
🪄 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: e4ec8ce4-bb14-44ce-a464-892fce7fc6da

📥 Commits

Reviewing files that changed from the base of the PR and between 0093278 and ceb349f.

📒 Files selected for processing (22)
  • dash-spv/src/sync/blocks/manager.rs
  • dash-spv/src/sync/filters/manager.rs
  • key-wallet-ffi/FFI_API.md
  • key-wallet-ffi/src/managed_wallet.rs
  • key-wallet-ffi/src/transaction.rs
  • key-wallet-ffi/src/utxo.rs
  • key-wallet-ffi/src/utxo_tests.rs
  • key-wallet-ffi/src/wallet_manager.rs
  • key-wallet-ffi/src/wallet_manager_tests.rs
  • key-wallet-manager/examples/wallet_creation.rs
  • key-wallet-manager/src/lib.rs
  • key-wallet-manager/src/process_block.rs
  • key-wallet-manager/src/test_utils/mock_wallet.rs
  • key-wallet-manager/src/wallet_interface.rs
  • key-wallet-manager/tests/integration_test.rs
  • key-wallet-manager/tests/spv_integration_tests.rs
  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/tests/balance_tests.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs
  • key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/metadata.rs

Comment thread key-wallet-manager/src/lib.rs
Comment thread key-wallet-manager/src/wallet_interface.rs
Comment thread key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
@xdustinface xdustinface merged commit fe7b744 into v0.42-dev Apr 24, 2026
50 of 51 checks passed
@xdustinface xdustinface deleted the refactor/rename-wallet-heights branch April 24, 2026 15:27
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