stop wallet scans when wallet disappears#699
stop wallet scans when wallet disappears#699Sandipmandal25 wants to merge 2 commits intobitcoinppl:appmanager-walletmanager-lifecyclefrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
fixed the rust side |
Greptile SummaryThis PR stores a Confidence Score: 4/5Safe to merge; all remaining findings are P2 hardening suggestions that do not affect correctness in the current sequential scan flow. The core change achieves its stated goal correctly. Three P2 notes: (1) scan handles are overwritten without aborting the previous — harmless given sequential scan ordering but could silently leak a task if two scans overlap; (2) stop_all_scans does not reset self.state, leaving queued actor messages a small window to update a torn-down actor; (3) single-tx send_fut scans are deliberately untracked but deserve a comment. rust/src/manager/wallet_manager/actor.rs — specifically the three scan-launch methods and stop_all_scans Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Caller
participant A as WalletActor
participant T1 as InitialScanTask
participant T2 as ExpandedScanTask
participant T3 as IncrementalScanTask
C->>A: start_wallet_scan_in_task()
alt No prior full scan
A->>A: send!(perform_full_scan)
A->>A: maybe_perform_initial_full_scan()
A->>T1: tokio::spawn(initial scan)
Note over A: scan_task = T1.abort_handle()
T1-->>A: call!(handle_full_scan_complete)
T1->>A: send!(maybe_perform_expanded_full_scan)
A->>A: send!(perform_expanded_full_scan)
A->>T2: tokio::spawn(expanded scan)
Note over A: scan_task = T2.abort_handle() ⚠️ T1 handle dropped
T2-->>A: send!(handle_full_scan_complete)
else Prior full scan exists
A->>A: send!(perform_incremental_scan)
A->>T3: tokio::spawn(incremental scan)
Note over A: scan_task = T3.abort_handle()
T3-->>A: send!(handle_incremental_scan_complete)
end
C->>A: stop_all_scans()
Note over A: scan_task.take().abort() ✅
Note over A: transaction_watchers cleared ✅
Note over A: self.state NOT reset ⚠️
Note over A: Drop
Note over A: scan_task.take().abort() ✅
|
| @@ -1190,6 +1195,7 @@ impl WalletActor { | |||
| // update wallet state | |||
| send!(addr.handle_full_scan_complete(full_scan_result, FULL_SCAN_TYPE)); | |||
| }); | |||
| self.scan_task = Some(handle.abort_handle()); | |||
|
|
|||
| Produces::ok(()) | |||
There was a problem hiding this comment.
Silent overwrite of previous scan handle
self.scan_task is overwritten without first aborting the old handle. AbortHandle::drop does not abort the underlying tokio task; only calling .abort() does. In the normal sequential flow (initial scan fully completes before the expanded scan spawns) this is fine, but if two calls somehow overlap (e.g. two start_wallet_scan_in_task calls more than 15 seconds apart while a scan is still in progress), the earlier task becomes untrackable and stop_all_scans / Drop will only cancel the later one. The same pattern applies to perform_incremental_scan and perform_initial_full_scan.
| if let Some(old) = self.scan_task.replace(handle.abort_handle()) { | |
| old.abort(); | |
| } |
There was a problem hiding this comment.
scans run sequentially so the old handle is always for a finished task, .abort() on a finished task is a no op in tokio so this is harmless. done the change anyway as its defensive
25f70e6 to
64a9a36
Compare
64a9a36 to
825cbd7
Compare
Summary
stop_all_scanshad a TODO for stopping wallet scans but was only clearing transaction watchers. Scan futures were being spawned without storing their handles, so they could not be cancelled.This change stores an abort handle for each scan (initial, expanded, incremental) when it starts, and cancels them in
stop_all_scansandDrop. This ensures scans stop promptly when the wallet disappears or the actor is dropped.fixes part of #295
Checklist