Repository navigation
perf: sync extra wallets apart from the wallet - #2255
Conversation
Bumps ldk-node to 0.7.0-rc.86, which syncs additional wallets in their own pass. They sync every 60 s, and the restore hold, empty address type prune and post-migration sync wait for both passes when the node tracks extra wallets. Verified: ./gradlew :app:testDevDebugUnitTest (AppViewModelSendFlowTest; LightningRepoTest before the last AppViewModel edit), ./gradlew detekt
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryMoves extra wallets onto a separate sync schedule and waits for their sync before finishing restore work.
No actionable issues found. Review was based on source inspection; tests were not run.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[SyncCompleted] --> B[Record on-chain pass height]
B --> C{Restore or migration work pending?}
C -->|Yes| D{Primary pass recorded?}
D -->|Yes| E{Extra wallets tracked?}
E -->|No| F[Use primary height]
E -->|Yes| G{Extra pass recorded?}
G -->|Yes| H[Use lower height]
F --> I[Finish eligible restore or migration work]
H --> I
D -->|No| J[Wait]
G -->|No| J
K[Node leaves Running] --> L[Clear recorded heights]
Reviews (1) · Last reviewed commit: "perf: sync extra wallets apart from the ..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d843f94e05
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
The journey funds a monitored Taproot address, restores from the phrase and checks the restore hold waits for the extra wallets' pass. Also drops the KDoc on a private helper, per AGENTS.md. Verified: ./gradlew detekt
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Bumps ldk-node to 0.7.0-rc.86, which syncs extra on-chain wallets in their own ADDITIONAL_ONCHAIN_WALLETS pass every 60 s. The restore hold, the empty address type prune and post-migration completion now wait until both passes have run since the node started, and use the lower of the two heights. Reviewed d843f94, full tier, static: per the Bitkit track policy an auto review does not build bitkit-android branches, so this rests on the code, the ldk-node v0.7.0-rc.86 source and CI.
What I checked, and 4 candidates I ruled out
Read in full: handleSyncCompleted, allOnchainWalletsSyncedHeight, completePendingRestoreActivitySeen, completeMigration, completeRNRemoteBackupRestore, applyPendingChannelMigration, LightningService.reconcileWatchOnlyAccounts and sync, and the new tests in AppViewModelSendFlowTest.kt and LightningRepoTest.kt.
ldk-node rc.86 checked: run_additional_wallet_sync_loop runs next to the primary loop, and its first interval.tick() fires straight away, so the first additional pass starts with the node and not 60 s later. emit_pass_events sends AdditionalOnchainWallets only when synced_accounts is not empty and stamps it with tip_height_of(synced_accounts). list_onchain_wallet_accounts returns every loaded wallet, primary included, so size > 1 matches what the additional pass syncs: monitored account-0 types plus derived accounts.
CI at review time: build-and-test, build-local, compose-ui, detekt, Greptile and e2e send green. e2e multi_address_local still pending.
Ruled out
- A hold that never lifts when one extra wallet keeps failing to sync: the additional pass returns
Errbefore emitting, so neither the restore hold nor post-migration completion would clear. rc.85 had the same problem: its combined pass foldedadditional_outcome.errorinto the result and skipped theOnchainWalletevent too. Not new in this PR. - Extra wallets removed mid-restore, leaving the hold waiting for a pass that never reports:
hasAdditionalWallets()is read again on every on-chain sync, so once the list is down to the primary wallet, its own pass releases the hold. - A height left over from the stopped node lifting the hold after a restart: the lifecycle collector clears the map on every state that is not
Running, and the height is read again after thehasAdditionalWallets()suspension.restore does not count syncs from before a node restart...covers it. - The channel-migration restart in
applyPendingChannelMigrationclearing the heights whilecompleteMigrationruns: that path is already past the gate and holdsisCompletingMigration, so clearing the map does not interrupt it.
Merge confidence: 4/5. Nothing was found, but multi_address_local was still pending at review time and the restore-with-extra-wallets run on a device is still an open Gap in the PR body.
Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (the session metadata available to this run does not report a reasoning setting)
rc.87 fixes sync_wallets never returning on VSS-backed nodes, which stopped the background syncs this PR depends on. Verified: ./gradlew --write-verification-metadata sha256 resolves 0.7.0-rc.87; testDevDebugUnitTest for AppViewModelSendFlowTest and LightningRepoTest pass
After the reset, Restore is reached through the terms and intro, and shows the multiple-devices warning before the word inputs. The README lists the tags. Verified: the journey ran end to end on the emulator at a1049fa with these steps taken by hand; XML parses
rc.88 fixes the additional wallets' sync pass hanging after a primary address type change, which failed multi_address_local E2E. Verified: assembleDevDebug and syncNativeDebugSymbolArtifacts pass with strict dependency verification
|
Bumped ldk-node to 0.7.0-rc.88 in 69530f1 to fix the Also pushed fa33730, which walks the extra wallets restore journey through onboarding (terms, intro, multiple-devices warning). |
rc.89 has the same behaviour as rc.88; its additional wallets' sync loop gained tests. Verified: assembleDevDebug and syncNativeDebugSymbolArtifacts pass with strict dependency verification
|
Bumped ldk-node to 0.7.0-rc.89 in eb5cc89. It behaves the same as rc.88; the only change is tests for its additional wallets' sync loop, which the library's release rules require to ship as a new rc. |
jvsena42
left a comment
There was a problem hiding this comment.
Code scan at eb5cc897a: no HIGH, MEDIUM or LOW findings. The device gate is still to run.
What I checked and found clean:
- Prune of a funded address type. The prune needs an
ADDITIONAL_ONCHAIN_WALLETScompletion since node start whenever extra wallets exist (AppViewModel.kt:2929). rc.89 emits that event only when every extra wallet synced without error (emit_pass_events). Restore monitors all four types before the node starts (WalletRepo.kt:708).pruneEmptyAddressTypesAfterRestoreskips a type whose balance read fails. This is stricter than master, where anySyncCompletedlet the prune run. - Balance after restore.
ADDITIONAL_ONCHAIN_WALLETSevents still go throughdebounceSyncByEvent→syncBalances.restoreSyncedBlockHeightuses the lower of the two heights. - Waits that never end. With no extra wallets the wallet's own pass releases the hold, since ldk-node emits no additional event then. A failed
hasAdditionalWallets()is retried on the next sync. The extras' first tick fires at once. The migration wait keeps its 120 s timeout. - "Since node start". The map is cleared on every non-Running lifecycle state, including Starting, so stop, wipe and the channel-migration restart reset it. All access is on the main dispatcher.
- ldk-node rc.85 → rc.89.
- No change to store namespaces, keys or schema.
SyncType::AdditionalOnchainWalletsis a new TLV variant in the persisted event queue. Upgrading from v3.1.1 (rc.80) is fine. Installing master over a PR build with that event queued may fail to read the queue, which only matters for QA downgrades.
syncWallets()duration. I checked whether app-triggered syncs now take primary + the sum of the extra wallets. They don't. rc.89 runs the primary and additional scopes concurrently on separate Electrum connections (chain/mod.rs:1230). Only the extra wallets run one after another (sync_additional_wallets_in_turn). So a manual sync takes about max(primary, sum of extras), where rc.85 pipelined everything on one connection. The device gate measures this.
Not posted: allOnchainWalletsSyncedHeight keeps a stale additional height when the extra wallets disappear (AppViewModel.kt:2966); iOS clears it in OnchainSyncTracker.record. A unit test shows the hold lifting early. Reaching it needs a failed seen-marking or migration retry during a restore, plus removing every extra wallet and adding one back without a node restart. The only effect is replayed activity showing as unseen. A cheap parity fix if you want it: onchainSyncedSinceStart.remove(SyncType.ADDITIONAL_ONCHAIN_WALLETS) before return primary.
Performance: relevant, because the PR's purpose is speed and it re-times background work (a new 60 s loop for the extra wallets). The device gate measures these, against master (rc.85) on the same emulator:
- wallet pass duration and pull-to-refresh time (
Syncing LDK…→LDK synced) with 0, 1 and 3+ extra wallets; - how often the extra wallets sync;
- time for a receive to a monitored non-primary type to show up (about 10 s on master, up to about 60 s here);
- restore time with history on two or more types, then
restore-waits-for-extra-wallets.xml, checking that Taproot stays monitored after the prune.
Device gate (partial): eb5cc89 — not run yet. Pending: journey restore-waits-for-extra-wallets.xml and the perf measurements above. The device result will follow in a second review.
Reviewer model: claude-fable-5-2 (primary review), claude-opus-5-5 (verification)
Reasoning effort: Not exposed (no effort setting in the run metadata available to either reviewer)
Adding an extra wallet back without a node restart reused the old height and lifted the restore hold early. iOS already clears it. Verified: ./gradlew :app:testDevDebugUnitTest --tests AppViewModelSendFlowTest :app:detekt
Verified: ./gradlew :app:testDevDebugUnitTest --tests AppViewModelSendFlowTest :app:detekt (the new test fails without the previous commit's fix)
Verified: ./gradlew :app:testDevDebugUnitTest --tests AppViewModelSendFlowTest :app:detekt
|
@jvsena42 thanks for the scan.
Fixed in 8f7490b: with no extra wallets left, the extra wallets' height is dropped, as on iOS, so adding one back waits for its sync. 6935dfc adds a test that fails without the fix.
Left as is on Android. A payment arriving in that window still shows its sheet once it confirms, since its block is above the restore tip. Showing it while it is in the mempool would need a held-receive queue like iOS has, and without one the extra wallets' replayed history would pop sheets. iOS gets the fix in synonymdev/bitkit-ios#1588. |
Verified: ./gradlew :app:testDevDebugUnitTest --tests AppViewModelSendFlowTest --tests LightningRepoTest :app:detekt
Verified: ./gradlew assembleDevDebug :app:syncNativeDebugSymbolArtifacts with strict dependency verification
Verified: none (journey text only; the backup sheet opens on the phrase, BackupIntroViewContinue no longer exists in the app)
jvsena42
left a comment
There was a problem hiding this comment.
Device gate passed on 7d9cacb20, run on an Android emulator against master fc82f5c9d (rc.85) on the same day. No HIGH, MEDIUM or LOW findings, so approving.
8f7490baf fixes the stale extra-wallet height I mentioned last round.
The head is now f78f62800. The commits since the gate are the rc.90 bump, a clean master merge and a one-line journey edit. rc.90 only changes PaymentDetails::update in payment/store.rs, so the gate result carries over.
Journey restore-waits-for-extra-wallets.xml: PASS, all steps.
- No Received sheet appeared for the 300 000 sat Taproot deposit during about 4 min after the restore. Home lists it, and the savings balance includes it from the first frame.
- The seen-marking waits for the extras' pass:
14:52:37.380 SyncCompleted ONCHAIN_WALLET (no marking) 14:52:39.427 SyncCompleted ADDITIONAL_ONCHAIN_WALLETS 14:52:39.957 Marking activities replayed by the first sync after restore as seen - Restore time, from the Restore tap to Get Started: 40.6 s on this branch and 71.4 s on master. Most of the gap is before
Full restore starting, and it is one sample each, so I'm not counting it either way.
Performance, one extra wallet (Native Segwit primary, Taproot monitored):
| master (rc.85) | PR | |
|---|---|---|
| wallet pass, median | 1444 ms (n=67) | 762 ms (n=24) |
| extra wallets' pass | inside the wallet pass | every 59.8-60.3 s, 678-855 ms |
| receive to the primary type, deposit to Home | 24.5 s, 24.5 s | 20.1 s, 19.7 s |
| receive to the monitored Taproot type | 27.3 s, 24.2 s | 37.3 s, 24.4 s |
pull-to-refresh, gesture to Sync manual completed |
5.1-5.5 s | 4.6-5.2 s |
- A receive to a monitored non-primary type now waits for the 60 s pass, so it can take up to about a minute where master took about 10 s. That is the design of the split. Both runs landed about 2 s after an extras'
SyncCompleted. - The first extras' pass after switching the primary type took 22.8 s and 28.4 s, once each. That is the full scan of the changed set.
Not tested on a device:
⚠️ 0 and 3+ extra wallets. Only one extra wallet was measured.⚠️ Paykit Server accounts as extra wallets. Master now loads them after node start (#2248), so their first pass can come after the restore gate opened. Not exercised here.⚠️ The headf78f62800itself (the rc.90 bump plus the master merge).
Unrelated to this PR, and seen on master too: after a restore, Backup failed for 'METADATA' [IllegalStateException='Public address exclusions must be backed up before replacing metadata'].
Reviewer model: claude-fable-5-2 (primary review, delta reviews), claude-opus-5-5 (verification, coordination), claude-sonnet-5-5 (device driver)
Reasoning effort: Not exposed (no effort setting in the run metadata available to these reviewers)
jvsena42
left a comment
There was a problem hiding this comment.
Changing my approval to request changes: the ldk-node rc.90 this PR pins has a MEDIUM that reaches the app. The finding and its failing test are at synonymdev/ldk-node#154 (review).
What it means here, traced in code and not run on a device: after a restore, a past send from a non-primary address type with change to the primary is first reported as +change, and the corrected event is dropped.
- If the backup already restored the row as SENT, its value becomes
max(sent, change).buildUpdatedOnchainActivitykeeps the larger value (CoreService.kt:1298-1302) and never changestxType. - Without a backup row, the activity is created as RECEIVED with the change amount and stays that way.
- Outside a restore, the same seed spending on another device while this one was offline shows a "Received +change" sheet.
My restore gate here only had a receive on the Taproot wallet, so it didn't cover this. The rest of my approval comment still stands once a fixed rc is pinned.
Reviewer model: claude-fable-5-2 (primary review), claude-opus-5-5 (verification, app-side trace, coordination)
Reasoning effort: Not exposed (no effort setting in the run metadata available to these reviewers)
Verified: ./gradlew assembleDevDebug :app:syncNativeDebugSymbolArtifacts with strict dependency verification
Verified: none (docs only; tags checked against restore-waits-for-extra-wallets.xml)
|
@jvsena42 pushed 4f64cc0, which pins v0.7.0-rc.91 with the fix for the MEDIUM you raised on synonymdev/ldk-node#154 (reply there), and 94d8abe, which adds the address type tags the restore journey uses to its README. In the restore case you traced, the first event and the payment record now carry the send itself (
|
|
The |
|
Cancelled my rerun of that run: |
jvsena42
left a comment
There was a problem hiding this comment.
Approving at 94d8abe81. The MEDIUM I raised here is fixed upstream in ldk-node rc.91, which this head pins. I verified the fix on regtest on synonymdev/ldk-node#154 (thread reply there).
- In the restore race, the first event and the payment record now carry the send (
-30133, Outbound), so the app never creates a change-sized row for it. - In the remaining case, the funding coin is not known to any loaded wallet on the first pass (beyond the additional wallet's 25-address lookahead, or a type added later). The first event is still
+change, and ldk-node now re-emits the send on the next pass. The app keeps the first row's type and the larger value.⚠️ I did not check this case on a device. The approval rests on your statement that master behaves the same there.
The commits since my last review change only the dependency pin and a journeys README note. No app code changed.
Device gate: 7d9cacb (journey, restore and sync timings in my earlier review). additional_wallet_amounts_test and my probe), not by an app run.
CI: the e2e @send_2 failure is the QuickPay price issue that synonymdev/bitkit-e2e-tests#326 fixes. It is unrelated to this PR and needs a re-run before merge.
Reviewer model: claude-fable-5-2 (ldk-node delta review), claude-opus-5-5 (verification, coordination)
Reasoning effort: Not exposed for Fable; low for Opus (session setting)
|
Merging: approved at 94d8abe, and checks pass now that |
|
For the record: the |
Twin: synonymdev/bitkit-ios#1588
Dependency: synonymdev/ldk-node#154
Bumps ldk-node to v0.7.0-rc.91, which syncs additional on-chain wallets (Paykit Server accounts, monitored address types) in their own background pass, so they no longer slow down the wallet's own sync. It also fixes that pass hanging for up to a minute after a primary address type change, and an on-chain send showing as a receipt of its change, with no fee, when the wallet it spent from is not loaded or has not synced the spent coin yet, as after a restore.
Description
LightningService.kt: setsadditionalWalletSyncIntervalSecsto 60 s in both Esplora and ElectrumBackgroundSyncConfig.AppViewModel.kt:SyncType.ONCHAIN_WALLETnow covers only the wallet's own pass, so the restore hold, the empty address type prune and the post-migration sync wait until the wallet's pass andSyncType.ADDITIONAL_ONCHAIN_WALLETShave both completed since the node started, and use the lower of the two heights. Without extra wallets the wallet's pass is enough, as before, and a height left by extra wallets since removed is dropped, so adding one back waits for its sync.LightningRepo.kt:hasAdditionalWallets()tells whether the node tracks wallets besides the primary.gradle/libs.versions.toml,gradle/verification-metadata.xml: rc.91 and its artifact checksums.Out of Scope
Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
Build from this branch (dev, regtest or mainnet). For the restore cases, use a wallet with more than one monitored address type or a Paykit Server account, so the node tracks extra wallets.
Journeys
journeys/backup-restore/restore-waits-for-extra-wallets.xml: back up a funded wallet whose Taproot address type stays monitored after switching to Native Segwit, reset, then restore through the terms, intro and the multiple-devices warning. Expect no Received sheet for the old deposit, the right balance, and old activity marked seen only after the extra wallets' pass.Manual Tests
N/A
Automated Checks
AppViewModelSendFlowTest.kt— restore marks activities seen only after the extra wallets synced, at their lower heightAppViewModelSendFlowTest.kt— restore waits for the wallet's pass when the extra wallets sync firstAppViewModelSendFlowTest.kt— restore waits again for extra wallets added back after all were removedAppViewModelSendFlowTest.kt— syncs from before a node restart and unknown wallets do not countAppViewModelSendFlowTest.kt— empty address type prune and post-migration sync wait for the extra walletsLightningRepoTest.kt—hasAdditionalWalletscounts wallets besides the primary and reports a failed readEvidence
restore-waits-for-extra-walletsjourney at a1049fa (rc.87), Android emulator: ran end to end through onboarding; the restore reached Home with no stall.assembleDevDebugandsyncNativeDebugSymbolArtifactspass at 4f64cc0 (rc.91) with strict dependency verification.multi_address_localincluded; it runs again on this head in CI../gradlew :app:testDevDebugUnitTest(AppViewModelSendFlowTest) and./gradlew detektpass at 848f299, after merging master;LightningRepoTestpasses at a1049fa (rc.87).Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high),Claude Haiku 5.5(reasoning:high)Gemini 4 Neon(reasoning:high)