@@ -48,44 +48,44 @@ const uint8_t valid_node_announcement[] = {
48
48
// A simple block containing only one transaction (which is the channel-open transaction for the
49
49
// channel we'll create). This was originally created by printing additional data in a simple
50
50
// rust-lightning unit test.
51
- const uint8_t channel_open_block[ ] = {
51
+ const uint8_t channel_open_header[ 80 ] = {
52
52
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
53
53
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
54
54
0x00 , 0x00 , 0x00 , 0x00 , 0xa2 , 0x47 , 0xd2 , 0xf8 , 0xd4 , 0xe0 , 0x6a , 0x3f , 0xf9 , 0x7a , 0x9a , 0x34 ,
55
55
0xbb , 0xa9 , 0x96 , 0xde , 0x63 , 0x84 , 0x5a , 0xce , 0xcf , 0x98 , 0xb8 , 0xbb , 0x75 , 0x4c , 0x4f , 0x7d ,
56
56
0xee , 0x4c , 0xa9 , 0x5f , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
57
- 0x01 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
57
+ };
58
+
59
+ const uint8_t channel_open_tx[] = {
60
+ 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
58
61
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
59
62
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
60
- 0x00 , 0x01 , 0x40 , 0x9c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x22 , 0x00 , 0x20 , 0x20 , 0x12 , 0x70 ,
61
- 0x44 , 0x41 , 0x40 , 0xaf , 0xc5 , 0x72 , 0x97 , 0xc8 , 0x69 , 0xba , 0x04 , 0xdb , 0x28 , 0x7b , 0xd7 , 0x32 ,
62
- 0x07 , 0x33 , 0x3a , 0x4a , 0xc2 , 0xc5 , 0x56 , 0x06 , 0x05 , 0x65 , 0xd7 , 0xa8 , 0xcf , 0x01 , 0x00 , 0x00 ,
63
- 0x00 , 0x00 , 0x00
63
+ 0x01 , 0x40 , 0x9c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x22 , 0x00 , 0x20 , 0x20 , 0x12 , 0x70 , 0x44 ,
64
+ 0x41 , 0x40 , 0xaf , 0xc5 , 0x72 , 0x97 , 0xc8 , 0x69 , 0xba , 0x04 , 0xdb , 0x28 , 0x7b , 0xd7 , 0x32 , 0x07 ,
65
+ 0x33 , 0x3a , 0x4a , 0xc2 , 0xc5 , 0x56 , 0x06 , 0x05 , 0x65 , 0xd7 , 0xa8 , 0xcf , 0x01 , 0x00 , 0x00 , 0x00 ,
66
+ 0x00 , 0x00
64
67
};
65
68
66
69
// The first transaction in the block is header (80 bytes) + transaction count (1 byte) into the block data.
67
- const uint8_t *channel_open_tx = channel_open_block + 81 ;
68
70
const uint8_t channel_open_txid[] = {
69
71
0x5f , 0xa9 , 0x4c , 0xee , 0x7d , 0x4f , 0x4c , 0x75 , 0xbb , 0xb8 , 0x98 , 0xcf , 0xce , 0x5a , 0x84 , 0x63 ,
70
72
0xde , 0x96 , 0xa9 , 0xbb , 0x34 , 0x9a , 0x7a , 0xf9 , 0x3f , 0x6a , 0xe0 , 0xd4 , 0xf8 , 0xd2 , 0x47 , 0xa2
71
73
};
72
74
73
75
// Two blocks built on top of channel_open_block:
74
- const uint8_t block_1[ ] = {
76
+ const uint8_t header_1[ 80 ] = {
75
77
0x01 , 0x00 , 0x00 , 0x00 , 0x65 , 0x8e , 0xf1 , 0x90 , 0x88 , 0xfa , 0x13 , 0x9c , 0x6a , 0xea , 0xf7 , 0xc1 ,
76
78
0x5a , 0xdd , 0x52 , 0x4d , 0x3c , 0x48 , 0x03 , 0xb3 , 0x9b , 0x25 , 0x4f , 0x02 , 0x79 , 0x05 , 0x90 , 0xe0 ,
77
79
0xc4 , 0x8d , 0xa0 , 0x62 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
78
80
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
79
81
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
80
- 0x00
81
82
};
82
- const uint8_t block_2[ ] = {
83
+ const uint8_t header_2[ 80 ] = {
83
84
0x01 , 0x00 , 0x00 , 0x00 , 0xf2 , 0x08 , 0x87 , 0x51 , 0xcb , 0xb1 , 0x1a , 0x51 , 0x76 , 0x01 , 0x6c , 0x5d ,
84
85
0x76 , 0x26 , 0x54 , 0x6f , 0xd9 , 0xbd , 0xa6 , 0xa5 , 0xe9 , 0x4b , 0x21 , 0x6e , 0xda , 0xa3 , 0x64 , 0x23 ,
85
86
0xcd , 0xf1 , 0xe2 , 0xe2 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
86
87
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
87
88
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
88
- 0x00
89
89
};
90
90
91
91
const LDKThirtyTwoBytes payment_preimage_1 = {
@@ -121,13 +121,15 @@ void broadcast_tx(const void *this_arg, LDKTransaction tx) {
121
121
struct NodeMonitors {
122
122
std::mutex mut;
123
123
std::vector<std::pair<LDK::OutPoint, LDK::ChannelMonitor>> mons;
124
- LDKChainWatchInterfaceUtil* watch_util;
125
124
LDKLogger* logger;
125
+
126
+ void ConnectBlock (const uint8_t (*header)[80], uint32_t height, LDKCVec_C2Tuple_usizeTransactionZZ tx_data, LDKBroadcasterInterface broadcast, LDKFeeEstimator fee_est) {
127
+ std::unique_lock<std::mutex> l (mut);
128
+ for (auto & mon : mons) {
129
+ LDK::CVec_C2Tuple_TxidCVec_TxOutZZZ res = ChannelMonitor_block_connected (&mon.second , &header_2, tx_data, height, broadcast, fee_est, *logger);
130
+ }
131
+ }
126
132
};
127
- void NodeMonitors_free (void *this_arg) {
128
- NodeMonitors* arg = (NodeMonitors*) this_arg;
129
- delete arg;
130
- }
131
133
132
134
LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor (const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitor monitor_arg) {
133
135
// First bind the args to C++ objects so they auto-free
@@ -137,19 +139,6 @@ LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg
137
139
NodeMonitors* arg = (NodeMonitors*) this_arg;
138
140
std::unique_lock<std::mutex> l (arg->mut );
139
141
140
- LDK::ChainWatchInterface watch = ChainWatchInterfaceUtil_as_ChainWatchInterface (arg->watch_util );
141
- LDK::C2Tuple_OutPointScriptZ funding_info = ChannelMonitor_get_funding_txo (&mon);
142
- LDKThirtyTwoBytes funding_txid;
143
- memcpy (funding_txid.data , OutPoint_get_txid (funding_info->a ), 32 );
144
- LDK::C2Tuple_Txidu32Z outpoint (C2Tuple_Txidu32Z_new (funding_txid, OutPoint_get_index (funding_info->a )));
145
- watch->install_watch_outpoint (watch->this_arg , outpoint, LDKu8slice {
146
- .data = funding_info->b ->data ,
147
- .datalen = funding_info->b ->datalen ,
148
- });
149
- watch->install_watch_tx (watch->this_arg , &funding_txid.data , LDKu8slice {
150
- .data = funding_info->b ->data ,
151
- .datalen = funding_info->b ->datalen ,
152
- });
153
142
arg->mons .push_back (std::make_pair (std::move (funding_txo), std::move (mon)));
154
143
return CResult_NoneChannelMonitorUpdateErrZ_ok ();
155
144
}
@@ -255,30 +244,27 @@ int main() {
255
244
.free = NULL ,
256
245
};
257
246
258
- LDK::ChainWatchInterfaceUtil chain1 = ChainWatchInterfaceUtil_new (network);
259
- LDK::BlockNotifier blocks1 = BlockNotifier_new (ChainWatchInterfaceUtil_as_ChainWatchInterface (&chain1));
260
-
261
- LDKManyChannelMonitor mon1 {
262
- .this_arg = new NodeMonitors { .watch_util = &chain1, .logger = &logger1 },
263
- .add_monitor = add_channel_monitor,
264
- .update_monitor = update_channel_monitor,
265
- .get_and_clear_pending_monitor_events = monitors_pending_monitor_events,
266
- .free = NodeMonitors_free,
247
+ NodeMonitors mons1;
248
+ mons1.logger = &logger1;
249
+ LDKWatch mon1 {
250
+ .this_arg = &mons1,
251
+ .watch_channel = add_channel_monitor,
252
+ .update_channel = update_channel_monitor,
253
+ .release_pending_monitor_events = monitors_pending_monitor_events,
254
+ .free = NULL ,
267
255
};
268
256
269
257
LDK::KeysManager keys1 = KeysManager_new (&node_seed, network, 0 , 0 );
270
258
LDK::KeysInterface keys_source1 = KeysManager_as_KeysInterface (&keys1);
271
259
LDKSecretKey node_secret1 = keys_source1->get_node_secret (keys_source1->this_arg );
272
260
273
261
LDK::UserConfig config1 = UserConfig_default ();
274
-
275
262
LDK::ChannelManager cm1 = ChannelManager_new (network, fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface (&keys1), config1, 0 );
276
- BlockNotifier_register_listener (&blocks1, ChannelManager_as_ChainListener (&cm1));
277
263
278
264
LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels (&cm1);
279
265
assert (channels->datalen == 0 );
280
266
281
- LDK::NetGraphMsgHandler net_graph1 = NetGraphMsgHandler_new (ChainWatchInterfaceUtil_as_ChainWatchInterface (&chain1) , logger1);
267
+ LDK::NetGraphMsgHandler net_graph1 = NetGraphMsgHandler_new (NULL , logger1);
282
268
283
269
LDK::MessageHandler msg_handler1 = MessageHandler_new (ChannelManager_as_ChannelMessageHandler (&cm1), NetGraphMsgHandler_as_RoutingMessageHandler (&net_graph1));
284
270
@@ -299,15 +285,14 @@ int main() {
299
285
.free = NULL ,
300
286
};
301
287
302
- LDK::ChainWatchInterfaceUtil chain2 = ChainWatchInterfaceUtil_new (network);
303
- LDK::BlockNotifier blocks2 = BlockNotifier_new (ChainWatchInterfaceUtil_as_ChainWatchInterface (&chain2));
304
-
305
- LDKManyChannelMonitor mon2 {
306
- .this_arg = new NodeMonitors { .watch_util = &chain2, .logger = &logger2 },
307
- .add_monitor = add_channel_monitor,
308
- .update_monitor = update_channel_monitor,
309
- .get_and_clear_pending_monitor_events = monitors_pending_monitor_events,
310
- .free = NodeMonitors_free,
288
+ NodeMonitors mons2;
289
+ mons2.logger = &logger2;
290
+ LDKWatch mon2 {
291
+ .this_arg = &mons2,
292
+ .watch_channel = add_channel_monitor,
293
+ .update_channel = update_channel_monitor,
294
+ .release_pending_monitor_events = monitors_pending_monitor_events,
295
+ .free = NULL ,
311
296
};
312
297
313
298
memset (&node_seed, 1 , 32 );
@@ -321,12 +306,11 @@ int main() {
321
306
UserConfig_set_own_channel_config (&config2, handshake_config2);
322
307
323
308
LDK::ChannelManager cm2 = ChannelManager_new (network, fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface (&keys2), config2, 0 );
324
- BlockNotifier_register_listener (&blocks2, ChannelManager_as_ChainListener (&cm2));
325
309
326
310
LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels (&cm2);
327
311
assert (channels2->datalen == 0 );
328
312
329
- LDK::NetGraphMsgHandler net_graph2 = NetGraphMsgHandler_new (ChainWatchInterfaceUtil_as_ChainWatchInterface (&chain2) , logger2);
313
+ LDK::NetGraphMsgHandler net_graph2 = NetGraphMsgHandler_new (NULL , logger2);
330
314
LDK::RoutingMessageHandler net_msgs2 = NetGraphMsgHandler_as_RoutingMessageHandler (&net_graph2);
331
315
LDK::ChannelAnnouncement chan_ann = ChannelAnnouncement_read (LDKu8slice { .data = valid_node_announcement, .datalen = sizeof (valid_node_announcement) });
332
316
LDK::CResult_boolLightningErrorZ ann_res = net_msgs2->handle_channel_announcement (net_msgs2->this_arg , &chan_ann);
@@ -435,14 +419,31 @@ int main() {
435
419
std::this_thread::yield ();
436
420
}
437
421
438
- BlockNotifier_block_connected (&blocks1, LDKu8slice { .data = channel_open_block, .datalen = sizeof (channel_open_block) }, 1 );
439
- BlockNotifier_block_connected (&blocks2, LDKu8slice { .data = channel_open_block, .datalen = sizeof (channel_open_block) }, 1 );
422
+ LDKCVec_C2Tuple_usizeTransactionZZ txdata { .data = (LDKC2TupleTempl_usize__Transaction*)malloc (sizeof (LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
423
+ *txdata.data = C2Tuple_usizeTransactionZ_new (0 , LDKTransaction { .data = channel_open_tx, .datalen = sizeof (channel_open_tx), .data_is_owned = false });
424
+ ChannelManager_block_connected (&cm1, &channel_open_header, txdata, 1 );
425
+
426
+ txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc (sizeof (LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
427
+ *txdata.data = C2Tuple_usizeTransactionZ_new (0 , LDKTransaction { .data = channel_open_tx, .datalen = sizeof (channel_open_tx), .data_is_owned = false });
428
+ ChannelManager_block_connected (&cm2, &channel_open_header, txdata, 1 );
429
+
430
+ txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc (sizeof (LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
431
+ *txdata.data = C2Tuple_usizeTransactionZ_new (0 , LDKTransaction { .data = channel_open_tx, .datalen = sizeof (channel_open_tx), .data_is_owned = false });
432
+ mons1.ConnectBlock (&channel_open_header, 1 , txdata, broadcast, fee_est);
433
+
434
+ txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2TupleTempl_usize__Transaction*)malloc (sizeof (LDKC2Tuple_usizeTransactionZ)), .datalen = 1 };
435
+ *txdata.data = C2Tuple_usizeTransactionZ_new (0 , LDKTransaction { .data = channel_open_tx, .datalen = sizeof (channel_open_tx), .data_is_owned = false });
436
+ mons2.ConnectBlock (&channel_open_header, 1 , txdata, broadcast, fee_est);
440
437
441
- BlockNotifier_block_connected (&blocks1, LDKu8slice { .data = block_1, .datalen = sizeof (block_1) }, 2 );
442
- BlockNotifier_block_connected (&blocks2, LDKu8slice { .data = block_1, .datalen = sizeof (block_1) }, 2 );
438
+ ChannelManager_block_connected (&cm1, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, 2 );
439
+ ChannelManager_block_connected (&cm2, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, 2 );
440
+ mons1.ConnectBlock (&header_1, 2 , LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, broadcast, fee_est);
441
+ mons2.ConnectBlock (&header_1, 2 , LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, broadcast, fee_est);
443
442
444
- BlockNotifier_block_connected (&blocks1, LDKu8slice { .data = block_2, .datalen = sizeof (block_2) }, 3 );
445
- BlockNotifier_block_connected (&blocks2, LDKu8slice { .data = block_2, .datalen = sizeof (block_2) }, 3 );
443
+ ChannelManager_block_connected (&cm1, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, 3 );
444
+ ChannelManager_block_connected (&cm2, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, 3 );
445
+ mons1.ConnectBlock (&header_2, 3 , LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, broadcast, fee_est);
446
+ mons2.ConnectBlock (&header_2, 3 , LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL , .datalen = 0 }, broadcast, fee_est);
446
447
447
448
PeerManager_process_events (&net1);
448
449
PeerManager_process_events (&net2);
0 commit comments