Skip to content

Commit 59a652d

Browse files
committed
fix: use u32::MAX for network graph reset to avoid LDK early return
LDK's remove_stale_channels_and_tracking_with_time() returns immediately if current_time > u32::MAX. Passing u64::MAX meant the graph was never actually cleared. Use u32::MAX instead so all channels appear stale. Also includes Swift bindings for listClosedChannels and ClosedChannelDetails.
1 parent d9d34a6 commit 59a652d

File tree

2 files changed

+155
-2
lines changed

2 files changed

+155
-2
lines changed

bindings/swift/Sources/LDKNode/LDKNode.swift

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,8 @@ public protocol NodeProtocol : AnyObject {
27792779

27802780
func listChannels() -> [ChannelDetails]
27812781

2782+
func listClosedChannels() -> [ClosedChannelDetails]
2783+
27822784
func listPayments() -> [PaymentDetails]
27832785

27842786
func listPeers() -> [PeerDetails]
@@ -2977,6 +2979,13 @@ open func listChannels() -> [ChannelDetails] {
29772979
})
29782980
}
29792981

2982+
open func listClosedChannels() -> [ClosedChannelDetails] {
2983+
return try! FfiConverterSequenceTypeClosedChannelDetails.lift(try! rustCall() {
2984+
uniffi_ldk_node_fn_method_node_list_closed_channels(self.uniffiClonePointer(),$0
2985+
)
2986+
})
2987+
}
2988+
29802989
open func listPayments() -> [PaymentDetails] {
29812990
return try! FfiConverterSequenceTypePaymentDetails.lift(try! rustCall() {
29822991
uniffi_ldk_node_fn_method_node_list_payments(self.uniffiClonePointer(),$0
@@ -5371,6 +5380,120 @@ public func FfiConverterTypeChannelUpdateInfo_lower(_ value: ChannelUpdateInfo)
53715380
}
53725381

53735382

5383+
public struct ClosedChannelDetails {
5384+
public var channelId: ChannelId
5385+
public var userChannelId: UserChannelId
5386+
public var counterpartyNodeId: PublicKey?
5387+
public var fundingTxo: OutPoint?
5388+
public var channelCapacitySats: UInt64?
5389+
public var lastLocalBalanceMsat: UInt64?
5390+
public var closureReason: ClosureReason?
5391+
public var closedAtTimestamp: UInt64
5392+
5393+
// Default memberwise initializers are never public by default, so we
5394+
// declare one manually.
5395+
public init(channelId: ChannelId, userChannelId: UserChannelId, counterpartyNodeId: PublicKey?, fundingTxo: OutPoint?, channelCapacitySats: UInt64?, lastLocalBalanceMsat: UInt64?, closureReason: ClosureReason?, closedAtTimestamp: UInt64) {
5396+
self.channelId = channelId
5397+
self.userChannelId = userChannelId
5398+
self.counterpartyNodeId = counterpartyNodeId
5399+
self.fundingTxo = fundingTxo
5400+
self.channelCapacitySats = channelCapacitySats
5401+
self.lastLocalBalanceMsat = lastLocalBalanceMsat
5402+
self.closureReason = closureReason
5403+
self.closedAtTimestamp = closedAtTimestamp
5404+
}
5405+
}
5406+
5407+
5408+
5409+
extension ClosedChannelDetails: Equatable, Hashable {
5410+
public static func ==(lhs: ClosedChannelDetails, rhs: ClosedChannelDetails) -> Bool {
5411+
if lhs.channelId != rhs.channelId {
5412+
return false
5413+
}
5414+
if lhs.userChannelId != rhs.userChannelId {
5415+
return false
5416+
}
5417+
if lhs.counterpartyNodeId != rhs.counterpartyNodeId {
5418+
return false
5419+
}
5420+
if lhs.fundingTxo != rhs.fundingTxo {
5421+
return false
5422+
}
5423+
if lhs.channelCapacitySats != rhs.channelCapacitySats {
5424+
return false
5425+
}
5426+
if lhs.lastLocalBalanceMsat != rhs.lastLocalBalanceMsat {
5427+
return false
5428+
}
5429+
if lhs.closureReason != rhs.closureReason {
5430+
return false
5431+
}
5432+
if lhs.closedAtTimestamp != rhs.closedAtTimestamp {
5433+
return false
5434+
}
5435+
return true
5436+
}
5437+
5438+
public func hash(into hasher: inout Hasher) {
5439+
hasher.combine(channelId)
5440+
hasher.combine(userChannelId)
5441+
hasher.combine(counterpartyNodeId)
5442+
hasher.combine(fundingTxo)
5443+
hasher.combine(channelCapacitySats)
5444+
hasher.combine(lastLocalBalanceMsat)
5445+
hasher.combine(closureReason)
5446+
hasher.combine(closedAtTimestamp)
5447+
}
5448+
}
5449+
5450+
5451+
#if swift(>=5.8)
5452+
@_documentation(visibility: private)
5453+
#endif
5454+
public struct FfiConverterTypeClosedChannelDetails: FfiConverterRustBuffer {
5455+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ClosedChannelDetails {
5456+
return
5457+
try ClosedChannelDetails(
5458+
channelId: FfiConverterTypeChannelId.read(from: &buf),
5459+
userChannelId: FfiConverterTypeUserChannelId.read(from: &buf),
5460+
counterpartyNodeId: FfiConverterOptionTypePublicKey.read(from: &buf),
5461+
fundingTxo: FfiConverterOptionTypeOutPoint.read(from: &buf),
5462+
channelCapacitySats: FfiConverterOptionUInt64.read(from: &buf),
5463+
lastLocalBalanceMsat: FfiConverterOptionUInt64.read(from: &buf),
5464+
closureReason: FfiConverterOptionTypeClosureReason.read(from: &buf),
5465+
closedAtTimestamp: FfiConverterUInt64.read(from: &buf)
5466+
)
5467+
}
5468+
5469+
public static func write(_ value: ClosedChannelDetails, into buf: inout [UInt8]) {
5470+
FfiConverterTypeChannelId.write(value.channelId, into: &buf)
5471+
FfiConverterTypeUserChannelId.write(value.userChannelId, into: &buf)
5472+
FfiConverterOptionTypePublicKey.write(value.counterpartyNodeId, into: &buf)
5473+
FfiConverterOptionTypeOutPoint.write(value.fundingTxo, into: &buf)
5474+
FfiConverterOptionUInt64.write(value.channelCapacitySats, into: &buf)
5475+
FfiConverterOptionUInt64.write(value.lastLocalBalanceMsat, into: &buf)
5476+
FfiConverterOptionTypeClosureReason.write(value.closureReason, into: &buf)
5477+
FfiConverterUInt64.write(value.closedAtTimestamp, into: &buf)
5478+
}
5479+
}
5480+
5481+
5482+
#if swift(>=5.8)
5483+
@_documentation(visibility: private)
5484+
#endif
5485+
public func FfiConverterTypeClosedChannelDetails_lift(_ buf: RustBuffer) throws -> ClosedChannelDetails {
5486+
return try FfiConverterTypeClosedChannelDetails.lift(buf)
5487+
}
5488+
5489+
#if swift(>=5.8)
5490+
@_documentation(visibility: private)
5491+
#endif
5492+
public func FfiConverterTypeClosedChannelDetails_lower(_ value: ClosedChannelDetails) -> RustBuffer {
5493+
return FfiConverterTypeClosedChannelDetails.lower(value)
5494+
}
5495+
5496+
53745497
public struct Config {
53755498
public var storageDirPath: String
53765499
public var network: Network
@@ -11276,6 +11399,31 @@ fileprivate struct FfiConverterSequenceTypeChannelDetails: FfiConverterRustBuffe
1127611399
}
1127711400
}
1127811401

11402+
#if swift(>=5.8)
11403+
@_documentation(visibility: private)
11404+
#endif
11405+
fileprivate struct FfiConverterSequenceTypeClosedChannelDetails: FfiConverterRustBuffer {
11406+
typealias SwiftType = [ClosedChannelDetails]
11407+
11408+
public static func write(_ value: [ClosedChannelDetails], into buf: inout [UInt8]) {
11409+
let len = Int32(value.count)
11410+
writeInt(&buf, len)
11411+
for item in value {
11412+
FfiConverterTypeClosedChannelDetails.write(item, into: &buf)
11413+
}
11414+
}
11415+
11416+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [ClosedChannelDetails] {
11417+
let len: Int32 = try readInt(&buf)
11418+
var seq = [ClosedChannelDetails]()
11419+
seq.reserveCapacity(Int(len))
11420+
for _ in 0 ..< len {
11421+
seq.append(try FfiConverterTypeClosedChannelDetails.read(from: &buf))
11422+
}
11423+
return seq
11424+
}
11425+
}
11426+
1127911427
#if swift(>=5.8)
1128011428
@_documentation(visibility: private)
1128111429
#endif
@@ -12936,6 +13084,9 @@ private var initializationResult: InitializationResult = {
1293613084
if (uniffi_ldk_node_checksum_method_node_list_channels() != 7954) {
1293713085
return InitializationResult.apiChecksumMismatch
1293813086
}
13087+
if (uniffi_ldk_node_checksum_method_node_list_closed_channels() != 18081) {
13088+
return InitializationResult.apiChecksumMismatch
13089+
}
1293913090
if (uniffi_ldk_node_checksum_method_node_list_payments() != 35002) {
1294013091
return InitializationResult.apiChecksumMismatch
1294113092
}

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,8 +1784,10 @@ impl Node {
17841784
})?;
17851785
}
17861786

1787-
// Clear the in-memory graph by marking all channels as stale
1788-
self.network_graph.remove_stale_channels_and_tracking_with_time(u64::MAX);
1787+
// Clear the in-memory graph by marking all channels as stale.
1788+
// Note: LDK's implementation returns early if current_time > u32::MAX,
1789+
// so we pass u32::MAX to ensure all channels appear stale and get removed.
1790+
self.network_graph.remove_stale_channels_and_tracking_with_time(u32::MAX as u64);
17891791

17901792
Ok(())
17911793
}

0 commit comments

Comments
 (0)