@@ -11,8 +11,9 @@ use common::{
1111 do_channel_full_cycle, expect_channel_pending_event, expect_channel_ready_event, expect_event,
1212 expect_payment_received_event, expect_payment_successful_event, generate_blocks_and_wait,
1313 logging:: { init_log_logger, validate_log_entry, TestLogWriter } ,
14- open_channel, premine_and_distribute_funds, random_config, setup_bitcoind_and_electrsd,
15- setup_builder, setup_node, setup_two_nodes, wait_for_tx, TestChainSource , TestSyncStore ,
14+ open_channel, premine_and_distribute_funds, random_config, random_listening_addresses,
15+ random_node_alias, setup_bitcoind_and_electrsd, setup_builder, setup_node, setup_two_nodes,
16+ wait_for_tx, TestChainSource , TestSyncStore ,
1617} ;
1718
1819use ldk_node:: config:: EsploraSyncConfig ;
@@ -24,6 +25,7 @@ use ldk_node::payment::{
2425use ldk_node:: { Builder , Event , NodeError } ;
2526
2627use lightning:: ln:: channelmanager:: PaymentId ;
28+ use lightning:: routing:: gossip:: NodeId ;
2729use lightning:: util:: persist:: KVStore ;
2830
2931use bitcoincore_rpc:: RpcApi ;
@@ -885,6 +887,89 @@ fn simple_bolt12_send_receive() {
885887 assert_eq ! ( node_a_payments. first( ) . unwrap( ) . amount_msat, Some ( overpaid_amount) ) ;
886888}
887889
890+ #[ test]
891+ fn test_node_announcement_propagation ( ) {
892+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
893+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
894+
895+ // Node A will use both listening and announcement addresses
896+ let mut config_a = random_config ( true ) ;
897+ let node_a_node_alias = random_node_alias ( ) ;
898+ let node_a_announcement_addresses = random_listening_addresses ( ) ;
899+ config_a. node_config . node_alias = node_a_node_alias. clone ( ) ;
900+ config_a. node_config . listening_addresses = Some ( random_listening_addresses ( ) ) ;
901+ config_a. node_config . announcement_addresses = Some ( node_a_announcement_addresses. clone ( ) ) ;
902+
903+ // Node B will only use listening addresses
904+ let mut config_b = random_config ( true ) ;
905+ let node_b_node_alias = random_node_alias ( ) ;
906+ let node_b_listening_addresses = random_listening_addresses ( ) ;
907+ config_b. node_config . node_alias = node_b_node_alias. clone ( ) ;
908+ config_b. node_config . listening_addresses = Some ( node_b_listening_addresses. clone ( ) ) ;
909+ config_b. node_config . announcement_addresses = None ;
910+
911+ let node_a = setup_node ( & chain_source, config_a, None ) ;
912+ let node_b = setup_node ( & chain_source, config_b, None ) ;
913+
914+ let address_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
915+ let premine_amount_sat = 5_000_000 ;
916+ premine_and_distribute_funds (
917+ & bitcoind. client ,
918+ & electrsd. client ,
919+ vec ! [ address_a] ,
920+ Amount :: from_sat ( premine_amount_sat) ,
921+ ) ;
922+
923+ node_a. sync_wallets ( ) . unwrap ( ) ;
924+
925+ // Open an announced channel from node_a to node_b
926+ open_channel ( & node_a, & node_b, 4_000_000 , true , & electrsd) ;
927+
928+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) ;
929+
930+ node_a. sync_wallets ( ) . unwrap ( ) ;
931+ node_b. sync_wallets ( ) . unwrap ( ) ;
932+
933+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
934+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
935+
936+ // Wait until node_b broadcasts a node announcement
937+ while node_b. status ( ) . latest_node_announcement_broadcast_timestamp . is_none ( ) {
938+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
939+ }
940+
941+ // Sleep to make sure the node announcement propagates
942+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
943+
944+ // Get node info from the other node's perspective
945+ let node_a_info = node_b. network_graph ( ) . node ( & NodeId :: from_pubkey ( & node_a. node_id ( ) ) ) . unwrap ( ) ;
946+ let node_a_announcement_info = node_a_info. announcement_info . as_ref ( ) . unwrap ( ) ;
947+
948+ let node_b_info = node_a. network_graph ( ) . node ( & NodeId :: from_pubkey ( & node_b. node_id ( ) ) ) . unwrap ( ) ;
949+ let node_b_announcement_info = node_b_info. announcement_info . as_ref ( ) . unwrap ( ) ;
950+
951+ // Assert that the aliases and addresses match the expected values
952+ #[ cfg( not( feature = "uniffi" ) ) ]
953+ assert_eq ! ( node_a_announcement_info. alias( ) , & node_a_node_alias. unwrap( ) ) ;
954+ #[ cfg( feature = "uniffi" ) ]
955+ assert_eq ! ( node_a_announcement_info. alias, & node_a_node_alias. unwrap( ) ) ;
956+
957+ #[ cfg( not( feature = "uniffi" ) ) ]
958+ assert_eq ! ( node_a_announcement_info. addresses( ) , & node_a_announcement_addresses) ;
959+ #[ cfg( feature = "uniffi" ) ]
960+ assert_eq ! ( node_a_announcement_info. addresses, & node_a_announcement_addresses) ;
961+
962+ #[ cfg( not( feature = "uniffi" ) ) ]
963+ assert_eq ! ( node_b_announcement_info. alias( ) , & node_b_node_alias. unwrap( ) ) ;
964+ #[ cfg( feature = "uniffi" ) ]
965+ assert_eq ! ( node_b_announcement_info. alias, & node_b_node_alias. unwrap( ) ) ;
966+
967+ #[ cfg( not( feature = "uniffi" ) ) ]
968+ assert_eq ! ( node_b_announcement_info. addresses( ) , & node_b_listening_addresses) ;
969+ #[ cfg( feature = "uniffi" ) ]
970+ assert_eq ! ( node_b_announcement_info. addresses, & node_b_listening_addresses) ;
971+ }
972+
888973#[ test]
889974fn generate_bip21_uri ( ) {
890975 let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
0 commit comments