Skip to content

refactor(dashpay)!: sync DashPay through platform-wallet and show it from shared snapshots - #1134

Draft
Claudius-Maginificent wants to merge 14 commits into
fix/dashpay-contact-info-keysfrom
refactor/dashpay-sync-manager
Draft

Claudius-Maginificent wants to merge 14 commits into
fix/dashpay-contact-info-keysfrom
refactor/dashpay-sync-manager

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: DashPay contacts, contact requests, profiles and payments now stay up to date on their own in the background, and every screen shows the same, current view of them instead of loading its own copy.

User story

As an everyday DashPay user, I want my contacts, requests, profile and payment history to stay current without pressing Refresh on every screen, to achieve a contact list I can trust, including changes I made on another device.

Scenario

Base flow

I open the Identities hub, look at Home and Contacts, then open the older DashPay screens (contacts, requests, profile, payment history, contact details). Meanwhile I accept a request or rename my profile on another device, and a contact pays me.

Actual behavior

Each screen loads its own copy of the DashPay data when it opens or when I press Refresh. The screens can disagree with each other, show a spinner on every visit, and a change made elsewhere shows up only after I refresh the right screen. A profile name saved earlier on this device keeps winning over a newer name from the network.

Expected behavior

DashPay data syncs in the background every 15 seconds once the network is ready. Every screen shows the same current data straight away, a change made on another device appears by itself, and Refresh asks for an immediate sync. My own actions (sending, accepting, declining or withdrawing a request, saving a profile or contact details, paying) appear as soon as they finish. Contact details also list the payments exchanged with that contact.

Detailed discussion

Stacked atop #1102 (fix/dashpay-contact-info-keys); merge that first.

What was done

DET moves onto platform-wallet's DashPaySyncManager and its ManagedIdentity DashPay state, and deletes the DET-side machinery that duplicated it.

  • Sync lifecycle. dashpay_sync starts and stops alongside the platform-address, identity and shielded coordinators: started by the masternode-ready CoordinatorGate, quiesced on disconnect, restarted in place.
  • Snapshots (wallet_backend/dashpay_snapshot.rs). One frame-safe Arc<DashPaySnapshot> per owner identity, published through an ArcSwap. Each snapshot combines upstream state with the DET-local overlays: withdrawn and declined requests, private memos, details-synced markers, contact DPNS usernames, and payment/profile first-seen times.
    • Rebuilds are serialized by a mutex and are published only when something changed.
    • The UI applies a snapshot only when its Arc changed.
    • The frame loop asks for DashPayTask::RefreshSnapshots after each completed sync pass (at most once per second, at least every 15 s).
    • Every DashPay write rebuilds the snapshots before its result lands.
  • Refresh. Refresh buttons, arriving at the hub and switching identity dispatch DashPayTask::SyncNow { identity }. With an identity, it also reads the owner's contactInfo documents with the wallet seed through wallet_backend/secret_seam.rs. The same read runs once on wallet unlock.
  • Request actions are keyed by ContactRequestKey { owner, counterparty } instead of a document id. Each action re-fetches the document before acting. The paid-action double-click guards and the per-owner write locks (ContactInfoWrites, lock_identity_profile) are kept.
  • Contact Details reopens its editor only when its own SyncNow ends (new BackendTaskContext::DashPaySync), not on a snapshot refresh or a profile read.
  • Display names: a profile name synced from the network wins over a name saved earlier on this device.
  • Removed:
    • ProfileCache, ContactsState load/retry/dispatch-id tracking, ConfirmedNote, and the legacy screens' loading flags
    • DashPayTask::{LoadProfile, LoadContacts, LoadContactsOffline, LoadContactRequests, LoadContactDetails, LoadPaymentHistory}, together with their result variants and raw-SDK loaders
    • the profile load revisions (save revisions stay), BackendTaskContext::DashPayContactsLoad, and AppAction::BackendTasksWithContexts
    • the det:contact_profile cache and TaskError::ContactProfileCacheStorage
    • DET incoming-payment detection (DetectIncomingContactPayments and the EventBridge candidates). Upstream reconcile_incoming_payments is the single writer.
    • WalletBackend::dashpay_sync(owner)
  • Receive cursor. ContactAddressIndex::highest_receive_index is no longer read. Upstream's DashpayReceivingFunds account marks receiving addresses used and extends its pool from the account xpub. The field stays because the stored bincode layout is positional.
  • Backend E2E TC-043: the test (and step 2 of the contact lifecycle) compared a contact-request document id with an identity id, so it could never find the request. It now selects the request by its sender.

