Skip to content

Commit dff9d6c

Browse files
committed
Reënable bindings diff detection, and fix duplicate channel monitor detection.
1 parent bc3fc27 commit dff9d6c

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

.github/workflows/swift.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
echo "rust-lightning commit hash:"
2525
git rev-parse HEAD
2626
cd ..
27-
git clone --branch https://github.com/lightningdevkit/ldk-c-bindings
27+
git clone --branch v0.0.108.0 https://github.com/lightningdevkit/ldk-c-bindings
2828
# git clone https://github.com/TheBlueMatt/ldk-c-bindings
2929
cd ldk-c-bindings
3030
echo "ldk-c-bindings commit hash:"
@@ -63,11 +63,10 @@ jobs:
6363
env:
6464
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
6565
LDK_SWIFT_GENERATOR_OUTPUT_DIRECTORY_PATH: ci/LDKSwift/Sources/LDKSwift/bindings
66-
- name: (Suspended) Check that the latest auto-generated Swift files are in the repo
66+
- name: Check that the latest auto-generated Swift files are in the repo
6767
run: |
6868
python ./ # Generate bindings into local directory
69-
# python ci/walker.py bindings/LDK
70-
# git diff --exit-code bindings/LDK ':(exclude)bindings/LDK/Bindings.swift'
69+
git diff --exit-code ci/LDKSwift/Sources/LDKSwift ':(exclude)ci/LDKSwift/Sources/LDKSwift/bindings/Bindings.swift'
7170
env:
7271
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
7372
- name: Install Swift Toolchain

ci/LDKSwift/Sources/LDKSwift/batteries/ChannelManagerConstructor.swift

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,39 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
5454
private let chain_monitor: ChainMonitor
5555

5656

