Repository navigation
Description
TL;DR: Saving the nickname or note of two contacts at almost the same time can make both saves pick the same slot on Platform. The second save is then refused, its change stays on this device only, and the next sync undoes it.
User story
As a DashPay user, I want every contact nickname, note or hide/unhide I save to reach my other devices, even when I edit several contacts quickly.
As a wallet app developer, I want the wallet to order contact-details saves for an identity, so I don't need my own lock around its call.
Scenario
Base flow
- The identity has at least two established contacts, so contact details are published.
- The user saves a note for contact A and, before that save finishes, a note for contact B. Neither contact has published details yet.
Actual behavior
Both saves read the identity's published contact-details documents at the same time, see the same highest slot number, and choose the same next slot. Platform enforces one document per (owner, key, slot), so the second create is refused.
That save had already written its change locally. The local note now differs from Platform. The next background sync applies Platform's state ("remote wins") and removes the note the user saved.
A similar overlap between a save and a running sync pass can also re-apply the older published value for the contact being edited, in the window between the local write and the publish.
Expected behavior
Saves for one identity run one after another, from reading the published documents to the broadcast result. A sync pass does not apply published details over a save that is still in flight for that identity. Each save then gets its own slot, and nothing the user saved is undone.
Detailed discussion
On v5.1-dev @ 575d961fe0, set_contact_info_with_external_signer (network/contact_info.rs#L504):
- Writes the metadata locally under a short
wallet_manager.write()guard that is dropped before any network call (~#L544-L580). - Fetches the owner's contactInfo documents and computes
high_waterper root key (#L626-L628). - For a contact with no document yet, allocates
next_index = high_water[root] + 1(~#L678-L690), then seals and broadcasts.
No lock spans steps 2–3 for an owner. The contract's unique index is (ownerId, rootEncryptionKeyIndex, derivationEncryptionKeyIndex) (comment at ~#L665-L672). Two concurrent creates therefore collide, and Platform refuses the second.
sync_contact_infos documents "Remote state wins … convergence is last-writer through Platform" (#L284-L290). For the refused save, that means its local change is reverted on the next pass.
Platform backstops the corruption (the unique index), so no document is lost. But the user's edit is, and the refused transition may still be charged.
Downstream: Dash Evo Tool holds its own per-owner async mutex around the call (src/context/contact_info_writes.rs, ContactInfoWrites::acquire). That lock only covers the app's own calls, not the wallet's background sync, which is why the fix belongs in the wallet.
Proposed change
- A per-owner async lock inside
IdentityWallet/DashPayView(a map ofWeak<tokio::sync::Mutex<()>>keyed by owner id), held from the document fetch to the broadcast result inset_contact_info_with_external_signer. sync_contact_infos/drain_contact_info_decrypttake the same lock per owner while applying, so a pass cannot apply over an in-flight save.- Worth the same look: whether
sync_profilescan overwrite a just-confirmedupdate_profile_with_external_signerresult with a pre-write fetch, when the pass's fetch started before the write and is applied after it. Not verified. A shared per-owner lock would close that too.
Prior work
- fix(platform-wallet): DashPay payment reconcile still stores under the wallet-manager write guard (stage/unstage split) #4609: DashPay reconcile still persists under the wallet-manager write guard. It is about lock scope during persistence, not ordering of saves.
- fix(platform-wallet): support HASH160 DashPay contact signing keys #5546: the contactInfo signing-key types. It touches the same function and should be rebased together.
Attribution
🤖 Co-authored by Claudius the Magnificent AI Agent
Activity