Repository navigation
fix: keep usdt requests protected during proof delivery - #1567
Conversation
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryKeeps requests out of the payable list while saved USDT payments are pending or their proofs await submission.
No actionable issues were found. Tests were reviewed but not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[USDT payment state changes] --> B[Request-state version increases]
B --> C[Wait until payment submission ends]
C --> D[Refresh stored requests]
D --> E[Load protected USDT attempts]
E --> F[Hide matching payable requests]
D --> G[Check proof and USDT versions]
G --> H[Publish only if versions still match]
Reviews (1) · Last reviewed commit: "fix: keep usdt requests protected during..." · Reviewed by Greptile |
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
talosmachina
left a comment
There was a problem hiding this comment.
Reviewed at d23d25a from the code and CI. The branch was not built or run as part of this review.
No blocking findings.
What I checked:
paymentProofVersion()now pairs the proof store version withpaymentRequestStateVersion. Every place that readbackupStateVersionalone was switched (refreshcheckpoint,synchronizeLocked, the post-apply recheck inapplyRequestSnapshotLocked), so a USDTsave()during a snapshot fetch now forces the STORED resync instead of applying a stale snapshot.- Lock order:
protectedPaymentAttemptstakes the USDT repomutexwhileoperationMutexis held, the same nestingverifiedReceiptsalready uses.reconcile()never takesoperationMutex, so I found no new inversion. reconcile()bumps the version infinallywhen the protection triple changes, or wheneverresumableRequestswas non-empty before. The early clear of_resumableRequestsis covered too: the new test holdsidentityStatusand checks that the attempt stays protected mid-reconcile.- In
protectedPaymentAttempts,proofQueuedattempts drop out, so after the hand-off protection moves to the proof store'scompletedRequestProofKindsAwaitingSubmission. Attempts the current reconcile marked resumable are excluded, so a definitely failed payment can be paid again. AppViewModel.observePaymentProofChangesmergespaymentRequestStateVersion.drop(1), so the initial value does not trigger an extra refresh, and the existingisPaymentSubmissionActivegate still defers it during a send.
CI: unit tests, detekt and lint pass. e2e-tests-local - lightning_security failed in the Run regtest setup step before any app test ran, so it looks like infrastructure, not this change. Four e2e jobs were still pending when I read the checks.
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: Reviewed the full PR diff against its merge base, at d23d25a. No earlier assessment baseline was available, so this pass covers the whole change.
No new actionable code findings.
Saved USDT attempts stay out of the payable list while payment has started or a local proof exists and has not been queued, including when that state changes during a request refresh. Reconciliation returns a definite failure to the payable list, and a later subscription period remains payable. Those rules match bitkit-ios#1005 at d959be05.
Validation: the CI build for this revision passed, including testDevDebugUnitTest. Detekt and lint also passed on this head. The new unit tests were inspected and not re-run locally.
Device testing: not performed in this review.
Ready for device testing.
Suggested additional test cases
- Android with USDT enabled. Setup: an incoming USDT payment request is open and the requester's app is backgrounded, as in #1534. Action: pay the request and stay on Android until the proof is queued. Expected: the paid request stays off the actionable sheet and list. A later unpaid billing period, when the request is recurring, stays payable.
jvsena42
left a comment
There was a problem hiding this comment.
Code scan: no HIGH/MEDIUM. One LOW is inline.
Checked and clean:
- Proof hand-off:
submitAttemptProofwrites the proof store before settingproofQueued, so a crash in between leaves both stores protecting the request. restoreBackup: it resetsproofQueued, andproof != nullstill protects the attempt.- Fail-closed paths:
protectedPaymentAttempts(...).getOrThrow()fails the whole refresh instead of showing an unprotected list, and reconcile's early clear only hides more. - Identity: identity and billing period are matched through
PubkyPublicKeyFormat.matchesand the fullPaykitPaymentRequestId. - Double pay: same-wallet double pay is still blocked in
prepare/validateReplacement.
On synonymdev/bitkit-ios#1005 the same shape predates that PR (storeAttempt already cleared resumableRequests), so it isn't a finding there.
Device gate (partial): not run yet. Perf-relevant: protectedPaymentAttempts decodes the keychain state under the USDT mutex on every snapshot, including the 10 s INBOX poll, and each FULL reconcile with a failed attempt stored adds one STORED refresh. I'll count refreshes per minute idle against master. No journeys apply. The device result follows in a second review.
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: Follow-up at 51718dec, covering changes since d23d25a. Inherited the completed baseline review for payable request filtering, snapshot invalidation, submission-deferred refresh, and incoming presentation. This pass rechecked USDT retry, restore, and wipe protection.
No new actionable code findings.
A definitely failed request stays payable when a later attempt is prepared and then fails before a transfer is stored. If transfer history cannot be read, the request stays protected. Restore and wipe clear the active wallet and identity, so attempts whose owner is not yet known stay protected; a successful wipe then clears the in-memory attempt list and refreshes requests. These rules match bitkit-ios#1005 at 7b813233. The retry regression in this comment is fixed at this revision.
Validation: the CI build for this revision passed, including testDevDebugUnitTest. Detekt and lint also passed on this head. The new unit tests were inspected and not re-run locally.
Device testing: not performed in this review.
Ready for device testing.
Suggested additional test cases
- Android with USDT enabled. Setup: an incoming USDT request whose earlier payment failed definitely, so the request is payable. Action: start the payment and cancel authorization, or otherwise fail before a transfer is stored. Expected: the request is payable again without waiting for the next full reconciliation. If transfer history cannot be read after that failure, the request stays protected.
jvsena42
left a comment
There was a problem hiding this comment.
Approving at 51718de. The LOW from my earlier review is fixed and resolved.
Device gate: d23d25a — journeys: none listed; perf: idle on Home with a contact and a pending incoming USDT request, 3 FULL / 7 INBOX / 1 STORED refreshes per 180 s vs master 3 / 7 / 0 (the one STORED is a one-off after the first reconcile, ~87 s after launch); while an unresolved USDT attempt is releasable, +1 STORED refresh per minute, bounded at the FULL cadence; app CPU over the idle window 1778 ticks vs master 2137; functional: the USDT request stays hidden while the payment is in flight and comes back after a definite failure (pass); Figma: n/a (no UI); l10n: no UI text changed.
The gate ran at d23d25a. The only commit since, 51718de, changes retry eligibility, restore and wipe bookkeeping in PaykitUsdtPaymentRepo and WipeWalletUseCase, and adds no repeated work. I reviewed it by code and it's covered by the new recovery and wipe tests. CI at 51718de is green.
Functional run: Pixel_9 payer (60 USDT from the local fixture) paid a $2.00 USDT-only request from a Pixel_Tablet contact, with the fixture set to provider-mode invalid-signature so the operation fails. The request bell stayed absent from the submission at 10:28 UTC through 10:42:07. It came back at 10:42:40, right after the STORED refresh that followed Core reporting the transfer failed, and the request reopened on the USDT Amount screen.
Perf method: both builds had one probe line at the top of PaykitPaymentRequestRepo.refresh (there's no existing log line for it), with 75 s warm-up then 180 s idle.
PaykitUsdtPaymentRepoRecoveryTest.
Observation, not a finding (not reproduced, and not compared with master): ~25 s after a cold launch, the first Pay tap closed the sheet without opening anything. A second tap toasted "Payment request operation is already in progress" for over 2 minutes, with no log line for an attempt. After a force-stop Pay worked. The payment-requests README already says the session restore holds the SDK right after launch, but this lasted well beyond that. Worth a look if you can reproduce it.
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings:
- LOW
app/src/main/java/to/bitkit/repositories/PaykitUsdtPaymentRepo.kt:515:reconcile()empties the resumable set before it refills it. An early return in between (a send starting, no identity, cancellation) hides a definitely failed request again until the next complete reconcile, about 60 s in the foreground. A unit test reproduces it at this head; details and a fix are inline.
QA for 51718de:
Tested on two Android 15 emulators with the dev build against a local Arbitrum fork (real Core, bundler and gateway), with $1 USD requests payable only in USDT. The payer build added debug-only log lines at refresh, reconcile and send exit. Test 3 also used a debug-only test hook that holds the proof hand-off until released.
Test 1: retry after a definite failure ✅ A retry that failed before broadcast left the definitely failed request payable at once.
- The first payment of
case3was sent with the fixture set to reject the paymaster signature. The request stayed hidden while the operation was in flight and came back as payable when Core reported it failed. - The retry failed before broadcast with the provider unavailable ("Could not update USDT"). The send logged
wasResumabletrue and no stored transfer. case3was back in Payment Requests two seconds later, before the next reconcile (checked in the debug log).
case-retry.2x.mp4
Test 2: paid request stays hidden ✅ The paid request never came back while its proof was queued, with the requester's app in the background.
- The final retry paid
case3, and the sheet was closed right after submission. - Payment Requests listed only
case1from submission through the proof hand-off and the polls and reconcile that followed. - The requester's USDT history at the end of Test 3's video shows this $1.00 at 2:04 PM.
case-paid.2x.mp4
Test 3: proof delivery delayed ✅ The request stayed hidden while its proof waited, across an app restart, and after delivery.
case1was paid with inclusion held, then included.- With the proof made but its hand-off held (debug log), the bell stayed absent and
case1stayed hidden through repeated reconciles, before and after an app restart. - After release, the proof was queued once and
case1stayed hidden. - The requester shows $1.00 received for that payment from the payer. The payer shows one failed attempt and two sends, with no duplicate.
- Offline alone cannot stage this state: Core cannot refresh the transfer without a network, so no proof is made until it returns.
case-delayed.2x.mp4
Test 4: later billing period ✅ The next period of a USDT subscription became payable while the previous period's payment was still in flight.
- The payer subscribed to a $1 daily USD subscription and paid the first installment with inclusion held. The bell disappeared.
- With the Dev Settings subscription clock offset set to 1 day, the app opened the next installment, and Payment Requests listed
case4with Pay, dated October 20, the second period. - The held first period was not listed.
case-period.2x.mp4
Relied on @jvsena42's device run at d23d25a for the idle refresh counts. Tests 1 and 2 drive the cases @piotr-iohk suggested in the d23d25a and 51718de reviews.
Coverage: full review of 402aecb..51718de. No device case drove the wipe and restore resets (resetForWipe, restoreBackup); they were reviewed in code and their tests.
Pair PR synonymdev/bitkit-ios#1005 at 7b81323 applies the same rules. Its reconcile() also empties resumableRequests first and returns early when a send bumps stateGeneration, so the LOW applies there too.
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: Follow-up re-review of changes since 51718dec, including affected paths and the prior early-exit concern, at 821f939. Inherited the completed baseline review for payable one-time and subscription filtering, snapshot invalidation, submission-deferred refresh, and incoming presentation.
No new actionable code findings.
An interrupted USDT reconcile keeps the previous same-owner failure set privately and publishes it again unless a completed pass replaces it, a send consumes it, or restore, wipe, or a wallet change discards it. A retry that starts during that hold and fails before a transfer is stored becomes payable again; a pending or proved attempt stays protected. These rules match bitkit-ios#1005 at 625c2d0b. The early-exit gap in this thread is fixed at this revision.
Validation: the CI build for this revision passed, including testDevDebugUnitTest. Lint passed on this head, and detekt passed for the same revision. The new recovery tests were inspected and not re-run locally. iOS parity is a source comparison of the changed contract, not a full review of that PR.
Device testing: not performed in this review. Earlier device runs remain tied to d23d25a and 51718dec.
Ready for device testing.
jvsena42
left a comment
There was a problem hiding this comment.
Approving at 821f939. The only commit since my approval, 821f939, keeps a same-owner copy of the resumable set while a reconcile runs and puts it back in a NonCancellable finally if the reconcile doesn't finish. Clean:
sendbumpsstateGenerationandsetPaymentStarted(true)removes the request from both sets under the mutex, so an interrupted reconcile can't re-release an attempt that started meanwhile.- Restore, wipe, an owner change in
activate, a non-releasable attempt and a completed reconcile all clear the copy. validateReplacementstill blocks a second send while an earlier attempt is unresolved.
Device gate: d23d25a (no device re-run for this delta; it adds no repeated work and doesn't change the refresh-bump condition, so the earlier idle numbers hold); perf: as in my previous review; l10n: no UI text changed. CI at 821f939: green.
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: None. The earlier interrupted-reconciliation LOW is fixed at 821f939.
QA for 821f939:
Two Android 15 Pixel 7 emulators, disposable wallets and a local Arbitrum fork. I built the reviewed head; the device builds add diagnostic logs and controlled reconciliation/proof-delivery hooks. Recordings play at 2×.
Test 1: interrupted reconciliation ✅ A definitely failed request becomes payable again after an early exit.
Activity shows the failed payment, and the same request remains available with Pay after reconciliation exits without an identity. Debug logs confirm eligibility was restored before another full reconciliation.
case1.2x.mp4
Test 2: aborted retry during reconciliation ✅ A retry proven unsent restores the request's earlier eligibility.
The retry starts while reconciliation privately holds the failure evidence, then aborts before submission. Debug logs confirm protection during the interrupted pass, readable history with no new operation, and eligibility restored by the stored refresh. The same request returns with Pay.
case2.2x.mp4
Test 3: submitted retry and delayed proof ✅ The request stays hidden through submission, confirmation, restart and proof handoff.
The interrupted pass does not release the new send. Inclusion is held, then the payment confirms. With proof handoff held, the request remains hidden across a payer restart; releasing the hold queues the proof once and leaves the request hidden. The requester is backgrounded. Debug logs establish the interleaving, saved proof and queue handoff; Activity and request visibility are recorded.
case3.2x.mp4
Test 4: billing-period isolation ✅ The next period appears with Pay while the first installment remains pending.
The first daily installment shows Pending. Advancing the subscription test clock by one day exposes the October 20 period with Pay and opens its USDT amount flow. Core blocks a second quote with its pending-payment guard, so this verifies request availability rather than a concurrent second payment. Resetting the clock hides the request again; the October 19 installment still shows Pending. Debug logs confirm the clock changes and request snapshots.
case4.2x.mp4
I relied on @jvsena42's idle-refresh measurements; this delta changes neither the polling schedule nor the refresh-bump condition.
Reviewed the delta, plus the earlier open LOW. Owner changes, backup restore, wipe and cancellation were checked in source and the unmodified 821f939 recovery regressions; those paths were not driven on devices.
Pair PR synonymdev/bitkit-ios#1005 fix: refresh requests when usdt payment state changes matches the protection contract at synonymdev/bitkit-ios@625c2d0. Source comparison only; no iOS device run.
Reviewed by gpt-6.1-sol-high via gh-pr-review-loop skill
Commands: @ovi-reviewer review · test · retest
ovitrif
left a comment
There was a problem hiding this comment.
Approved per the ovi-reviewer review.
|
Merged, as it was approved and green. |
Description
Include saved USDT payment attempts when filtering payable requests, and refresh the request list as payment or proof state changes. In-flight/completed payments remain protected while proof delivery retries; definite failures can be retried. Request snapshots detect overlapping USDT state changes and preserve wallet, identity and billing-period isolation.
Refs #1534. This fixes the confirmed code gap; it does not establish the cause of every reported stale request.
Out of Scope
Design
N/A — no layout changes.
Preview
N/A — payment-state refresh behavior.
QA Notes
Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Automated Checks
added
PaykitPaymentRequestRepoTest.kt— pending/completed USDT protection and overlapping refresh.added
PaykitPaymentRequestRepoSubscriptionTest.kt— later periods remain payable.added
PaykitUsdtPaymentRepoRecoveryTest.kt— restart, wallet/identity isolation, definite failure, unsent retries, restored ownership, and interrupted-refresh recovery without releasing a new send.added
AppViewModelSendFlowTest.kt— USDT changes refresh requests after active submission finishes.updated
WipeWalletUseCaseTest.kt— transient payment state resets after keychain cleanup.ran compile, 4,341 unit tests and detekt; all tests passed and complete lint diagnostics match current master with no introduced findings.