Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit 2774fe8

Browse files
committed
featL android remote persist with auto retry
1 parent fd6b659 commit 2774fe8

5 files changed

Lines changed: 34 additions & 5 deletions

File tree

lib/android/src/main/java/com/reactnativeldk/classes/BackupClient.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,36 @@ class BackupClient {
174174
}
175175
}
176176

177+
@Throws(BackupError::class)
178+
fun persist(label: Label, bytes: ByteArray, retry: Int) {
179+
var attempts = 0
180+
var persistError: Exception? = null
181+
182+
while (attempts < retry) {
183+
try {
184+
persist(label, bytes)
185+
186+
LdkEventEmitter.send(
187+
EventTypes.native_log,
188+
"Remote persist success for ${label.string} after ${attempts+1} attempts"
189+
)
190+
return
191+
} catch (error: Exception) {
192+
persistError = error
193+
attempts += 1
194+
LdkEventEmitter.send(
195+
EventTypes.native_log,
196+
"Remote persist failed for ${label.string} ($attempts attempts)"
197+
)
198+
Thread.sleep(attempts.toLong()) // Ease off with each attempt
199+
}
200+
}
201+
202+
if (persistError != null) {
203+
throw persistError
204+
}
205+
}
206+
177207
@Throws(BackupError::class)
178208
fun persist(label: Label, bytes: ByteArray) {
179209
if (skipRemoteBackup) {

lib/android/src/main/java/com/reactnativeldk/classes/LdkChannelManagerPersister.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ class LdkChannelManagerPersister: ChannelManagerConstructor.EventHandler {
173173

174174
override fun persist_manager(channel_manager_bytes: ByteArray?) {
175175
if (channel_manager_bytes != null && LdkModule.accountStoragePath != "") {
176+
BackupClient.persist(BackupClient.Label.CHANNEL_MANAGER(), channel_manager_bytes, retry = 100)
176177
File(LdkModule.accountStoragePath + "/" + LdkFileNames.channel_manager.fileName).writeBytes(channel_manager_bytes)
177178

178-
BackupClient.persist(BackupClient.Label.CHANNEL_MANAGER(), channel_manager_bytes)
179-
180179
LdkEventEmitter.send(EventTypes.native_log, "Persisted channel manager to disk")
181180
LdkEventEmitter.send(EventTypes.backup, "")
182181
}

lib/android/src/main/java/com/reactnativeldk/classes/LdkPersister.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class LdkPersister {
2424

2525
val isNew = !file.exists()
2626

27+
BackupClient.persist(BackupClient.Label.CHANNEL_MONITOR(channelId=channelId), data.write(), retry = 100)
2728
file.writeBytes(data.write())
28-
BackupClient.persist(BackupClient.Label.CHANNEL_MONITOR(channelId=channelId), data.write())
2929

3030
LdkEventEmitter.send(EventTypes.native_log, "Persisted channel (${id.to_channel_id().hexEncodedString()}) to disk")
3131
LdkEventEmitter.send(EventTypes.backup, "")

lib/ios/Classes/LdkChannelManagerPersister.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
267267
}
268268

269269
do {
270-
try BackupClient.persist(.channelManager, channelManager.write(), retry: 10)
270+
try BackupClient.persist(.channelManager, channelManager.write(), retry: 100)
271271

272272
try Data(channelManager.write()).write(to: managerStorage)
273273
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Persisted channel manager to disk")

lib/ios/Classes/LdkPersist.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LdkPersister: Persist {
2323

2424
let isNew = !FileManager().fileExists(atPath: channelStoragePath.path)
2525

26-
try BackupClient.persist(.channelMonitor(id: channelId), data.write(), retry: 10)
26+
try BackupClient.persist(.channelMonitor(id: channelId), data.write(), retry: 100)
2727
try Data(data.write()).write(to: channelStoragePath)
2828

2929
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Persisted channel (\(channelId)) to disk")

0 commit comments

Comments
 (0)