From 8739fc87951bc941a70f97447481af43d8ee096b Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 17 Jan 2024 14:55:01 +0200 Subject: [PATCH] fix: ios and android catch channel write fails --- example/ios/Podfile.lock | 6 +++--- .../main/java/com/reactnativeldk/classes/LdkPersister.kt | 8 +++++++- lib/ios/Classes/LdkPersist.swift | 8 +++++++- lib/package.json | 2 +- lib/src/lightning-manager.ts | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 67748d92..524f4c6d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -375,7 +375,7 @@ PODS: - React-jsinspector (0.72.4) - React-logger (0.72.4): - glog - - react-native-ldk (0.0.124): + - react-native-ldk (0.0.125): - React - react-native-randombytes (3.6.1): - React-Core @@ -723,7 +723,7 @@ SPEC CHECKSUMS: React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594 React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77 - react-native-ldk: 5ac636bea5e24c687a4a009a339d5ee82e8c8d0f + react-native-ldk: c78b18c8c8fe218481721f7083e3e0f825aa957e react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846 react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989 React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f @@ -753,4 +753,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 940323d07de591a59a2ab39fc0ef7b7d6dc89c0d -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 diff --git a/lib/android/src/main/java/com/reactnativeldk/classes/LdkPersister.kt b/lib/android/src/main/java/com/reactnativeldk/classes/LdkPersister.kt index f62b4540..3be7bf54 100644 --- a/lib/android/src/main/java/com/reactnativeldk/classes/LdkPersister.kt +++ b/lib/android/src/main/java/com/reactnativeldk/classes/LdkPersister.kt @@ -25,7 +25,13 @@ class LdkPersister { val isNew = !file.exists() BackupClient.addToPersistQueue(BackupClient.Label.CHANNEL_MONITOR(channelId=channelId), data.write()) { - file.writeBytes(data.write()) + try { + file.writeBytes(data.write()) + } catch (e: Exception) { + //If this fails we can't do much but LDK will retry on startup + LdkEventEmitter.send(EventTypes.native_log, "Failed to locally persist channel (${id.to_channel_id().hexEncodedString()}) to disk") + return@addToPersistQueue + } //Update chainmonitor with successful persist val res = LdkModule.chainMonitor?.channel_monitor_updated(id, update_id) diff --git a/lib/ios/Classes/LdkPersist.swift b/lib/ios/Classes/LdkPersist.swift index 1ebb5e25..ee738bb9 100644 --- a/lib/ios/Classes/LdkPersist.swift +++ b/lib/ios/Classes/LdkPersist.swift @@ -25,7 +25,13 @@ class LdkPersister: Persist { BackupClient.addToPersistQueue(.channelMonitor(id: channelIdHex), data.write()) { //Callback for when the persist queue queue entry is processed - try! Data(data.write()).write(to: channelStoragePath) + do { + try Data(data.write()).write(to: channelStoragePath) + } catch { + //If this fails we can't do much but LDK will retry on startup + LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to Failed to locally persist channel (\(channelIdHex)). \(error.localizedDescription)") + return + } //Update chainmonitor with successful persist let res = Ldk.chainMonitor?.channelMonitorUpdated(fundingTxo: channelId, completedUpdateId: updateId) diff --git a/lib/package.json b/lib/package.json index 57cd0629..560f6a56 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,7 +1,7 @@ { "name": "@synonymdev/react-native-ldk", "title": "React Native LDK", - "version": "0.0.124", + "version": "0.0.126", "description": "React Native wrapper for LDK", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/lib/src/lightning-manager.ts b/lib/src/lightning-manager.ts index cbead8b1..a466f8a8 100644 --- a/lib/src/lightning-manager.ts +++ b/lib/src/lightning-manager.ts @@ -1962,7 +1962,7 @@ class LightningManager { if (supports_zero_conf) { if (isTrustedPeer) { await ldk.writeToLogFile( - 'error', + 'info', `Accepting zero conf channel from peer ${counterparty_node_id}`, );