Skip to content

Commit

Permalink
fix: ios and android catch channel write fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Jan 17, 2024
1 parent 2076a20 commit 8739fc8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -753,4 +753,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 940323d07de591a59a2ab39fc0ef7b7d6dc89c0d

COCOAPODS: 1.12.1
COCOAPODS: 1.14.3
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion lib/ios/Classes/LdkPersist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);

Expand Down

0 comments on commit 8739fc8

Please sign in to comment.