stop a silent payments wallet scan that completes after its wallet is closed from refreshing and subscribing the closed wallet again
What changed, and why it matters
This commit fixes a bug where closing a Sparrow wallet while a background 'silent payments' scan was still running could cause the closed wallet to be re-subscribed and refreshed after the scan finished. The fix adds a 'closed' flag so any late-arriving scan results are ignored instead of reactivating a wallet the user already closed. It is a reliability/privacy bug rather than a direct theft-of-funds vulnerability.
Apply the patch. It is a low-risk defensive fix. Users who run silent payments wallets should upgrade to avoid the stale-subscription/refresh behavior, though no immediate funds-loss is evident from the diff.
Security signals we found
Closed wallet could be silently re-subscribed/refreshed by asynchronous background task
Background silent payments scan callback could fire wallet history events on a closed wallet
Potential for stale wallet state or unintended network subscription after user closed wallet
Fix prevents reporting a scan cancellation caused by wallet closure as a history failure
Evidence from the diff
WalletForm now tracks a boolean closed field. It is set to true when walletTabsClosed fires for the form (including nested forms). refreshHistory(...) returns early if closed is true, preventing a queued refresh from re-subscribing the wallet. The silent-payment scan success and failure callbacks also return early if closed is true, stopping a scan that completes after closure from posting WalletHistoryFinishedEvent or WalletHistoryFailedEvent and from refreshing/subscribing the wallet again. The failure-path comment notes that closing releases the subscription and cancels the scan, so that outcome should not be reported as a history failure.
Changed components
src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.javaSilent payments scan service callbacks (setOnSucceeded / setOnFailed)Wallet tab close lifecycle (WalletTabsClosedEvent handler)refreshHistory methodsInspect captured patch +18 / −0
### src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java
@@ -60,6 +60,8 @@ public class WalletForm {
private boolean spSubscriptionHeld;
private boolean spPendingRefresh;
+ private boolean closed;
+
private final BooleanProperty lockedProperty = new SimpleBooleanProperty(false);
private final Disposable refreshNodesDisposable;
@@ -159,6 +161,11 @@ public void refreshHistory(Integer blockHeight, Set<WalletNode> nodes) {
}
public void refreshHistory(Integer blockHeight, List<Wallet> filterToWallets, Set<WalletNode> nodes) {
+ //A refresh queued before the wallet was closed would otherwise subscribe it again
+ if(closed) {
+ return;
+ }
+
Wallet previousWallet = wallet.copy();
if(wallet.isValid() && AppServices.isConnected()) {
if(log.isDebugEnabled()) {
@@ -235,6 +242,10 @@ private void refreshHistorySP(Wallet previousWallet, Integer blockHeight) {
ElectrumServer.SilentPaymentScanService scanService = new ElectrumServer.SilentPaymentScanService(wallet, shouldHold, wallet.getNeededScanStart());
scanService.setOnSucceeded(workerStateEvent -> {
spScanInProgress = false;
+ if(closed) {
+ return;
+ }
+
spSubscriptionHeld = true;
if(scanService.getValue()) {
EventManager.get().post(new WalletHistoryFinishedEvent(wallet));
@@ -244,6 +255,11 @@ private void refreshHistorySP(Wallet previousWallet, Integer blockHeight) {
});
scanService.setOnFailed(workerStateEvent -> {
spScanInProgress = false;
+ //Closing releases the subscription, which cancels the scan: that is not a history failure to report
+ if(closed) {
+ return;
+ }
+
if(scanService.isReleasedHold()) {
spSubscriptionHeld = false;
}
@@ -835,12 +851,14 @@ public void walletSilentPaymentAddressesChanged(WalletSilentPaymentAddressesChan
public void walletTabsClosed(WalletTabsClosedEvent event) {
for(WalletTabData tabData : event.getClosedWalletTabData()) {
if(tabData.getWalletForm() == this) {
+ closed = true;
EventManager.get().unregister(this);
disposeRefreshNodes();
if(walletTransactionsEntry != null) {
walletTransactionsEntry.unregisterForConfirmations();
}
for(WalletForm nestedWalletForm : nestedWalletForms) {
+ nestedWalletForm.closed = true;
EventManager.get().unregister(nestedWalletForm);
nestedWalletForm.disposeRefreshNodes();
if(nestedWalletForm.walletTransactionsEntry != null) {Why this scored 33/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.