Upstream gaps (each marked // TODO(upstream): ...)

  1. No sync-completed event (platform-wallet: report each finished DashPay sync pass through PlatformEventHandler platform#5596): the frame loop polls the last pass time.
  2. ContactRequest carries no document id (platform-wallet: keep the document id on a synced ContactRequest platform#5597): actions are keyed by owner and counterparty and re-fetch the document.
  3. No seedless reader for contactInfo only (platform-wallet: let a seedless wallet read its contact details without draining the whole contact-crypto queue platform#5595): reading stored contact details needs the wallet seed.
  4. ContactProfileEntry has no DPNS username (platform-wallet: keep a contact's DPNS username next to their cached DashPay profile platform#5598). Stopgap: a small DET k/v store (contact_usernames) holds the usernames looked up once per session. It reuses the old det:contact_profile: keys, so stored usernames survive. Remove it once platform-wallet carries the username.
  5. No per-owner contactInfo write serialization upstream (platform-wallet: serialize contact-details saves per identity so two saves cannot pick the same document slot platform#5599): DET keeps ContactInfoWrites and lock_identity_profile.
  6. Identities without a loaded wallet (wallet-less or locked) are not synced (platform-wallet: sync DashPay profiles for identities no loaded wallet manages platform#5600): DET reads their profiles once per session with the SDK's batched Sdk::get_profiles.
  7. No per-output payment keys (platform-wallet: record DashPay payments per output, not per transaction platform#5601): entries older versions recorded under txid:vout shadow upstream's bare-txid twin at read time (unit-tested).

Known limitations

  • Two concurrent contactInfo writes for the same identity would lose an edit in platform-wallet (platform-wallet: serialize contact-details saves per identity so two saves cannot pick the same document slot platform#5599). DET's per-owner lock (ContactInfoWrites) is what prevents this today, so every DET contactInfo write must go through it.
  • Profiles of identities without a loaded wallet are read once per session.
  • The legacy DashPay screens show a spinner only until the first snapshot arrives.
  • After one wallet is removed, its identities' snapshots stay until the next refresh (at most 15 s); its identities are no longer listed by then.
  • A sync for an identity whose wallet is locked skips the contactInfo read (logged at debug). Arriving at the hub may ask for the wallet password, as the previous contact load did.
  • The DET-local blocked marker has no production writer (no UI sets it), so the snapshots do not read it. Nothing user-visible changes.
  • tests/backend-e2e/dashpay_tasks.rs is rewritten onto SyncNow and snapshots, but the module is still disabled in tests/backend-e2e/main.rs.

Testing

  • New tests:
    • unit tests for the snapshot builder: contacts, pending requests both ways, withdrawn and declined requests, memo vs held-details precedence, unknown vs absent profile, legacy payment-key shadowing
    • an end-to-end snapshot test through WalletBackend (held details win over this device's copy)
    • refresh throttling and payment-record mapping
    • synced display name over a saved one
    • profiles read for identities without a loaded wallet (an owner with no profile is recorded as having none)
    • the coordinator lifecycle
    • Contact Details editor gating, including frame-loop refreshes
    • hub kittests rewritten around SyncNow
  • cargo test --all-features --lib --test kittest: 3810/3810 lib tests and 508/509 kittests passed in the full run. The remaining kittest (identity_selector) was fixed and passes in a targeted re-run (2/2), the Contact Details tests (5/5) were re-run after the last behaviour change, and all DashPay lib tests (240/240) pass on the head commit.
  • cargo clippy --all-features --all-targets -- -D warnings and cargo fmt --all -- --check are clean on the head commit.
  • Not run: backend E2E (needs testnet funds); dashpay_tasks is disabled in that suite.

Breaking changes

Internal API only. The DashPayTask load variants, their BackendTaskSuccessResult variants, AppAction::BackendTasksWithContexts, ContactProfileCacheView, TaskError::ContactProfileCacheStorage and WalletBackend::dashpay_sync are removed. Request actions take counterparty_id instead of request_id. No stored data format changes, and no user action is needed.

Checklist

  • Conventional commits
  • cargo fmt, cargo clippy -D warnings
  • Targeted tests and kittests
  • Backend E2E on testnet

Attribution

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q

lklimek and others added 13 commits October 26, 2026 17:11
…let state

Add `WalletBackend::dashpay_snapshot(owner)`: one lock-free read per
identity combining platform-wallet's DashPay state (profile, established
contacts, pending requests, contact profiles, payments) with this
device's overlays (withdrawn/declined requests, private memos, payment
times). Snapshots are rebuilt after every DashPay write task and by a new
`DashPayTask::RefreshSnapshots` the frame loop dispatches after each
completed sync pass (polled; TODO(upstream) on_dashpay_sync_completed)
and every 15 s. `DashPayTask::SyncNow` runs a pass on demand once the
masternode list is ready.

What platform-wallet does not hold is looked up after a pass: contacts'
DPNS usernames (kept in a slimmed per-contact username store that reads
the old contact-profile blobs) and the profiles of wallet-less identities.

Drop DET's own incoming-payment detector: platform-wallet records
incoming DashPay payments itself (live and by reconcile), so DET's
`txid:vout` copies duplicated them. Older composite entries still shadow
their bare-txid twin at read time (TODO(upstream) per-output keys).

Build pending: host disk full, no build slot yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…inators

Start `DashPaySyncManager` in the quorum-readiness gate next to the
platform-address, identity and shielded coordinators, and quiesce it on
a same-network disconnect; manager shutdown already drains it. Contact
requests, profiles, contact profiles, contactInfo and payments now
refresh every 15 s without a screen asking.

Build pending: host disk full, no build slot yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
platform-wallet does not read `contactInfo` back for a wallet loaded
without its seed, which is how wallets load after a restart. DET now
reads them with the seed (DIP-0015 and legacy-key documents, same
precedence as before) and stores the result through platform-wallet's
`set_contact_metadata`, so the contact snapshot shows them from
platform-wallet's state instead of a DET-side merge. A legacy document
is taken over once.

The read runs on wallet unlock, on `DashPayTask::SyncNow { identity }`
and before every contact details save, under the owner's contactInfo
write lock. TODO(upstream): dip15-contactinfo-reader.

Build pending: host disk full, no build slot yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Accept, Decline and Cancel now name the other identity instead of a
request document id: platform-wallet's request state has no document
id, and DashPay holds at most one request each way per pair. Each
action re-fetches the request by ($ownerId, toUserId) before acting and
still verifies its direction. In-flight claims, per-owner action locks,
results and `DashPayContactRequestActionFailed` carry a
`ContactRequestKey { owner, counterparty }`, so two identities acting
on the same person never block each other. Progress records older
versions kept per document are still cleared by the fetched document id.

The backend E2E steps now pick A's request by its sender, the identity
id they were already comparing against.

Build pending: host disk full, no build slot yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The Identities hub reads profiles, contacts, requests and recent payments
from the snapshots platform-wallet's DashPay sync publishes, and asks for a
sync (SyncNow) on arrival, refresh, identity switch and Contacts entry once
the masternode list is ready.

Removes ProfileCache, the per-tab load/retry/dispatch-id machinery, the
confirmed-note bookkeeping and Home's payment-history loads. Profiles of
identities platform-wallet does not sync (no wallet, or a wallet not
loaded) are read once per session after a sync pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The Contacts, Requests, Profile, Payments and Contact Details screens read
the selected identity's DashPay snapshot every frame and rebuild only when
it changes. Their Refresh buttons ask for a sync (SyncNow); the per-screen
load flags, dispatch guards and offline/network load tasks are gone.

Contact Details still reads the public profile of someone the snapshot
does not hold as a contact, and now lists the payments exchanged with the
contact. Payments carry the time this device first saw them.

Adds a test seam publishing a profile into the snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The hub asks for a sync instead of per-tab loads, so its kittests check
when SyncNow goes out and seed profiles and contacts as a sync would.
Tests of the removed load, retry and late-answer routing are dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Screens read DashPay state from the snapshots platform-wallet's sync keeps
current, so the raw-SDK load tasks and what served them go:

- DashPayTask::LoadProfile, LoadContacts, LoadContactsOffline,
  LoadContactRequests, LoadContactDetails and LoadPaymentHistory, with
  their result variants and loaders
- the profile load revisions (saves keep theirs, so a stale save result
  is still recognised); a synced profile name now wins over one saved on
  this device earlier, so a change made elsewhere shows
- the contact-list load context, its batch dispatch routing and
  AppAction::BackendTasksWithContexts, which only the loads produced
- WalletBackend::dashpay_sync(owner), superseded by the sync manager

Synced own profiles get the time this device first saw them after each
pass, as fetched ones did. The contact details precedence tests move to
the model, next to shown_contact_details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Brings in the Platform v5.1-dev bump, v1.0-dev, and the contact details
fixes. The load tasks those fixes touched are gone here:

- Contact Details waits for its own SyncNow (new DashPaySync context)
  instead of the removed LoadContactDetails read before it reopens the
  editor after a failure.
- The deleted contact profile cache and load paths stay deleted; their
  accessor and base58 updates are applied to what replaced them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
First compile of the DashPay snapshot steps:

- box the profile in ProfileState::Present (large_enum_variant)
- restore the re-engage test double lost with the load tests
- fix imports, a stale argument and kittest payment previews
- move the offline contact-details test onto the snapshot, keeping
  end-to-end coverage that held details win over this device's copy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n sync

Any DashPaySynced result reopened the editor, including the frame loop's
snapshot refreshes, which can land while the sync reading the published
details is still running. Only the SyncNow for this identity does now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…placed

platform-wallet's DashpayReceivingFunds account marks receiving addresses
used and extends its pool (gap limit 10) from the account xpub, so the
receive cursor DET's removed payment detector advanced has no writer. The
address registration no longer reads it; the field stays in
ContactAddressIndex because the stored bincode layout is positional.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 6a76f90. Normal review starts when eligible; priority review starts as soon as a slot is available.

The profiles of identities platform-wallet does not sync are read with
the SDK's batched get_profiles instead of a hand-written query per
identity; an owner it returns nothing for is recorded as having none.

Each upstream gap's TODO now names its dashpay/platform issue
(#5595-#5601).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Claudius-Maginificent Claudius-Maginificent added the blocked Blocked by something external to this issue label Oct 27, 2026
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Blocked by the stack: this PR is based on #1102, which waits on dashpay/platform#5546 (DashPay contact details signed with HASH160 keys, DET's default identity key type). It can land only after that upstream PR merges, DET bumps its Platform pin past it, and #1102 merges; then retarget this branch to v1.0-dev.

🤖 Co-authored by Claudius the Magnificent AI Agent

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

To do here, handed over from #1117 by the maintainer: keep src/model/dashpay.rs free of backend types.

The ContactQr parser and signer added by #1117 import crate::backend_task::error::TaskError and return its variants, which reverses the model-layer dependency. Define a model-owned ContactQrError with typed upstream sources and map it to TaskError at the backend or UI boundary. The file reaches this branch once #1117 is in its base.

🤖 Co-authored by Claudius the Magnificent AI Agent

@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Scope addition (maintainer decision, carried over from #1117 — thepastaclaw finding PRRT_kwDOM8GK3c6zmKjS):

Make the DashPay profile writer use the same key-availability policy as the profile screen. WalletBackend::dashpay_write_profile (src/wallet_backend/dashpay.rs) passes the plain QualifiedIdentity to platform-wallet's create/update_profile_with_external_signer. Upstream's profile_signing_key selects through Signer::can_sign_with, which in QualifiedIdentity (src/model/qualified_identity/mod.rs) accepts any filed private-key placement — including legacy-encrypted keys or keys held by a wallet that is not loaded. The profile screen meanwhile picks via dashpay_signing_key / holds_obtainable_key. With a profile-capable key this device cannot sign with at a lower id than a usable one, saving the profile fails before broadcast (no fee).

Suggested fix (~20–25 lines): wrap the identity in a profile-only signer whose can_sign_with also requires holds_obtainable_key, pass it to both profile writers, and add a test with a lower-id unavailable HIGH ECDSA key plus a later usable one. Not changing the global can_sign_with, which every SDK signing path uses.

🤖 Co-authored by Claudius the Magnificent AI Agent

@Claudius-Maginificent Claudius-Maginificent added priority: low Low priority — nice to have priority: medium Medium priority and removed priority: low Low priority — nice to have priority: medium Medium priority labels Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Blocked by something external to this issue priority: low Low priority — nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants