Restart the foreground sync service when the connection changes
What changed, and why it matters
This commit fixes a bug where changing the wallet's server connection (for example, switching between a local node and a remote light wallet server) did not restart the background sync service. As a result, the service could keep syncing against the old server until manually restarted. The patch makes the app restart the foreground sync service after a connection change so it picks up the new server settings.
Treat as a routine reliability fix. Verify that `restartForegroundSyncIfRunning` gracefully handles the case where the service is not running and that the isolate restart does not lose sync progress or corrupt wallet state. No urgent security response is indicated by the diff alone.
Security signals we found
configuration-not-applied-to-background-isolate
sync-service-continues-using-stale-server
connection-change-handling-improvement
Evidence from the diff
The change exposes a new restartForegroundSyncIfRunning API from the wallet_background package and calls it inside applyConnectionChange after the wallet manager rebuilds the wallet. The goal is to force the foreground sync isolate to re-read the updated server configuration. This is a correctness/reliability fix rather than a memory-safety or cryptographic bug.
Changed components
lib/services/foreground_sync_service.dartlib/wallet_core_glue.dartforeground sync isolateInspect captured patch +5 / −2
### lib/services/foreground_sync_service.dart
@@ -10,6 +10,7 @@ export 'package:wallet_background/wallet_background.dart'
startForegroundSync,
stopForegroundSync,
startForegroundSyncIfEnabled,
+ restartForegroundSyncIfRunning,
isWalletFullySynced,
stopSyncAndDeleteWallets;
### lib/wallet_core_glue.dart
@@ -10,7 +10,7 @@ import 'package:skylight_wallet/models/monero_wallet_adapter.dart';
import 'package:skylight_wallet/widgets/tx_details.dart' show TxDetailsDialog;
import 'package:skylight_wallet/periodic_tasks.dart' show backgroundDispatcher;
import 'package:skylight_wallet/services/foreground_sync_service.dart'
- show foregroundSyncCallback, stopSyncAndDeleteWallets;
+ show foregroundSyncCallback, stopSyncAndDeleteWallets, restartForegroundSyncIfRunning;
import 'package:skylight_wallet/services/notifications_service.dart';
import 'package:skylight_wallet/services/shared_preferences_service.dart';
import 'package:skylight_wallet/services/tor_service.dart';
@@ -256,5 +256,7 @@ Future<void> deleteWallet(BuildContext context) async {
/// Rebuilds the wallet if the server kind (LWS↔node) changed, then resyncs.
void applyConnectionChange(BuildContext context) {
- unawaited(Provider.of<WalletManager>(context, listen: false).applyConnectionChange('XMR'));
+ final manager = Provider.of<WalletManager>(context, listen: false);
+ // Restart the foreground service too, so its isolate re-reads the new server.
+ unawaited(manager.applyConnectionChange('XMR').then((_) => restartForegroundSyncIfRunning()));
}Why this scored 22/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.