@@ -87,7 +87,7 @@ pub(crate) const WALLET_KEYS_SEED_LEN: usize = 64;
87
87
/// | `log_dir_path` | None |
88
88
/// | `network` | Bitcoin |
89
89
/// | `listening_addresses` | None |
90
- /// | `node_alias` | None |
90
+ /// | `node_alias` | None |
91
91
/// | `default_cltv_expiry_delta` | 144 |
92
92
/// | `onchain_wallet_sync_interval_secs` | 80 |
93
93
/// | `wallet_sync_interval_secs` | 30 |
@@ -113,12 +113,14 @@ pub struct Config {
113
113
pub network : Network ,
114
114
/// The addresses on which the node will listen for incoming connections.
115
115
///
116
- /// **Note**: Node announcements will only be broadcast if the `node_alias` and the
116
+ /// **Note**: We will only allow opening and accepting public channels if the `node_alias` and the
117
117
/// `listening_addresses` are set.
118
118
pub listening_addresses : Option < Vec < SocketAddress > > ,
119
- /// The node alias to be used in announcements.
119
+ /// The node alias that will be used when broadcasting announcements to the gossip network .
120
120
///
121
- /// **Note**: Node announcements will only be broadcast if the `node_alias` and the
121
+ /// The provided alias must be a valid UTF-8 string and no longer than 32 bytes in total.
122
+ ///
123
+ /// **Note**: We will only allow opening and accepting public channels if the `node_alias` and the
122
124
/// `listening_addresses` are set.
123
125
pub node_alias : Option < NodeAlias > ,
124
126
/// The time in-between background sync attempts of the onchain wallet, in seconds.
@@ -276,47 +278,9 @@ pub fn default_config() -> Config {
276
278
Config :: default ( )
277
279
}
278
280
279
- /// Specifies reasons why a channel cannot be announced.
280
- #[ derive( Debug , PartialEq ) ]
281
- pub ( crate ) enum ChannelAnnouncementBlocker {
282
- /// The node alias is not set.
283
- MissingNodeAlias ,
284
- /// The listening addresses are not set.
285
- MissingListeningAddresses ,
286
- // This listening addresses is set but the vector is empty.
287
- EmptyListeningAddresses ,
288
- }
289
-
290
- /// Enumeration defining the announcement status of a channel.
291
- #[ derive( Debug , PartialEq ) ]
292
- pub ( crate ) enum ChannelAnnouncementStatus {
293
- /// The channel is announceable.
294
- Announceable ,
295
- /// The channel is not announceable.
296
- Unannounceable ( ChannelAnnouncementBlocker ) ,
297
- }
298
-
299
- /// Checks if a node is can announce a channel based on the configured values of both the node's
300
- /// alias and its listening addresses.
301
- ///
302
- /// If either of them is unset, the node cannot announce the channel. This ability to announce/
303
- /// unannounce a channel is codified with `ChannelAnnouncementStatus`
304
- pub ( crate ) fn can_announce_channel ( config : & Config ) -> ChannelAnnouncementStatus {
305
- if config. node_alias . is_none ( ) {
306
- return ChannelAnnouncementStatus :: Unannounceable (
307
- ChannelAnnouncementBlocker :: MissingNodeAlias ,
308
- ) ;
309
- }
310
-
311
- match & config. listening_addresses {
312
- None => ChannelAnnouncementStatus :: Unannounceable (
313
- ChannelAnnouncementBlocker :: MissingListeningAddresses ,
314
- ) ,
315
- Some ( addresses) if addresses. is_empty ( ) => ChannelAnnouncementStatus :: Unannounceable (
316
- ChannelAnnouncementBlocker :: EmptyListeningAddresses ,
317
- ) ,
318
- Some ( _) => ChannelAnnouncementStatus :: Announceable ,
319
- }
281
+ pub ( crate ) fn may_announce_channel ( config : & Config ) -> bool {
282
+ config. node_alias . is_some ( )
283
+ && config. listening_addresses . as_ref ( ) . map_or ( false , |addrs| !addrs. is_empty ( ) )
320
284
}
321
285
322
286
pub ( crate ) fn default_user_config ( config : & Config ) -> UserConfig {
@@ -331,13 +295,10 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
331
295
user_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx =
332
296
config. anchor_channels_config . is_some ( ) ;
333
297
334
- match can_announce_channel ( config) {
335
- ChannelAnnouncementStatus :: Announceable => ( ) ,
336
- ChannelAnnouncementStatus :: Unannounceable ( _) => {
337
- user_config. accept_forwards_to_priv_channels = false ;
338
- user_config. channel_handshake_config . announced_channel = false ;
339
- user_config. channel_handshake_limits . force_announced_channel_preference = true ;
340
- } ,
298
+ if !may_announce_channel ( config) {
299
+ user_config. accept_forwards_to_priv_channels = false ;
300
+ user_config. channel_handshake_config . announced_channel = false ;
301
+ user_config. channel_handshake_limits . force_announced_channel_preference = true ;
341
302
}
342
303
343
304
user_config
@@ -347,23 +308,16 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
347
308
mod tests {
348
309
use std:: str:: FromStr ;
349
310
350
- use crate :: config:: ChannelAnnouncementStatus ;
351
-
352
- use super :: can_announce_channel;
311
+ use super :: may_announce_channel;
353
312
use super :: Config ;
354
313
use super :: NodeAlias ;
355
314
use super :: SocketAddress ;
356
315
357
316
#[ test]
358
- fn node_can_announce_channel ( ) {
317
+ fn node_announce_channel ( ) {
359
318
// Default configuration with node alias and listening addresses unset
360
319
let mut node_config = Config :: default ( ) ;
361
- assert_eq ! (
362
- can_announce_channel( & node_config) ,
363
- ChannelAnnouncementStatus :: Unannounceable (
364
- crate :: config:: ChannelAnnouncementBlocker :: MissingNodeAlias
365
- )
366
- ) ;
320
+ assert ! ( !may_announce_channel( & node_config) ) ;
367
321
368
322
// Set node alias with listening addresses unset
369
323
let alias_frm_str = |alias : & str | {
@@ -372,28 +326,18 @@ mod tests {
372
326
NodeAlias ( bytes)
373
327
} ;
374
328
node_config. node_alias = Some ( alias_frm_str ( "LDK_Node" ) ) ;
375
- assert_eq ! (
376
- can_announce_channel( & node_config) ,
377
- ChannelAnnouncementStatus :: Unannounceable (
378
- crate :: config:: ChannelAnnouncementBlocker :: MissingListeningAddresses
379
- )
380
- ) ;
329
+ assert ! ( !may_announce_channel( & node_config) ) ;
381
330
382
331
// Set node alias with an empty list of listening addresses
383
332
node_config. listening_addresses = Some ( vec ! [ ] ) ;
384
- assert_eq ! (
385
- can_announce_channel( & node_config) ,
386
- ChannelAnnouncementStatus :: Unannounceable (
387
- crate :: config:: ChannelAnnouncementBlocker :: EmptyListeningAddresses
388
- )
389
- ) ;
333
+ assert ! ( !may_announce_channel( & node_config) ) ;
390
334
391
335
// Set node alias with a non-empty list of listening addresses
392
336
let socket_address =
393
337
SocketAddress :: from_str ( "localhost:8000" ) . expect ( "Socket address conversion failed." ) ;
394
338
if let Some ( ref mut addresses) = node_config. listening_addresses {
395
339
addresses. push ( socket_address) ;
396
340
}
397
- assert_eq ! ( can_announce_channel ( & node_config) , ChannelAnnouncementStatus :: Announceable ) ;
341
+ assert ! ( may_announce_channel ( & node_config) ) ;
398
342
}
399
343
}
0 commit comments