Skip to content

fix(wallet): improve account and wallet model handling#610

Open
romchornyi wants to merge 1 commit into
masterfrom
fix/locked-rewards-flow
Open

fix(wallet): improve account and wallet model handling#610
romchornyi wants to merge 1 commit into
masterfrom
fix/locked-rewards-flow

Conversation

@romchornyi

@romchornyi romchornyi commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
  • Enhance DSAccount with better transaction tracking
  • Improve DSWallet for multi-account support
  • Better balance calculation and cache management
  • Enhanced property accessors for improved performance

Issue being fixed or feature implemented

Enhances the core wallet infrastructure to support better transaction tracking, multi-account operations, and improve performance. These changes address performance bottlenecks in balance calculation and property access while laying the groundwork for multi-account wallet support.

What was done?

  • DSAccount: Improved transaction tracking with better filtering, caching, and optimized property accessors
  • DSWallet: Enhanced multi-account support with improved account management and state synchronization
  • Balance Calculation: Implemented smart caching with proper invalidation for faster balance queries
  • Performance: Reduced time complexity for property access and optimized memory usage for large transaction histories

How Has This Been Tested?

  • Verified transaction tracking accuracy across multiple accounts in test scenarios
  • Tested balance calculation with various transaction types (send, receive, coinbase)
  • Validated cache invalidation on transaction updates
  • Confirmed multi-account wallet operations work correctly
  • Tested property accessor performance improvements with large transaction histories
  • Built and ran with existing test suite to ensure no regressions

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added a new wallet/account balance view for funds that are still locked and not yet spendable.
    • Wallet totals now distinguish available balance from locked balance across all accounts.
  • Bug Fixes

    • Balance updates now refresh when locked funds change, helping totals stay accurate and notifications remain consistent.

- Enhance DSAccount with better transaction tracking
- Improve DSWallet for multi-account support
- Better balance calculation and cache management
- Enhanced property accessors for improved performance
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a lockedBalance property to DSAccount and DSWallet representing the sum of immature coinbase outputs (fewer than 100 confirmations). DSAccount computes and updates this value during updateBalance, and DSWallet aggregates it across all accounts.

Changes

Locked Balance Feature

Layer / File(s) Summary
DSAccount lockedBalance tracking
DashSync/shared/Models/Wallet/DSAccount.h, DashSync/shared/Models/Wallet/DSAccount.m
Adds a read-only lockedBalance property, initializes it to 0, accumulates amounts from locked coinbase outputs owned by account derivation paths, updates _lockedBalance, and triggers notifications/logging when balanceChanged or lockedChanged.
DSWallet lockedBalance aggregation
DashSync/shared/Models/Wallet/DSWallet.h, DashSync/shared/Models/Wallet/DSWallet.m
Adds a read-only lockedBalance property and a method that sums lockedBalance across all wallet accounts.

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

Sequence Diagram(s)

sequenceDiagram
  participant DSWallet
  participant DSAccount
  participant DerivationPath

  DSAccount->>DSAccount: updateBalance()
  DSAccount->>DerivationPath: check if output address is controlled
  DerivationPath-->>DSAccount: ownership result
  DSAccount->>DSAccount: accumulate lockedBalance
  DSAccount->>DSAccount: update _lockedBalance, evaluate balanceChanged/lockedChanged
  DSAccount->>DSAccount: post notification if changed
  DSWallet->>DSAccount: request lockedBalance per account
  DSAccount-->>DSWallet: return lockedBalance
  DSWallet->>DSWallet: sum lockedBalance across accounts
Loading

Suggested reviewers: Syn-McJ

🚥 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 is concise and clearly matches the wallet and account model changes in this PR.
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 fix/locked-rewards-flow

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.

@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.

🧹 Nitpick comments (1)
DashSync/shared/Models/Wallet/DSAccount.m (1)

745-753: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Nested output/derivation-path scan; consider reusing an existing ownership lookup.

For every immature transaction, this does an O(outputs × fundDerivationPaths) linear scan via containsAddress: per output. If the balance loop elsewhere already has a faster/cached way to check output ownership (e.g., a hash-set of owned addresses or an existing UTXO ownership check), reusing it here would avoid duplicating the ownership-check logic and keep the two computations consistent.

🤖 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 `@DashSync/shared/Models/Wallet/DSAccount.m` around lines 745 - 753, The
immature-transaction balance path in DSAccount.m is still doing a nested scan
over tx.outputs and self.fundDerivationPaths via containsAddress:, which
duplicates ownership logic and is unnecessarily slow. Update this loop to reuse
the same cached/faster ownership check used elsewhere in the balance calculation
(for example, an owned-address set or existing UTXO ownership helper) so output
ownership is determined once and consistently in the same way as the rest of the
balance code.
🤖 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.

Nitpick comments:
In `@DashSync/shared/Models/Wallet/DSAccount.m`:
- Around line 745-753: The immature-transaction balance path in DSAccount.m is
still doing a nested scan over tx.outputs and self.fundDerivationPaths via
containsAddress:, which duplicates ownership logic and is unnecessarily slow.
Update this loop to reuse the same cached/faster ownership check used elsewhere
in the balance calculation (for example, an owned-address set or existing UTXO
ownership helper) so output ownership is determined once and consistently in the
same way as the rest of the balance code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 436898f3-e60f-4d99-8af6-9cfd9ce83896

📥 Commits

Reviewing files that changed from the base of the PR and between aeff147 and ddb14e5.

📒 Files selected for processing (4)
  • DashSync/shared/Models/Wallet/DSAccount.h
  • DashSync/shared/Models/Wallet/DSAccount.m
  • DashSync/shared/Models/Wallet/DSWallet.h
  • DashSync/shared/Models/Wallet/DSWallet.m

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.

2 participants