Skip to content

fix(key-wallet): preserve UTXO flags across reprocessing - #837

Merged
xdustinface merged 2 commits into
dashpay:devfrom
xdustinface:fix/preserve-utxo-flags-on-reprocess
Jul 6, 2026
Merged

fix(key-wallet): preserve UTXO flags across reprocessing#837
xdustinface merged 2 commits into
dashpay:devfrom
xdustinface:fix/preserve-utxo-flags-on-reprocess

Conversation

@xdustinface

@xdustinface xdustinface commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

update_utxos rebuilds each of our outputs with a fresh Utxo::new on every reprocess of a transaction. On the mempool→block transition this silently reset flags that had already been set on an earlier pass, in particular is_instantlocked: a UTXO whose transaction received an InstantSend lock while in the mempool lost the lock flag the moment the transaction was confirmed in a block.

This carries forward the flags that must not regress when an entry for the outpoint already exists:

  • is_instantlocked and is_trusted latch monotonically. An InstantSend lock is permanent for a txid (DIP-0010) and trust only ever settles, so once either is true it stays true.
  • is_locked (the coin-reservation flag, toggled only via lock/unlock) is carried through unchanged rather than being reset.
  • is_confirmed is left freshly derived from the context so a reorg can still downgrade it.

It was latent so far because every current consumer ORs is_instantlocked with is_confirmed, and a confirmed reprocess sets is_confirmed true in the same pass. It is worth fixing on its own since is_instantlocked is now also an input to asset-lock funding selection, and a standalone consumer or a UI badge would surface the wipe.

Testing

test_full_confirmation_lifecycle now asserts the IS-lock flag survives the block-confirmation stage. The assertion fails without the fix and passes with it.

Found during CodeRabbit review of #836.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved wallet UTXO lock and trust state when transactions are reprocessed, so prior status is no longer lost during updates.
    • Continued to derive confirmation status from the latest chain context so reorg changes are reflected correctly.
  • Tests
    • Added an explicit check to ensure InstantSend lock status is retained when a transaction transitions from unconfirmed to confirmed during reprocessing.

`update_utxos` rebuilds each output with a fresh `Utxo::new` on every reprocess, so a mempool→block confirmation silently reset `is_instantlocked` (and `is_trusted` and any coin reservation) back to false. An InstantSend lock is permanent for a txid per DIP-0010 and trust only ever settles, so both now latch monotonically when an entry for the outpoint already exists, and the coin-reservation flag is carried through unchanged. `is_confirmed` stays freshly derived so a reorg can still downgrade it.

Addresses CodeRabbit review comment on PR dashpay#836
dashpay#836 (comment)
@coderabbitai

coderabbitai Bot commented Jul 2, 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: 204c2b42-cfd7-4678-97eb-7f7637c5ef04

📥 Commits

Reviewing files that changed from the base of the PR and between 55d241b and a74ba77.

📒 Files selected for processing (2)
  • key-wallet/src/managed_account/managed_core_funds_account.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs
✅ Files skipped from review due to trivial changes (1)
  • key-wallet/src/transaction_checking/wallet_checker.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • key-wallet/src/managed_account/managed_core_funds_account.rs

📝 Walkthrough

Walkthrough

ManagedCoreFundsAccount::update_utxos now preserves selected UTXO flags from any prior entry with the same outpoint while still recomputing is_confirmed. A test adds coverage for the InstantSend lock flag across mempool-to-block reprocessing.

Changes

UTXO Flag Preservation

Layer / File(s) Summary
Preserve state flags across reprocessing
key-wallet/src/managed_account/managed_core_funds_account.rs, key-wallet/src/transaction_checking/wallet_checker.rs
update_utxos carries forward is_instantlocked, is_trusted, and is_locked from prior UTXO entries with matching outpoints, while is_confirmed is still recomputed; a test asserts is_instantlocked persists after confirmation reprocessing.

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

Possibly related issues

Suggested reviewers: llbartekll, 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: preserving UTXO flags during reprocessing in key-wallet.
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 unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.36%. Comparing base (417d61d) to head (a74ba77).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #837      +/-   ##
==========================================
+ Coverage   73.33%   73.36%   +0.03%     
==========================================
  Files         324      324              
  Lines       72923    72929       +6     
==========================================
+ Hits        53478    53506      +28     
+ Misses      19445    19423      -22     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 45.48% <ø> (-0.02%) ⬇️
rpc 20.00% <ø> (ø)
spv 90.67% <ø> (+0.13%) ⬆️
wallet 72.97% <100.00%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
.../src/managed_account/managed_core_funds_account.rs 77.85% <100.00%> (+0.27%) ⬆️
...-wallet/src/transaction_checking/wallet_checker.rs 99.25% <100.00%> (+<0.01%) ⬆️

... and 8 files with indirect coverage changes

@xdustinface

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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)
key-wallet/src/managed_account/managed_core_funds_account.rs (1)

205-216: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extending test coverage to is_trusted/is_locked preservation.

The companion test in wallet_checker.rs only asserts is_instantlocked survives reprocessing. Since this same merge block also latches is_trusted and carries through is_locked, an assertion covering those paths would guard against future regressions in the same spot that caused this bug.

🤖 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 `@key-wallet/src/managed_account/managed_core_funds_account.rs` around lines
205 - 216, The reprocessing merge logic in managed_core_funds_account should be
covered by tests for the additional latched fields. Extend the existing
companion test in wallet_checker.rs (the one that already checks UTXO
reprocessing) to also assert that ManagedCoreFundsAccount’s preservation path
keeps is_trusted latched and carries is_locked through from the prior UTXO,
alongside the existing is_instantlocked check.
🤖 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 `@key-wallet/src/managed_account/managed_core_funds_account.rs`:
- Around line 205-216: The reprocessing merge logic in
managed_core_funds_account should be covered by tests for the additional latched
fields. Extend the existing companion test in wallet_checker.rs (the one that
already checks UTXO reprocessing) to also assert that ManagedCoreFundsAccount’s
preservation path keeps is_trusted latched and carries is_locked through from
the prior UTXO, alongside the existing is_instantlocked check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff3f3495-2f29-45e0-a1f5-2fc99fa50a91

📥 Commits

Reviewing files that changed from the base of the PR and between a8a0968 and 55d241b.

📒 Files selected for processing (2)
  • key-wallet/src/managed_account/managed_core_funds_account.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs

@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label Jul 6, 2026
@xdustinface
xdustinface requested a review from ZocoLini July 6, 2026 11:48

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

I guess there must be a reason, but why are we creating a new structure instead of using the same one

@xdustinface

xdustinface commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

I guess there must be a reason, but why are we creating a new structure instead of using the same one

Im not sure, probably no reason.

@xdustinface
xdustinface merged commit 3170ad3 into dashpay:dev Jul 6, 2026
37 checks passed
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