57-
public init(channel_manager_serialized: [UInt8], channel_monitors_serialized: [[UInt8]], keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, filter: Filter?, net_graph_serialized: [UInt8]?, tx_broadcaster: BroadcasterInterface, logger: Logger) throws {
57+
public init(channel_manager_serialized: [UInt8], channel_monitors_serialized: [[UInt8]], keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, filter: Filter?, net_graph_serialized: [UInt8]?, tx_broadcaster: BroadcasterInterface, logger: Logger, enableP2PGossip: Bool = false) throws {
5858

5959
var monitors: [LDKChannelMonitor] = []
6060
self.channel_monitors = []
6161

62-
var monitorFundingSet = Set<[UInt8]>()
62+
var monitorFundingSet = Set<String>()
6363

6464
for currentSerializedChannelMonitor in channel_monitors_serialized {
6565
let channelMonitorResult: Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ = UtilMethods.constructor_BlockHashChannelMonitorZ_read(ser: currentSerializedChannelMonitor, arg: keys_interface)
6666
if channelMonitorResult.cOpaqueStruct?.result_ok != true {
6767
throw InvalidSerializedDataError.invalidSerializedChannelMonitor
6868
}
69-
// res
7069

7170
let value: LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZPtr = channelMonitorResult.cOpaqueStruct!.contents
7271
let a: LDKThirtyTwoBytes = value.result!.pointee.a
7372
let b: LDKChannelMonitor = value.result!.pointee.b
7473

75-
let nativeA = Bindings.LDKThirtyTwoBytes_to_array(nativeType: a);
76-
if monitorFundingSet.contains(nativeA) {
77-
throw InvalidSerializedDataError.duplicateSerializedChannelMonitor
78-
}
79-
monitorFundingSet.insert(nativeA)
80-
74+
let blockHash = Bindings.LDKThirtyTwoBytes_to_array(nativeType: a);
8175
let clonedChannelMonitor = ChannelMonitor(pointer: b).dangle().clone()
82-
// var clonedChannelMonitor = currentChannelMonitor.clone(orig: currentChannelMonitor)
76+
77+
if let channelFundingOutpoint = clonedChannelMonitor.get_funding_txo().getA() {
78+
let fundingOutpointHash = "\(channelFundingOutpoint.get_txid()):\(channelFundingOutpoint.get_index())"
79+
if monitorFundingSet.contains(fundingOutpointHash) {
80+
Bindings.print("Duplicate channel monitor funding txo: \(fundingOutpointHash)", severity: .ERROR)
81+
throw InvalidSerializedDataError.duplicateSerializedChannelMonitor
82+
}
83+
monitorFundingSet.insert(fundingOutpointHash)
84+
}
85+
8386
clonedChannelMonitor.cOpaqueStruct?.is_owned = false // is_owned should never have to be modified
8487

8588
monitors.append(clonedChannelMonitor.cOpaqueStruct!)
86-
self.channel_monitors.append((clonedChannelMonitor, nativeA))
89+
self.channel_monitors.append((clonedChannelMonitor, blockHash))
8790
}
8891

8992
print("Collected channel monitors, reading channel manager")
@@ -119,13 +122,11 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
119122

120123
let noCustomMessages = IgnoringMessageHandler()
121124
var messageHandler: MessageHandler!
122-
if let netGraph = net_graph {
123-
// TODO: fix
124-
// self.graph_msg_handler = NetGraphMsgHandler(network_graph: netGraph, chain_access: Option_AccessZ.none(), logger: logger)
125-
126-
// messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: self.graph_msg_handler!.as_RoutingMessageHandler())
127-
// temporarily disable handling routing messages by the peer manager to avoid excessive memory growth
128-
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: noCustomMessages.as_RoutingMessageHandler())
125+
if let netGraph = net_graph, enableP2PGossip {
126+
let noneOption = Option_AccessZ.none()
127+
let p2pGossipSync = P2PGossipSync(network_graph: netGraph, chain_access: Option_AccessZ.none(), logger: logger)
128+
self.graph_msg_handler = GossipSync.p2_p(a: p2pGossipSync)
129+
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: p2pGossipSync.as_RoutingMessageHandler())
129130
} else {
130131
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: noCustomMessages.as_RoutingMessageHandler())
131132
}
@@ -151,7 +152,7 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
151152
/**
152153
* Constructs a channel manager from the given interface implementations
153154
*/
154-
public init(network: LDKNetwork, config: UserConfig, current_blockchain_tip_hash: [UInt8], current_blockchain_tip_height: UInt32, keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, net_graph: NetworkGraph?, tx_broadcaster: BroadcasterInterface, logger: Logger) {
155+
public init(network: LDKNetwork, config: UserConfig, current_blockchain_tip_hash: [UInt8], current_blockchain_tip_height: UInt32, keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, net_graph: NetworkGraph?, tx_broadcaster: BroadcasterInterface, logger: Logger, enableP2PGossip: Bool = false) {
155156

156157
self.channel_monitors = []
157158
self.channel_manager_latest_block_hash = nil
@@ -167,16 +168,11 @@ public class ChannelManagerConstructor: NativeTypeWrapper {
167168
self.net_graph = net_graph
168169
let noCustomMessages = IgnoringMessageHandler()
169170
var messageHandler: MessageHandler!
170-
if let netGraph = net_graph {
171+
if let netGraph = net_graph, enableP2PGossip {
171172
let noneOption = Option_AccessZ.none()
172-
173-
// TODO: fix
174-
// self.graph_msg_handler = NetGraphMsgHandler(network_graph: netGraph, chain_access: noneOption, logger: logger)
175-
176-
177-
// messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: self.graph_msg_handler!.as_RoutingMessageHandler())
178-
// temporarily disable handling routing messages by the peer manager to avoid excessive memory growth
179-
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: noCustomMessages.as_RoutingMessageHandler())
173+
let p2pGossipSync = P2PGossipSync(network_graph: netGraph, chain_access: Option_AccessZ.none(), logger: logger)
174+
self.graph_msg_handler = GossipSync.p2_p(a: p2pGossipSync)
175+
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: p2pGossipSync.as_RoutingMessageHandler())
180176
} else {
181177
messageHandler = MessageHandler(chan_handler_arg: channelManager.as_ChannelMessageHandler(), route_handler_arg: noCustomMessages.as_RoutingMessageHandler())
182178
}

0 commit comments

Comments
 (0)