Harden local node sync and restart flow
build / Build Linux wallet (push) Successful in 2m47s
build / Build Windows wallet (push) Successful in 20m15s

This commit is contained in:
Codex Bot
2026-04-19 18:29:36 +02:00
parent ed43484fe4
commit 7a1b86c8d0
3 changed files with 35 additions and 15 deletions
+15 -8
View File
@@ -147,14 +147,21 @@ class _PeyaAppState extends ConsumerState<PeyaApp> {
return;
}
}
try {
await ref
.read(walletControllerProvider.notifier)
.connectNode(config.nodeConfig);
await ref.read(walletControllerProvider.notifier).syncNow();
return;
} catch (error) {
ref.read(loggerProvider).w('Failed to connect node: $error');
final attempts = config.nodeConfig.mode == NodeMode.local ? 5 : 1;
for (var attempt = 0; attempt < attempts; attempt++) {
try {
await ref
.read(walletControllerProvider.notifier)
.connectNode(config.nodeConfig);
await ref.read(walletControllerProvider.notifier).syncNow();
return;
} catch (error) {
if (attempt + 1 >= attempts) {
ref.read(loggerProvider).w('Failed to connect node: $error');
return;
}
await Future.delayed(const Duration(seconds: 1));
}
}
}
+9 -2
View File
@@ -39,12 +39,19 @@ class WindowsLocalNodeService implements LocalNodeService {
@override
Future<bool> stop() async {
final effective = _resolveConfig(null);
final stopped = await _stopViaRpc(effective);
if (!await _isRpcAvailable(effective)) {
return true;
}
final rpcAccepted = await _stopViaRpc(effective);
final stopped = await _waitForStop(effective);
if (!stopped) {
_logger.w('Failed to stop local node via RPC.');
return false;
}
return _waitForStop(effective);
if (!rpcAccepted) {
_logger.i('Local node stopped despite RPC response/read failure.');
}
return true;
}
@override
+11 -5
View File
@@ -391,11 +391,17 @@ class _LocalNodeControlsState extends ConsumerState<_LocalNodeControls> {
final nodeConfig = config.nodeConfig;
final walletState = ref.read(walletControllerProvider);
if (walletState.walletInfo != null && nodeConfig.mode == NodeMode.local) {
try {
await ref.read(walletControllerProvider.notifier).connectNode(nodeConfig);
await ref.read(walletControllerProvider.notifier).syncNow();
} catch (_) {
// Keep action successful if daemon started; sync errors surface through wallet state.
for (var attempt = 0; attempt < 5; attempt++) {
try {
await ref.read(walletControllerProvider.notifier).connectNode(nodeConfig);
await ref.read(walletControllerProvider.notifier).syncNow();
break;
} catch (_) {
if (attempt == 4) {
break;
}
await Future.delayed(const Duration(seconds: 1));
}
}
}
return ok;