Skip to content

Conversation

@ovitrif
Copy link
Collaborator

@ovitrif ovitrif commented Nov 4, 2025

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:

  • Replace single cachedStoreId with 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
  • Update VssBackupClient.setup() to accept walletIndex parameter (defaults to 0)
  • Clear cached vssStoreId on wipe

This PR matches the improvements from synonymdev/bitkit-ios#202, commit 91b47ba.

Preview

n/a - refactor.

QA Notes

  • regression Test wallet backup & restore.

@ovitrif ovitrif requested a review from Copilot November 4, 2025 20:28
@ovitrif ovitrif changed the title Add walletIndex to storeId caching logic refactor: add walletIndex to vss storeId caching logic Nov 4, 2025
@ovitrif ovitrif changed the title refactor: add walletIndex to vss storeId caching logic refactor: cache vss storeId by walletIndex Nov 4, 2025
@ovitrif ovitrif changed the title refactor: cache vss storeId by walletIndex refactor: cache VSS storeId by walletIndex Nov 4, 2025
Copy link
Contributor

Copilot AI left a 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 VssStoreIdProvider to accept a walletIndex parameter and cache store IDs per wallet index
  • Updated LightningService to pass the walletIndex when 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

claude and others added 3 commits November 4, 2025 22:42
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.
@ovitrif ovitrif force-pushed the claude/cache-storeid-walletindex-011CUoQoz6YfTo69Rn2ygUeQ branch from bb3863b to 0b3be33 Compare November 4, 2025 21:44
@ovitrif ovitrif marked this pull request as ready for review November 4, 2025 22:24
@ovitrif ovitrif self-assigned this Nov 4, 2025
@ovitrif ovitrif requested a review from jvsena42 November 4, 2025 22:27
@ovitrif ovitrif enabled auto-merge November 5, 2025 14:23
Copy link
Member

@jvsena42 jvsena42 left a 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

@ovitrif ovitrif merged commit 84af35c into master Nov 5, 2025
11 checks passed
@ovitrif ovitrif deleted the claude/cache-storeid-walletindex-011CUoQoz6YfTo69Rn2ygUeQ branch November 5, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants