-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: cache VSS storeId by walletIndex #454
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
refactor: cache VSS storeId by walletIndex #454
Conversation
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.
Pull Request Overview
This PR adds multi-wallet support to the VSS store ID provider by introducing a walletIndex parameter. The changes enable the system to cache and retrieve separate VSS store IDs for different wallet indices.
- Modified
VssStoreIdProviderto accept awalletIndexparameter and cache store IDs per wallet index - Updated
LightningServiceto pass thewalletIndexwhen retrieving VSS store ID - Added cache management methods to clear cached store IDs
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/src/main/java/to/bitkit/data/backup/VssStoreIdProvider.kt | Refactored from single cached value to map-based caching with wallet index support, added cache clearing methods |
| app/src/main/java/to/bitkit/services/LightningService.kt | Updated to pass walletIndex parameter when retrieving VSS store ID |
This change ensures that VSS store ID derivation maintains separate caches for each wallet index, preventing collisions when managing multiple wallets within the same application instance. Changes: - Replace single cachedStoreId with cachedStoreIds map keyed by walletIndex - Update getVssStoreId() to accept walletIndex parameter (defaults to 0) - Add clearCache() method to clear all cached store IDs - Add clearCache(walletIndex) method to clear cache for specific wallet - Update LightningService to pass walletIndex when getting store ID - Enhance logging to include walletIndex This matches the improvements from bitkit-ios PR #202, commit 91b47ba.
Changes: - Remove @volatile annotation (redundant with synchronized blocks) - Change cachedStoreIds from var to val (map reference never changes) - Move cache check inside synchronized block for proper thread-safety - MutableMap operations must be synchronized; @volatile only affects reference visibility This ensures all map operations happen under synchronization, preventing potential race conditions when multiple threads access the cache.
bb3863b to
0b3be33
Compare
jvsena42
left a comment
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.
Tested wipe and restore wallet on emulator
Description
This PR ensures that VSS store ID derivation maintains separate caches for each wallet index, preventing collisions when managing multiple wallets within the same application instance.
Changes:
cachedStoreIdwith map keyed bywalletIndexgetVssStoreId()to acceptwalletIndexparameter (defaults to 0)clearCache()method to clear all cached store IDsclearCache(walletIndex)method to clear cache for specific walletLightningServiceto passwalletIndexwhen getting store IDwalletIndexVssBackupClient.setup()to acceptwalletIndexparameter (defaults to 0)vssStoreIdon wipeThis PR matches the improvements from synonymdev/bitkit-ios#202, commit 91b47ba.
Preview
n/a - refactor.
QA Notes
regressionTest wallet backup & restore.