@@ -20,6 +20,7 @@ extern "C" {
20
20
#include < thread>
21
21
#include < mutex>
22
22
#include < vector>
23
+ #include < iostream>
23
24
24
25
const uint8_t valid_node_announcement[] = {
25
26
0x94 , 0xe4 , 0xf5 , 0x61 , 0x41 , 0x24 , 0x7d , 0x90 , 0x23 , 0xa0 , 0xc8 , 0x34 , 0x8c , 0xc4 , 0xca , 0x51 ,
@@ -226,13 +227,15 @@ class PeersConnection {
226
227
227
228
assert (!socket_connect (node1_handler, ChannelManager_get_our_node_id (&cm2), (sockaddr*)&listen_addr, sizeof (listen_addr)));
228
229
230
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting initial handshake completion..." << std::endl;
229
231
while (true ) {
230
232
// Wait for the initial handshakes to complete...
231
233
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_1 = PeerManager_get_peer_node_ids (&net1);
232
234
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_2 = PeerManager_get_peer_node_ids (&net2);
233
235
if (peers_1->datalen == 1 && peers_2->datalen == 1 ) { break ; }
234
236
std::this_thread::yield ();
235
237
}
238
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Initial handshake complete!" << std::endl;
236
239
237
240
// Connect twice, which should auto-disconnect, and is a good test of our disconnect pipeline
238
241
assert (!socket_connect (node1_handler, ChannelManager_get_our_node_id (&cm2), (sockaddr*)&listen_addr, sizeof (listen_addr)));
@@ -242,15 +245,18 @@ class PeersConnection {
242
245
PeerManager_disconnect_by_node_id (&net1, ChannelManager_get_our_node_id (&cm2));
243
246
assert (!socket_connect (node1_handler, ChannelManager_get_our_node_id (&cm2), (sockaddr*)&listen_addr, sizeof (listen_addr)));
244
247
248
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting new connection handshake..." << std::endl;
245
249
while (true ) {
246
250
// Wait for the new connection handshake...
247
251
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_1 = PeerManager_get_peer_node_ids (&net1);
248
252
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_2 = PeerManager_get_peer_node_ids (&net2);
249
253
if (peers_1->datalen == 1 && peers_2->datalen == 1 ) { break ; }
250
254
std::this_thread::yield ();
251
255
}
256
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " New connection handshake complete!" << std::endl;
252
257
253
258
// Wait for all our sockets to disconnect (making sure we disconnect any new connections)...
259
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting peer disconnection..." << std::endl;
254
260
while (true ) {
255
261
PeerManager_disconnect_by_node_id (&net1, ChannelManager_get_our_node_id (&cm2));
256
262
// Wait for the peers to disconnect...
@@ -259,20 +265,23 @@ class PeersConnection {
259
265
if (peers_1->datalen == 0 && peers_2->datalen == 0 ) { break ; }
260
266
std::this_thread::yield ();
261
267
}
268
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Peers disconnected!" << std::endl;
262
269
// Note that the above is somewhat race-y, as node 2 may still think its connected.
263
270
// Thus, make sure any connections are disconnected on its end as well.
264
271
PeerManager_disconnect_by_node_id (&net2, ChannelManager_get_our_node_id (&cm1));
265
272
266
273
// Finally make an actual connection and keep it this time
267
274
assert (!socket_connect (node1_handler, ChannelManager_get_our_node_id (&cm2), (sockaddr*)&listen_addr, sizeof (listen_addr)));
268
275
276
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting initial handshake completion..." << std::endl;
269
277
while (true ) {
270
278
// Wait for the initial handshakes to complete...
271
279
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_1 = PeerManager_get_peer_node_ids (&net1);
272
280
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_2 = PeerManager_get_peer_node_ids (&net2);
273
281
if (peers_1->datalen == 1 && peers_2->datalen == 1 ) { break ; }
274
282
std::this_thread::yield ();
275
283
}
284
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Initial handshake complete!" << std::endl;
276
285
}
277
286
void stop () {
278
287
interrupt_socket_handling (node1_handler);
@@ -354,13 +363,15 @@ class PeersConnection {
354
363
auto writelen = write (pipefds_1_to_2[1 ], con_res->contents .result ->data , con_res->contents .result ->datalen );
355
364
assert (writelen > 0 && uint64_t (writelen) == con_res->contents .result ->datalen );
356
365
366
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting initial handshake completion..." << std::endl;
357
367
while (true ) {
358
368
// Wait for the initial handshakes to complete...
359
369
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_1 = PeerManager_get_peer_node_ids (&net1);
360
370
LDK::CVec_C2Tuple_PublicKeyCOption_NetAddressZZZ peers_2 = PeerManager_get_peer_node_ids (&net2);
361
371
if (peers_1->datalen == 1 && peers_2->datalen ==1 ) { break ; }
362
372
std::this_thread::yield ();
363
373
}
374
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Initial handshake complete!" << std::endl;
364
375
}
365
376
366
377
void stop () {
@@ -644,6 +655,7 @@ int main() {
644
655
LDKPublicKey chan_open_pk = ChannelCounterparty_get_node_id (&new_channels_counterparty);
645
656
assert (!memcmp (chan_open_pk.compressed_form , ChannelManager_get_our_node_id (&cm2).compressed_form , 33 ));
646
657
658
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting first channel..." << std::endl;
647
659
while (true ) {
648
660
LDK::CVec_ChannelDetailsZ new_channels_2 = ChannelManager_list_channels (&cm2);
649
661
if (new_channels_2->datalen == 1 ) {
@@ -655,8 +667,10 @@ int main() {
655
667
}
656
668
std::this_thread::yield ();
657
669
}
670
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " First channel listed!" << std::endl;
658
671
659
672
LDK::EventsProvider ev1 = ChannelManager_as_EventsProvider (&cm1);
673
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting FundingGenerationReady event..." << std::endl;
660
674
while (true ) {
661
675
EventQueue queue;
662
676
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -677,19 +691,23 @@ int main() {
677
691
}
678
692
std::this_thread::yield ();
679
693
}
694
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received FundingGenerationReady event!" << std::endl;
680
695
681
696
// We observe when the funding signed messages have been exchanged by
682
697
// waiting for two monitors to be registered.
683
698
assert (num_txs_broadcasted == 0 );
684
699
PeerManager_process_events (&net1);
700
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting transaction broadcast..." << std::endl;
685
701
while (num_txs_broadcasted != 1 ) {
686
702
std::this_thread::yield ();
687
703
}
704
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Transaction was broadcast!" << std::endl;
688
705
689
706
// Note that the channel ID is the same as the channel txid reversed as the output index is 0
690
707
uint8_t expected_chan_id[32 ];
691
708
for (int i = 0 ; i < 32 ; i++) { expected_chan_id[i] = channel_open_txid[31 -i]; }
692
709
710
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting ChannelPending event..." << std::endl;
693
711
while (true ) {
694
712
EventQueue queue;
695
713
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -701,8 +719,10 @@ int main() {
701
719
}
702
720
std::this_thread::yield ();
703
721
}
722
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received ChannelPending event!" << std::endl;
704
723
705
724
LDK::EventsProvider ev2 = ChannelManager_as_EventsProvider (&cm2);
725
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting ChannelPending event..." << std::endl;
706
726
while (true ) {
707
727
EventQueue queue;
708
728
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -714,6 +734,7 @@ int main() {
714
734
}
715
735
std::this_thread::yield ();
716
736
}
737
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received ChannelPending event!" << std::endl;
717
738
718
739
LDK::Listen listener1 = ChannelManager_as_Listen (&cm1);
719
740
listener1->block_connected (listener1->this_arg , LDKu8slice { .data = channel_open_block, .datalen = sizeof (channel_open_block) }, 1 );
@@ -742,6 +763,7 @@ int main() {
742
763
PeerManager_process_events (&net1);
743
764
PeerManager_process_events (&net2);
744
765
766
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting ChannelReady event..." << std::endl;
745
767
while (true ) {
746
768
EventQueue queue;
747
769
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -753,7 +775,9 @@ int main() {
753
775
}
754
776
std::this_thread::yield ();
755
777
}
778
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received ChannelReady event!" << std::endl;
756
779
780
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting ChannelReady event..." << std::endl;
757
781
while (true ) {
758
782
EventQueue queue;
759
783
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -765,9 +789,11 @@ int main() {
765
789
}
766
790
std::this_thread::yield ();
767
791
}
792
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received ChannelReady event!" << std::endl;
768
793
769
794
// Now send funds from 1 to 2!
770
795
uint64_t channel_scid;
796
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting usable channel..." << std::endl;
771
797
while (true ) {
772
798
LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels (&cm1);
773
799
if (outbound_channels->datalen == 1 ) {
@@ -793,6 +819,7 @@ int main() {
793
819
}
794
820
std::this_thread::yield ();
795
821
}
822
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Listed usable channel!" << std::endl;
796
823
797
824
LDKCOption_u64Z min_value = {
798
825
.tag = LDKCOption_u64Z_Some,
@@ -843,11 +870,14 @@ int main() {
843
870
844
871
mons_updated = 0 ;
845
872
PeerManager_process_events (&net1);
873
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting 4 updated monitors..." << std::endl;
846
874
while (mons_updated != 4 ) {
847
875
std::this_thread::yield ();
848
876
}
877
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " 4 monitors updated!" << std::endl;
849
878
850
879
// Check that we received the payment!
880
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting PendingHTLCsForwardable event..." << std::endl;
851
881
while (true ) {
852
882
EventQueue queue;
853
883
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
@@ -858,6 +888,7 @@ int main() {
858
888
}
859
889
std::this_thread::yield ();
860
890
}
891
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received PendingHTLCsForwardable event!" << std::endl;
861
892
ChannelManager_process_pending_htlc_forwards (&cm2);
862
893
PeerManager_process_events (&net2);
863
894
@@ -886,14 +917,20 @@ int main() {
886
917
}
887
918
PeerManager_process_events (&net2);
888
919
// Wait until we've passed through a full set of monitor updates (ie new preimage + CS/RAA messages)
920
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting 5 updated monitors..." << std::endl;
889
921
while (mons_updated != 5 ) {
890
922
std::this_thread::yield ();
891
923
}
924
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " 5 monitors updated!" << std::endl;
892
925
{
893
926
EventQueue queue;
894
927
LDKEventHandler handler = { .this_arg = &queue, .handle_event = handle_event, .free = NULL };
895
- while (queue.events .size () < 2 )
928
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting PaymentSent and PaymentPathSuccessful events..." << std::endl;
929
+ while (queue.events .size () < 2 ) {
896
930
ev1.process_pending_events (handler);
931
+ std::this_thread::yield ();
932
+ }
933
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received PaymentSent and PaymentPathSuccessful events (presumably)!" << std::endl;
897
934
assert (queue.events .size () == 2 );
898
935
assert (queue.events [0 ]->tag == LDKEvent_PaymentSent);
899
936
assert (!memcmp (queue.events [0 ]->payment_sent .payment_preimage .data , payment_preimage.data , 32 ));
@@ -1011,6 +1048,7 @@ int main() {
1011
1048
1012
1049
PeersConnection conn (cm1, cm2, net1, net2);
1013
1050
1051
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting usable channel..." << std::endl;
1014
1052
while (true ) {
1015
1053
// Wait for the channels to be considered up once the reestablish messages are processed
1016
1054
LDK::CVec_ChannelDetailsZ outbound_channels = ChannelManager_list_usable_channels (&cm1);
@@ -1019,6 +1057,7 @@ int main() {
1019
1057
}
1020
1058
std::this_thread::yield ();
1021
1059
}
1060
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Listed usable channel!" << std::endl;
1022
1061
1023
1062
// Send another payment, this time via the retires path
1024
1063
LDK::CResult_InvoiceSignOrCreationErrorZ invoice_res2 = create_invoice_from_channelmanager (&cm2,
@@ -1036,6 +1075,7 @@ int main() {
1036
1075
PeerManager_process_events (&net1);
1037
1076
1038
1077
// Check that we received the payment!
1078
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting PendingHTLCsForwardable event..." << std::endl;
1039
1079
while (true ) {
1040
1080
EventQueue queue2;
1041
1081
LDKEventHandler handler2 = { .this_arg = &queue2, .handle_event = handle_event, .free = NULL };
@@ -1047,9 +1087,11 @@ int main() {
1047
1087
}
1048
1088
std::this_thread::yield ();
1049
1089
}
1090
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received PendingHTLCsForwardable event!" << std::endl;
1050
1091
ChannelManager_process_pending_htlc_forwards (&cm2);
1051
1092
PeerManager_process_events (&net2);
1052
1093
1094
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting PaymentClaimable/PaymentClaimed event..." << std::endl;
1053
1095
while (true ) {
1054
1096
EventQueue queue2;
1055
1097
LDKEventHandler handler2 = { .this_arg = &queue2, .handle_event = handle_event, .free = NULL };
@@ -1076,16 +1118,20 @@ int main() {
1076
1118
}
1077
1119
std::this_thread::yield ();
1078
1120
}
1121
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received PaymentClaimable/PaymentClaimed event!" << std::endl;
1079
1122
1080
1123
EventQueue queue1;
1081
1124
LDKEventHandler handler1 = { .this_arg = &queue1, .handle_event = handle_event, .free = NULL };
1125
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting PaymentSent and PaymentPathSuccessful events..." << std::endl;
1082
1126
while (queue1.events .size () < 2 ) {
1083
1127
PeerManager_process_events (&net2);
1084
1128
PeerManager_process_events (&net1);
1085
1129
1086
1130
LDK::EventsProvider ev1 = ChannelManager_as_EventsProvider (&cm1);
1087
1131
ev1.process_pending_events (handler1);
1132
+ std::this_thread::yield ();
1088
1133
}
1134
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received PaymentSent and PaymentPathSuccessful events (presumably)!" << std::endl;
1089
1135
assert (queue1.events .size () == 2 );
1090
1136
assert (queue1.events [0 ]->tag == LDKEvent_PaymentSent);
1091
1137
assert (queue1.events [1 ]->tag == LDKEvent_PaymentPathSuccessful);
@@ -1095,9 +1141,11 @@ int main() {
1095
1141
close_res = ChannelManager_close_channel (&cm1, &chan_id, ChannelManager_get_our_node_id (&cm2));
1096
1142
assert (close_res->result_ok );
1097
1143
PeerManager_process_events (&net1);
1144
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting 2 transaction broadcasts..." << std::endl;
1098
1145
while (num_txs_broadcasted != 2 ) {
1099
1146
std::this_thread::yield ();
1100
1147
}
1148
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Broadcast 2 transactions!" << std::endl;
1101
1149
LDK::CVec_ChannelDetailsZ chans_after_close1 = ChannelManager_list_channels (&cm1);
1102
1150
assert (chans_after_close1->datalen == 0 );
1103
1151
LDK::CVec_ChannelDetailsZ chans_after_close2 = ChannelManager_list_channels (&cm2);
@@ -1112,11 +1160,13 @@ int main() {
1112
1160
}, LDKBlindedPath { .inner = NULL , .is_owned = true })
1113
1161
.result_ok );
1114
1162
PeerManager_process_events (&net1);
1163
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Awaiting onion message..." << std::endl;
1115
1164
while (true ) {
1116
1165
std::this_thread::yield ();
1117
1166
std::unique_lock<std::mutex> lck (peer_2_custom_onion_messages.mtx );
1118
1167
if (peer_2_custom_onion_messages.msgs .size () != 0 ) break ;
1119
1168
}
1169
+ std::cout << __FILE__ << " :" << __LINE__ << " - " << " Received onion message!" << std::endl;
1120
1170
1121
1171
conn.stop ();
1122
1172
0 commit comments