Skip to content

Commit fcb94b9

Browse files
committed
Fix VssStoreIdProvider cache to be per walletIndex
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.
1 parent 9d6cbd0 commit fcb94b9

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/src/main/java/to/bitkit/data/backup/VssStoreIdProvider.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class VssStoreIdProvider @Inject constructor(
1313
private val keychain: Keychain,
1414
) {
1515
@Volatile
16-
private var cachedStoreId: String? = null
16+
private var cachedStoreIds: MutableMap<Int, String> = mutableMapOf()
1717

18-
fun getVssStoreId(): String {
19-
cachedStoreId?.let { return it }
18+
fun getVssStoreId(walletIndex: Int = 0): String {
19+
cachedStoreIds[walletIndex]?.let { return it }
2020

2121
return synchronized(this) {
22-
cachedStoreId?.let { return it }
22+
cachedStoreIds[walletIndex]?.let { return it }
2323

2424
val mnemonic = keychain.loadString(Keychain.Key.BIP39_MNEMONIC.name) ?: throw ServiceError.MnemonicNotFound
2525
val passphrase = keychain.loadString(Keychain.Key.BIP39_PASSPHRASE.name)
@@ -30,12 +30,24 @@ class VssStoreIdProvider @Inject constructor(
3030
passphrase = passphrase,
3131
)
3232

33-
Logger.info("VSS store id: '$storeId'", context = TAG)
34-
cachedStoreId = storeId
33+
Logger.info("VSS store id: '$storeId' for walletIndex: $walletIndex", context = TAG)
34+
cachedStoreIds[walletIndex] = storeId
3535
storeId
3636
}
3737
}
3838

39+
fun clearCache() {
40+
synchronized(this) {
41+
cachedStoreIds.clear()
42+
}
43+
}
44+
45+
fun clearCache(walletIndex: Int) {
46+
synchronized(this) {
47+
cachedStoreIds.remove(walletIndex)
48+
}
49+
}
50+
3951
companion object {
4052
private const val TAG = "VssStoreIdProvider"
4153
}

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class LightningService @Inject constructor(
104104

105105
Logger.debug("Building node…")
106106

107-
val vssStoreId = vssStoreIdProvider.getVssStoreId()
107+
val vssStoreId = vssStoreIdProvider.getVssStoreId(walletIndex)
108108

109109
ServiceQueue.LDK.background {
110110
node = try {

0 commit comments

Comments
 (0)