Skip to content

feat(wallet): list the asset locks that fund Platform from the wallet's own transactions - #8137

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:feat/wallet-asset-lock-fundings
Nov 16, 2026
Merged

PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:feat/wallet-asset-lock-fundings

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

An identity registration or top-up locks coins into a credit output that pays a funding key derived from the wallet's seed. Nothing in the wallet points back at that lock. If Platform has not consumed it when a DashPay client loses its own records, as after a seed restore, the client cannot find it: it would fund a second lock with the same registration key, and top-up credits would stay stranded.

What was done?

interfaces::Wallet::listAssetLockFundings(keys) lists every credit output of a wallet asset lock that pays one of the given funding keys: txid, credit index, key, amount and status. It is derived only from the transactions the wallet holds, which a restore recovers by rescanning, so nothing new is persisted.

  • ACTIVE: not abandoned, and no conflict is mined.
  • INACTIVE: abandoned and unmined. It is still listed because it can still be mined.
  • CONFLICTED: a conflict is mined.

The status comes from the state the wallet records for the transaction, not from its depth. A rescan installs mined transactions above the last block the wallet has processed, where the depth would be negative, so a lock found there would otherwise read as conflicted.

Deriving the keys needs an unlocked wallet. There is no in-tree caller yet; the DashPay GUI that uses it comes in a later PR. This was the last commit of #8068 and is split out because it shares no code or state with the rescan work there. The two PRs touch adjacent lines, so whichever merges second needs a trivial rebase.

How Has This Been Tested?

wallet_tests/create_asset_lock_transaction is extended rather than adding a scenario:

  • the committed lock is listed ACTIVE and the abandoned conflict INACTIVE; a key that funds nothing lists nothing;
  • after the lock is mined, the conflict becomes CONFLICTED;
  • a wallet restored from the seed finds the mined lock after a rescan, and lists it ACTIVE while its processed height is still two blocks below the lock;
  • a locked wallet reports WALLET_LOCKED.

test_dash --run_test=wallet_tests,platformkeys_tests passes at this head (macOS arm64, depends build, --enable-debug --enable-werror, no GUI). When the commit was written, deriving the status from depth made the restored-wallet check fail with CONFLICTED; that reversion was not re-run for this split.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (if you have permission to set one)

🤖 Generated with Claude Code

…'s own transactions

An identity registration or top-up locks coins into a credit output that
pays a key derived from the wallet's seed. If Platform has not consumed
that lock when the GUI's own records are lost, as after a seed restore,
nothing pointed back at it: the GUI would fund a second lock with the
same registration key, and top-up credits stayed stranded.

listAssetLockFundings(keys) reads that inventory from the transactions
the wallet holds, which a restore recovers by rescanning: every credit
output of a wallet asset lock that pays one of the given funding keys,
with its txid, credit index, key, amount and status. ACTIVE is not
abandoned and has no mined conflict; INACTIVE is abandoned and unmined,
which can still be mined, so it stays listed; CONFLICTED has a mined
conflict. Nothing else is persisted. Deriving the keys needs an unlocked
wallet.

The status comes from the state the wallet records for the transaction,
not from its depth. Depth counts from the last block notification the
wallet processed, and a rescan installs mined transactions above it, so
a lock it finds two or more blocks higher would have a negative depth
and read as conflicted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cab00716-ec12-4809-bb3c-b1055d467d0c
Commits

Reviewing files that changed from the base of the PR and between 5c34dcf and c47973f.

Files selected for processing: 6

  • src/interfaces/wallet.h
  • src/wallet/interfaces.cpp
  • src/wallet/platformtypes.h
  • src/wallet/test/wallet_tests.cpp
  • src/wallet/wallet.cpp
  • src/wallet/wallet.h
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@thepastaclaw

thepastaclaw commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit c47973f) · triage: normal

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

Final validation — Phase 1 + Phase 2

The PR cleanly adds wallet and interface support for locating asset-lock credit outputs by derived Platform funding keys. The implementation derives keys under the wallet lock, scans wallet-owned asset-lock transactions, preserves the requested status semantics, and includes coverage for conflicts, rescans, and locked wallets. Cppcheck and ClangFormat pass; the queued lint and failed milestone policy check do not indicate code defects.

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a contained wallet/API behavior change involving asset-lock discovery, key derivation, transaction status classification, and rescan-related state handling, but it does not directly change funds movement, consensus, cryptographic primitives, or persistence formats.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort high); agent phase2-reviewer

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 13, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Approved

PastaPastaPasta

This comment was marked as duplicate.

@PastaPastaPasta
PastaPastaPasta merged commit 45732d5 into dashpay:develop Nov 16, 2026
51 of 53 checks passed
@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 16, 2026
knst added a commit that referenced this pull request Nov 21, 2026
…n needs

b80cf61 fix(wallet): clamp the rescan time before subtracting the timestamp window (pasta)
e2914de fix(wallet): take the rescan status from the scan, and complete a held chain's prefix (pasta)
429a43e fix(wallet): do not report an incomplete friendship chain rescan as done (pasta)
f55fe73 refactor(wallet): report the friendship chain rescan to the caller instead of recording it (Konstantin Akimov)
531b552 feat(wallet): owe a rescan for each DIP-15 receiving chain the wallet gains (pasta)

Pull request description:

  ## Issue being fixed or feature implemented

  A contact pays our DIP-15 receiving chain for that friendship. A wallet restored from its seed, or one whose contact was made on another device, does not hold that chain, and has already scanned the blocks those payments are in. Importing the chain, or moving its birth back to an earlier contact request, therefore needs a rescan from that birth.

  On develop the caller cannot tell when that is the case: `ensureFriendshipReceivingKeychain()` returns the same result whether the chain was imported, made older, or already held, and there is no way to rescan from a birth time through the wallet interface.

  This PR is wallet-only, with no Rust or Platform dependency.

  **The new interface surface has no in-tree caller yet.** `rescan_from` and `rescanFromTime()` are for the DashPay GUI train (contacts #7766, payments #7767, seed recovery #7910, all drafts), which will be restacked onto this.

  ## What was done?

  - `ensureFriendshipReceivingKeychain()` returns a `FriendshipKeychain`: the public chain plus `rescan_from`. It is set to the chain's birth when the chain was imported, when a held chain's birth moved earlier, or when a held chain was given its key. The caller then owes one `rescanFromTime()` from it, the contract `importdescriptors` has; one rescan from the lowest value serves many chains.
  - A chain held with its key and born no later is left untouched, without a wallet database write, and reports no rescan. Its range is not looked at. The wallet's own import gives a chain the default range from index 0 and each payment tops it up, so a shorter range, or one that starts past index 0, only comes from importing the private descriptor by hand, where the range and the rescan are the user's. Reopening the wallet with a larger `-keypool` reports no rescan either.
  - Lowering a held chain's birth also lowers the wallet's birth time, as a reload would.
  - `rescanFromTime(T)` scans, on the caller's thread, from the first block a key born at `T` may be paid in, and maps the scan's status as `startRescan()` does: `BUSY` when another rescan holds the wallet, `USER_ABORT` when it was aborted or cut short by a shutdown request, `FAILURE` when a block it needed could not be read. It calls `ScanForWalletTransactions()` rather than `CWallet::RescanFromTime()`, which does not report an abort or a shutdown.
  - `SUCCESS` means the mempool was read too, once. The scan reads it after the blocks; when no block is recent enough for `T`, `rescanFromTime()` reads it directly and returns `SUCCESS`: that read cannot be interrupted, so nothing is left unread. Otherwise a payment already in the mempool when the chain was imported would stay unknown until it is mined.

  Limits:

  - The wallet does not record that a rescan is needed. A caller that stops between the import and the rescan has to remember it itself: a retried `ensureFriendshipReceivingKeychain()` finds the chain held and reports no rescan. This is the same as `importdescriptors` with `rescan` interrupted.
  - On a node that has pruned the blocks the rescan needs, `rescanFromTime()` returns `FAILURE`. What to tell the user is the caller's policy.
  - A failed wallet database write during the import or the rescan throws, as it does on develop and for `importdescriptors`; the wallet must be reloaded before a retry. `AddWalletDescriptor()` is not atomic either. Both are inherited from Bitcoin Core and are tracked in #8147.

  Compared with earlier revisions of this PR:

  - The persisted `owed_rescan` wallet record, its sequence numbers and settle rules, and `owedRescanFrom()` are dropped in favour of returning `rescan_from`.
  - The block-filter rescan locking fix is #8139, and the asset-lock funding inventory is #8137.
  - The partial bitcoin#35752 backport, the handling of failed imports and failed writes, `rescanUnavailableFrom()` and `getFriendshipReceivingXpub()` are dropped. `rescanPrunedFrom()` and `startRescan()` are as on develop.

  ## How Has This Been Tested?

  Unit tests, observing coins and the returned `rescan_from` through the wallet interface:

  - `platformkeys_tests/recovery_import_after_restore_is_spendable` (rewritten): a restored wallet that has scanned the payment's block imports the chain from a later request and its rescan finds nothing; an earlier request moves the birth back and reports the earlier rescan; a rescan from genesis aborted before its first block returns `USER_ABORT`; the reported rescan makes the payment spendable.
  - `platformkeys_tests/friendship_import_reports_rescan` (new):
    - a new chain reports a rescan from its birth; the same or a later birth reports none and writes nothing; an earlier birth reports a rescan and lowers the chain's and the wallet's birth;
    - a chain held without its key is given the key and reports a rescan;
    - a payment that is in the mempool when the chain arrives is found by the rescan and announced exactly once, both when the rescan has blocks to read and when the chain was born after every block.

    With the mempool read a second time after a scan, the announced-once check fails.
  - `wallet_tests/scan_for_wallet_transactions` (one added block): a rescan over pruned blocks returns `FAILURE`, also from the lowest possible time, which is clamped rather than overflowing into a time after every block. Without the clamp the debug build traps on the overflow.

  Run on macOS arm64 on this branch merged with `develop` at 37f944b (CMake, `-DWERROR=ON`, no GUI): `test_dash --run_test=platformkeys_tests,wallet_tests,walletdb_tests,walletload_tests` passes.

  A shutdown request during the scan has no test of its own: the unit test setup cannot request one. The scan reports it with the same status as the abort that `recovery_import_after_restore_is_spendable` covers.

  No functional test was added: the change adds no RPC.

  ## Breaking Changes

  None. No new wallet record types.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(if you have permission to set one)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: 7c2ba8e9dc3e5655fdcbeb05adeba031f548ca86b4d280d32984632c4c43b22e6630a547f1a514b65a247cd76e0a8dfb3144f47662f9e459822904e352f133ad
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