@@ -122,8 +122,8 @@ pub use builder::BuildError;
122
122
pub use builder:: NodeBuilder as Builder ;
123
123
124
124
use config:: {
125
- can_announce_channel , default_user_config , ChannelAnnouncementStatus ,
126
- LDK_WALLET_SYNC_TIMEOUT_SECS , NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL ,
125
+ default_user_config , may_announce_channel , LDK_WALLET_SYNC_TIMEOUT_SECS ,
126
+ NODE_ANN_BCAST_INTERVAL , PEER_RECONNECTION_INTERVAL ,
127
127
RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL , RGS_SYNC_INTERVAL ,
128
128
WALLET_SYNC_INTERVAL_MINIMUM_SECS ,
129
129
} ;
@@ -605,20 +605,20 @@ impl Node {
605
605
let bcast_ann_timestamp = Arc :: clone ( & self . latest_node_announcement_broadcast_timestamp ) ;
606
606
let mut stop_bcast = self . stop_sender . subscribe ( ) ;
607
607
let node_alias = self . config . node_alias . clone ( ) ;
608
- let can_announce_channel = can_announce_channel ( & self . config ) ;
609
- runtime. spawn ( async move {
610
- // We check every 30 secs whether our last broadcast is NODE_ANN_BCAST_INTERVAL away.
611
- #[ cfg( not( test) ) ]
612
- let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 30 ) ) ;
613
- #[ cfg( test) ]
614
- let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 5 ) ) ;
615
- loop {
616
- tokio:: select! {
608
+ if may_announce_channel ( & self . config ) {
609
+ runtime. spawn ( async move {
610
+ // We check every 30 secs whether our last broadcast is NODE_ANN_BCAST_INTERVAL away.
611
+ #[ cfg( not( test) ) ]
612
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 30 ) ) ;
613
+ #[ cfg( test) ]
614
+ let mut interval = tokio:: time:: interval ( Duration :: from_secs ( 5 ) ) ;
615
+ loop {
616
+ tokio:: select! {
617
617
_ = stop_bcast. changed( ) => {
618
618
log_trace!(
619
619
bcast_logger,
620
620
"Stopping broadcasting node announcements." ,
621
- ) ;
621
+ ) ;
622
622
return ;
623
623
}
624
624
_ = interval. tick( ) => {
@@ -648,36 +648,37 @@ impl Node {
648
648
continue ;
649
649
}
650
650
651
- match can_announce_channel {
652
- ChannelAnnouncementStatus :: Unannounceable ( _) => {
653
- // Skip if we are not listening on any addresses or if the node alias is not set.
654
- continue ;
655
- }
656
- ChannelAnnouncementStatus :: Announceable => {
657
- let addresses = bcast_config. listening_addresses. clone( ) . unwrap_or( Vec :: new( ) ) ;
658
- if let Some ( node_alias) = node_alias. as_ref( ) {
659
- bcast_pm. broadcast_node_announcement( [ 0 ; 3 ] , node_alias. 0 , addresses) ;
660
- } else {
661
- continue
662
- }
663
- }
664
- }
651
+ let addresses = if let Some ( addresses) = bcast_config. listening_addresses. clone( ) {
652
+ addresses
653
+ } else {
654
+ debug_assert!( false , "We checked whether the node may announce, so listening addresses should always be set" ) ;
655
+ continue ;
656
+ } ;
657
+
658
+ if let Some ( node_alias) = node_alias. as_ref( ) {
659
+ bcast_pm. broadcast_node_announcement( [ 0 ; 3 ] , node_alias. 0 , addresses) ;
665
660
666
- let unix_time_secs_opt =
667
- SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
668
- * bcast_ann_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
661
+ let unix_time_secs_opt =
662
+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . ok( ) . map( |d| d. as_secs( ) ) ;
663
+ * bcast_ann_timestamp. write( ) . unwrap( ) = unix_time_secs_opt;
669
664
670
- if let Some ( unix_time_secs) = unix_time_secs_opt {
671
- io:: utils:: write_latest_node_ann_bcast_timestamp( unix_time_secs, Arc :: clone( & bcast_store) , Arc :: clone( & bcast_logger) )
672
- . unwrap_or_else( |e| {
673
- log_error!( bcast_logger, "Persistence failed: {}" , e) ;
674
- panic!( "Persistence failed" ) ;
675
- } ) ;
665
+ if let Some ( unix_time_secs) = unix_time_secs_opt {
666
+ io:: utils:: write_latest_node_ann_bcast_timestamp( unix_time_secs, Arc :: clone( & bcast_store) , Arc :: clone( & bcast_logger) )
667
+ . unwrap_or_else( |e| {
668
+ log_error!( bcast_logger, "Persistence failed: {}" , e) ;
669
+ panic!( "Persistence failed" ) ;
670
+ } ) ;
671
+ }
672
+ } else {
673
+ debug_assert!( false , "We checked whether the node may announce, so node alias should always be set" ) ;
674
+ continue
676
675
}
676
+
677
677
}
678
+ }
678
679
}
679
- }
680
- } ) ;
680
+ } ) ;
681
+ }
681
682
682
683
let mut stop_tx_bcast = self . stop_sender . subscribe ( ) ;
683
684
let tx_bcaster = Arc :: clone ( & self . tx_broadcaster ) ;
@@ -1341,26 +1342,18 @@ impl Node {
1341
1342
& self , node_id : PublicKey , address : SocketAddress , channel_amount_sats : u64 ,
1342
1343
push_to_counterparty_msat : Option < u64 > , channel_config : Option < ChannelConfig > ,
1343
1344
) -> Result < UserChannelId , Error > {
1344
- match can_announce_channel ( & self . config ) {
1345
- config :: ChannelAnnouncementStatus :: Announceable => self . open_channel_inner (
1345
+ if may_announce_channel ( & self . config ) {
1346
+ self . open_channel_inner (
1346
1347
node_id,
1347
1348
address,
1348
1349
channel_amount_sats,
1349
1350
push_to_counterparty_msat,
1350
1351
channel_config,
1351
1352
true ,
1352
- ) ,
1353
- config:: ChannelAnnouncementStatus :: Unannounceable ( reason) => match reason {
1354
- config:: ChannelAnnouncementBlocker :: MissingNodeAlias => {
1355
- return Err ( Error :: InvalidNodeAlias )
1356
- } ,
1357
- config:: ChannelAnnouncementBlocker :: MissingListeningAddresses => {
1358
- return Err ( Error :: InvalidSocketAddress )
1359
- } ,
1360
- config:: ChannelAnnouncementBlocker :: EmptyListeningAddresses => {
1361
- return Err ( Error :: InvalidSocketAddress )
1362
- } ,
1363
- } ,
1353
+ )
1354
+ } else {
1355
+ log_error ! ( self . logger, "Failed to open announced channel as the node hasn't been sufficiently configured to act as a forwarding node. Please make sure to configure listening addreesses and node alias" ) ;
1356
+ return Err ( Error :: ChannelCreationFailed ) ;
1364
1357
}
1365
1358
}
1366
1359
0 commit comments