Skip to content

Commit a5b2692

Browse files
authored
Merge pull request #187 from synonymdev/rgs-fixes
fix: check rgs updates every hour
2 parents 5c1cf14 + 3ca9f2f commit a5b2692

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

lib/android/src/main/java/com/reactnativeldk/Helpers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fun RapidGossipSync.downloadAndUpdateGraph(downloadUrl: String, tempStoragePath:
235235
return@downloadFile
236236
}
237237

238-
val res = update_network_graph_no_std(File(destinationFile).readBytes(), Option_u64Z.some((System.currentTimeMillis() / 1000)))
238+
val res = update_network_graph(File(destinationFile).readBytes())
239239
if (!res.is_ok()) {
240240
val error = res as? Result_u32GraphSyncErrorZ.Result_u32GraphSyncErrorZ_Err
241241

lib/android/src/main/java/com/reactnativeldk/LdkModule.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
291291

292292
//If it's been more than 24 hours then we need to update RGS
293293
val timestamp = if (networkGraph!!._last_rapid_gossip_sync_timestamp is Option_u32Z.Some) (networkGraph!!._last_rapid_gossip_sync_timestamp as Option_u32Z.Some).some.toLong() else 0 // (networkGraph!!._last_rapid_gossip_sync_timestamp as Option_u32Z.Some).some
294-
val hoursDiffSinceLastRGS = (System.currentTimeMillis() / 1000 - timestamp) / 60 / 60
295-
if (hoursDiffSinceLastRGS < 24) {
296-
LdkEventEmitter.send(EventTypes.native_log, "Skipping rapid gossip sync. Last updated $hoursDiffSinceLastRGS hours ago.")
294+
val minutesDiffSinceLastRGS = (System.currentTimeMillis() / 1000 - timestamp) / 60
295+
if (minutesDiffSinceLastRGS < 60) {
296+
LdkEventEmitter.send(EventTypes.native_log, "Skipping rapid gossip sync. Last updated ${minutesDiffSinceLastRGS/60} hours ago.")
297297
return handleResolve(promise, LdkCallbackResponses.network_graph_init_success)
298298
}
299299

300-
LdkEventEmitter.send(EventTypes.native_log, "Rapid gossip sync applying update. Last updated $hoursDiffSinceLastRGS hours ago.")
300+
LdkEventEmitter.send(EventTypes.native_log, "Rapid gossip sync applying update. Last updated ${minutesDiffSinceLastRGS/60} hours ago.")
301301

302302
rapidGossipSync!!.downloadAndUpdateGraph(rapidGossipSyncUrl, "$accountStoragePath/rapid_gossip_sync/", timestamp) { error ->
303303
if (error != null) {
@@ -1091,7 +1091,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
10911091
logDump.add("Claimable balances unavailable. Chain monitor not set yet")
10921092
}
10931093

1094-
networkGraph?._last_rapid_gossip_sync_timestamp?.let { res ->
1094+
channelManagerConstructor?.net_graph?._last_rapid_gossip_sync_timestamp?.let { res ->
10951095
val syncTimestamp = if (res is Option_u32Z.Some) (res as Option_u32Z.Some).some.toLong() else 0
10961096
if (syncTimestamp == 0L) {
10971097
logDump.add("Last rapid gossip sync time: NEVER")

lib/ios/Helpers.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ extension RouteHintHop {
112112
//Our own channels
113113
extension ChannelDetails {
114114
var asJson: [String: Any] {
115+
let shortChannelId = getShortChannelId() != nil ? String(getShortChannelId()!) : ""
116+
115117
return [
116118
"channel_id": Data(getChannelId() ?? []).hexEncodedString(),
117119
"is_public": getIsPublic(),
@@ -124,9 +126,9 @@ extension ChannelDetails {
124126
"channel_type": Data(getChannelType()?.write() ?? []).hexEncodedString(),
125127
"user_channel_id": Data(getUserChannelId()).hexEncodedString(), //String
126128
"confirmations_required": getConfirmationsRequired() as Any, // Optional number
127-
"short_channel_id": getShortChannelId() != nil ? String(getShortChannelId()!) : "", //String
128-
"inbound_scid_alias": getInboundScidAlias() != nil ? String(getInboundScidAlias()!) : "", //String
129-
"inbound_payment_scid": getInboundPaymentScid() != nil ? String(getInboundPaymentScid()!) : "", //String
129+
"short_channel_id": shortChannelId,
130+
"inbound_scid_alias": getInboundScidAlias() != nil ? String(getInboundScidAlias()!) : shortChannelId, //String
131+
"inbound_payment_scid": getInboundPaymentScid() as Any, //Optional number,
130132
"inbound_capacity_sat": getInboundCapacityMsat() / 1000,
131133
"outbound_capacity_sat": getOutboundCapacityMsat() / 1000,
132134
"channel_value_satoshis": getChannelValueSatoshis(),
@@ -279,7 +281,7 @@ extension RapidGossipSync {
279281

280282
guard let self = self else { return }
281283

282-
let res = self.updateNetworkGraphNoStd(updateData: [UInt8](try! Data(contentsOf: destinationFile)), currentTimeUnix: UInt64(Date().timeIntervalSince1970))
284+
let res = self.updateNetworkGraph(updateData: [UInt8](try! Data(contentsOf: destinationFile)))
283285
guard res.isOk() else {
284286
var errorMessage = "Failed to update network graph."
285287
switch res.getError()?.getValueType() {

lib/ios/Ldk.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ class Ldk: NSObject {
272272

273273
//If it's been more than 24 hours then we need to update RGS
274274
let timestamp = networkGraph?.getLastRapidGossipSyncTimestamp() ?? 0
275-
let hoursDiffSinceLastRGS = (Calendar.current.dateComponents([.hour], from: Date.init(timeIntervalSince1970: TimeInterval(timestamp)), to: Date()).hour)!
275+
let minutesDiffSinceLastRGS = (Calendar.current.dateComponents([.minute], from: Date.init(timeIntervalSince1970: TimeInterval(timestamp)), to: Date()).minute)!
276276

277-
guard hoursDiffSinceLastRGS > 24 else {
278-
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Skipping rapid gossip sync. Last updated \(hoursDiffSinceLastRGS) hours ago.")
277+
guard minutesDiffSinceLastRGS > 60 else {
278+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Skipping rapid gossip sync. Last updated \(minutesDiffSinceLastRGS/60) hours ago.")
279279
return handleResolve(resolve, .network_graph_init_success)
280280
}
281281

282-
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Rapid gossip sync applying update. Last updated \(hoursDiffSinceLastRGS) hours ago.")
282+
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Rapid gossip sync applying update. Last updated \(minutesDiffSinceLastRGS/60) hours ago.")
283283

284284
rapidGossipSync!.downloadAndUpdateGraph(downloadUrl: String(rapidGossipSyncUrl), tempStoragePath: rapidGossipSyncStoragePath, timestamp: timestamp) { [weak self] error in
285285
guard let self = self else { return }
@@ -1176,7 +1176,7 @@ class Ldk: NSObject {
11761176
logDump.append("Claimable balances unavailable. Chain monitor not set yet")
11771177
}
11781178

1179-
if let syncTimestamp = networkGraph?.getLastRapidGossipSyncTimestamp() {
1179+
if let syncTimestamp = channelManagerConstructor?.netGraph?.getLastRapidGossipSyncTimestamp() {
11801180
let date = Date(timeIntervalSince1970: TimeInterval(syncTimestamp))
11811181

11821182
let dateFormatter = DateFormatter()

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@synonymdev/react-native-ldk",
33
"title": "React Native LDK",
4-
"version": "0.0.118",
4+
"version": "0.0.119",
55
"description": "React Native wrapper for LDK",
66
"main": "./dist/index.js",
77
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)