-
Notifications
You must be signed in to change notification settings - Fork 9
sync main #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync main #265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // TODO(komodo-team): Allow passing the start sync mode; currently hard-coded | ||
| // to sync from the time of activation. | ||
| // Start sync mode can be passed via one-shot sync params through | ||
| // ActivationConfigService.setOneShotSyncParams() before activation. | ||
| // See zhtlc_config_dialog.dart for UI implementation. | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:developer' show log; | ||
|
|
@@ -81,17 +82,22 @@ class ZhtlcActivationStrategy extends ProtocolActivationStrategy { | |
| privKeyPolicy: privKeyPolicy, | ||
| ); | ||
|
|
||
| // Apply sync params if provided by the user configuration via rpc_data | ||
| if (params.mode?.rpcData != null && userConfig.syncParams != null) { | ||
| final rpcData = params.mode!.rpcData!; | ||
| final updatedRpcData = ActivationRpcData( | ||
| lightWalletDServers: rpcData.lightWalletDServers, | ||
| electrum: rpcData.electrum, | ||
| syncParams: userConfig.syncParams, | ||
| ); | ||
| params = params.copyWith( | ||
| mode: ActivationMode(rpc: params.mode!.rpc, rpcData: updatedRpcData), | ||
| ); | ||
| // Apply one-shot sync_params only when explicitly provided via config form | ||
| // right before activation. This avoids caching and unintended rewinds. | ||
| if (params.mode?.rpcData != null) { | ||
| final oneShotSync = await configService.takeOneShotSyncParams(asset.id); | ||
| if (oneShotSync != null) { | ||
| final rpcData = params.mode!.rpcData!; | ||
| final updatedRpcData = ActivationRpcData( | ||
| lightWalletDServers: rpcData.lightWalletDServers, | ||
| electrum: rpcData.electrum, | ||
| syncParams: oneShotSync, | ||
| ); | ||
|
Comment on lines
+87
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When applying one‑shot Useful? React with 👍 / 👎. |
||
| params = params.copyWith( | ||
| mode: | ||
| ActivationMode(rpc: params.mode!.rpc, rpcData: updatedRpcData), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| yield ZhtlcActivationProgress.validation(protocol); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import 'package:hive_ce/hive.dart'; | |||||||||||||||||||||||
| import 'package:komodo_defi_rpc_methods/komodo_defi_rpc_methods.dart'; | ||||||||||||||||||||||||
| import 'package:komodo_defi_types/komodo_defi_type_utils.dart'; | ||||||||||||||||||||||||
| import 'package:komodo_defi_types/komodo_defi_types.dart'; | ||||||||||||||||||||||||
| import 'package:komodo_defi_local_auth/komodo_defi_local_auth.dart'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| typedef JsonMap = Map<String, dynamic>; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -51,15 +52,20 @@ class ZhtlcUserConfig { | |||||||||||||||||||||||
| final int scanBlocksPerIteration; | ||||||||||||||||||||||||
| final int scanIntervalMs; | ||||||||||||||||||||||||
| final int? taskStatusPollingIntervalMs; | ||||||||||||||||||||||||
| /// Optional, accepted for backward compatibility. Not persisted. | ||||||||||||||||||||||||
| /// If provided to saveZhtlcConfig, it will be applied as a one-shot | ||||||||||||||||||||||||
| /// sync override for the next activation and then discarded. | ||||||||||||||||||||||||
| final ZhtlcSyncParams? syncParams; | ||||||||||||||||||||||||
| // Sync params are no longer persisted here; they are supplied one-shot | ||||||||||||||||||||||||
| // via ActivationConfigService at activation time when the user requests | ||||||||||||||||||||||||
| // an intentional resync. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| JsonMap toJson() => { | ||||||||||||||||||||||||
| 'zcashParamsPath': zcashParamsPath, | ||||||||||||||||||||||||
| 'scanBlocksPerIteration': scanBlocksPerIteration, | ||||||||||||||||||||||||
| 'scanIntervalMs': scanIntervalMs, | ||||||||||||||||||||||||
| if (taskStatusPollingIntervalMs != null) | ||||||||||||||||||||||||
| 'taskStatusPollingIntervalMs': taskStatusPollingIntervalMs, | ||||||||||||||||||||||||
| if (syncParams != null) 'syncParams': syncParams!.toJsonRequest(), | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| static ZhtlcUserConfig fromJson(JsonMap json) => ZhtlcUserConfig( | ||||||||||||||||||||||||
|
|
@@ -70,9 +76,6 @@ class ZhtlcUserConfig { | |||||||||||||||||||||||
| taskStatusPollingIntervalMs: json.valueOrNull<int>( | ||||||||||||||||||||||||
| 'taskStatusPollingIntervalMs', | ||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||
| syncParams: ZhtlcSyncParams.tryParse( | ||||||||||||||||||||||||
| json.valueOrNull<dynamic>('syncParams'), | ||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -189,10 +192,31 @@ class ActivationConfigService { | |||||||||||||||||||||||
| ActivationConfigService( | ||||||||||||||||||||||||
| this.repo, { | ||||||||||||||||||||||||
| required WalletIdResolver walletIdResolver, | ||||||||||||||||||||||||
| }) : _walletIdResolver = walletIdResolver; | ||||||||||||||||||||||||
| Stream<KdfUser?>? authStateChanges, | ||||||||||||||||||||||||
| }) : _walletIdResolver = walletIdResolver { | ||||||||||||||||||||||||
| // Listen to auth state changes to clear one-shot params on sign-out | ||||||||||||||||||||||||
| _authStateSubscription = authStateChanges?.listen((user) { | ||||||||||||||||||||||||
| if (user == null) { | ||||||||||||||||||||||||
| // User signed out, clear all one-shot params | ||||||||||||||||||||||||
| _oneShotSyncParams.clear(); | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| // User signed in or changed, clear one-shot params for previous wallet | ||||||||||||||||||||||||
| // if it was different from the current one | ||||||||||||||||||||||||
| if (_lastWalletId != null && _lastWalletId != user.walletId) { | ||||||||||||||||||||||||
| clearOneShotSyncParamsForWallet(_lastWalletId!); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| _lastWalletId = user.walletId; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
192
to
+211
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify auth state stream behavior and consider initialization. The auth state listener correctly handles sign-out and wallet switching, but there are two potential edge cases:
Consider either:
Run the following script to check how authStateChanges is wired in the bootstrap: 🏁 Script executed: #!/bin/bash
# Check how authStateChanges stream is provided to ActivationConfigService
rg -A 5 -B 5 'ActivationConfigService\(' --type=dartLength of output: 2378 Length of output: 2265 🏁 Script executed: #!/bin/bash
# Search for authStateChanges stream definition/initialization
rg -n 'authStateChanges' --type=dart -B 2 -A 2Length of output: 17571 Length of output: 582 🏁 Script executed: #!/bin/bash
# Check full constructor and initialization logic
sed -n '192,220p' packages/komodo_defi_sdk/lib/src/activation_config/activation_config_service.dartLength of output: 1091 Length of output: 0 🏁 Script executed: #!/bin/bash
# Search for dispose method in ActivationConfigService
sed -n '301,310p' packages/komodo_defi_sdk/lib/src/activation_config/activation_config_service.dartLength of output: 214 Initialize The auth state stream ( Fix: Initialize ActivationConfigService(
this.repo, {
required WalletIdResolver walletIdResolver,
Stream<KdfUser?>? authStateChanges,
}) : _walletIdResolver = walletIdResolver {
// Initialize current wallet ID
walletIdResolver().then((walletId) {
_lastWalletId = walletId;
});
// Listen to auth state changes...
_authStateSubscription = authStateChanges?.listen((user) { ... });
}Additionally, 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| final ActivationConfigRepository repo; | ||||||||||||||||||||||||
| final WalletIdResolver _walletIdResolver; | ||||||||||||||||||||||||
| StreamSubscription<KdfUser?>? _authStateSubscription; | ||||||||||||||||||||||||
| WalletId? _lastWalletId; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // One-shot sync params coordinator. Not persisted; cleared after use. | ||||||||||||||||||||||||
| final Map<_WalletAssetKey, ZhtlcSyncParams?> _oneShotSyncParams = {}; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Future<WalletId> _requireActiveWallet() async { | ||||||||||||||||||||||||
| final walletId = await _walletIdResolver(); | ||||||||||||||||||||||||
|
|
@@ -234,6 +258,11 @@ class ActivationConfigService { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Future<void> saveZhtlcConfig(AssetId id, ZhtlcUserConfig config) async { | ||||||||||||||||||||||||
| final walletId = await _requireActiveWallet(); | ||||||||||||||||||||||||
| // If legacy callers provide syncParams in the config, convert it to | ||||||||||||||||||||||||
| // a one-shot sync override and do not persist it. | ||||||||||||||||||||||||
| if (config.syncParams != null) { | ||||||||||||||||||||||||
| _oneShotSyncParams[_WalletAssetKey(walletId, id)] = config.syncParams; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| await repo.saveConfig(walletId, id, config); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -243,6 +272,37 @@ class ActivationConfigService { | |||||||||||||||||||||||
| _awaitingControllers[_WalletAssetKey(walletId, id)]?.complete(config); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Sets a one-shot sync params value for the next activation of [id]. | ||||||||||||||||||||||||
| /// This is not persisted and will be consumed and cleared on activation. | ||||||||||||||||||||||||
| Future<void> setOneShotSyncParams( | ||||||||||||||||||||||||
| AssetId id, | ||||||||||||||||||||||||
| ZhtlcSyncParams? syncParams, | ||||||||||||||||||||||||
| ) async { | ||||||||||||||||||||||||
| final walletId = await _requireActiveWallet(); | ||||||||||||||||||||||||
| _oneShotSyncParams[_WalletAssetKey(walletId, id)] = syncParams; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Returns and clears any pending one-shot sync params for [id]. | ||||||||||||||||||||||||
| Future<ZhtlcSyncParams?> takeOneShotSyncParams(AssetId id) async { | ||||||||||||||||||||||||
| final walletId = await _requireActiveWallet(); | ||||||||||||||||||||||||
| final key = _WalletAssetKey(walletId, id); | ||||||||||||||||||||||||
| final value = _oneShotSyncParams.remove(key); | ||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Clears all one-shot sync params for the specified wallet. | ||||||||||||||||||||||||
| /// This should be called when a user signs out to prevent stale one-shot | ||||||||||||||||||||||||
| /// params from being applied on the next activation after re-login. | ||||||||||||||||||||||||
| void clearOneShotSyncParamsForWallet(WalletId walletId) { | ||||||||||||||||||||||||
| _oneShotSyncParams.removeWhere((key, _) => key.walletId == walletId); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Disposes of the service and cleans up resources. | ||||||||||||||||||||||||
| void dispose() { | ||||||||||||||||||||||||
| _authStateSubscription?.cancel(); | ||||||||||||||||||||||||
| _authStateSubscription = null; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+300
to
+304
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Complete the cleanup by clearing one-shot params. The dispose method cancels the auth state subscription but doesn't clear the Apply this diff: /// Disposes of the service and cleans up resources.
void dispose() {
_authStateSubscription?.cancel();
_authStateSubscription = null;
+ _oneShotSyncParams.clear();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| final Map<_WalletAssetKey, Completer<ZhtlcUserConfig?>> _awaitingControllers = | ||||||||||||||||||||||||
| {}; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -408,6 +408,9 @@ class KomodoDefiSdk with SecureRpcPasswordMixin { | |||||
| _disposeIfRegistered<KomodoDefiLocalAuth>((m) => m.dispose()), | ||||||
| _disposeIfRegistered<AssetManager>((m) => m.dispose()), | ||||||
| _disposeIfRegistered<ActivationManager>((m) => m.dispose()), | ||||||
| _disposeIfRegistered<ActivationConfigService>( | ||||||
| (m) async => m.dispose(), | ||||||
|
||||||
| (m) async => m.dispose(), | |
| (m) => m.dispose(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The
syncParamsvariable may be null ifsyncTypeis 'earliest', butZhtlcConfigDialogResultaccepts nullableoneShotSync. Consider adding a comment explaining thatsyncParamswill be null when 'earliest' is selected, as this is intentional behavior for that sync type.