@@ -204,24 +204,36 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
204204pub ( crate ) fn random_node_alias ( ) -> Option < NodeAlias > {
205205 let mut rng = thread_rng ( ) ;
206206 let ranged_val = rng. gen_range ( 0 ..10 ) ;
207+
208+ let alias = format ! ( "ldk-node-{}" , ranged_val) ;
209+ let mut bytes = [ 0u8 ; 32 ] ;
210+ bytes[ ..alias. as_bytes ( ) . len ( ) ] . copy_from_slice ( alias. as_bytes ( ) ) ;
211+
212+ Some ( NodeAlias ( bytes) )
213+ }
214+
215+ pub ( crate ) fn random_announce_channel ( ) -> bool {
216+ let mut rng = thread_rng ( ) ;
217+ let ranged_val = rng. gen_range ( 0 ..=1 ) ;
207218 match ranged_val {
208- 0 => None ,
209- val => {
210- let alias = format ! ( "ldk-node-{}" , val) ;
211- let mut bytes = [ 0u8 ; 32 ] ;
212- bytes[ ..alias. as_bytes ( ) . len ( ) ] . copy_from_slice ( alias. as_bytes ( ) ) ;
213- Some ( NodeAlias ( bytes) )
214- } ,
219+ 0 => false ,
220+ _ => true ,
215221 }
216222}
217223
218- pub ( crate ) fn random_config ( anchor_channels : bool ) -> Config {
224+ pub ( crate ) fn random_config ( anchor_channels : bool , announce_channel : bool ) -> Config {
219225 let mut config = Config :: default ( ) ;
220226
221227 if !anchor_channels {
222228 config. anchor_channels_config = None ;
223229 }
224230
231+ if announce_channel {
232+ let alias = random_node_alias ( ) ;
233+ println ! ( "Setting random LDK node alias: {:?}" , alias) ;
234+ config. node_alias = alias;
235+ }
236+
225237 config. network = Network :: Regtest ;
226238 config. onchain_wallet_sync_interval_secs = 100000 ;
227239 config. wallet_sync_interval_secs = 100000 ;
@@ -235,10 +247,6 @@ pub(crate) fn random_config(anchor_channels: bool) -> Config {
235247 println ! ( "Setting random LDK listening addresses: {:?}" , rand_listening_addresses) ;
236248 config. listening_addresses = Some ( rand_listening_addresses) ;
237249
238- let alias = random_node_alias ( ) ;
239- println ! ( "Setting random LDK node alias: {:?}" , alias) ;
240- config. node_alias = alias;
241-
242250 config. log_level = LogLevel :: Gossip ;
243251
244252 config
@@ -261,14 +269,15 @@ macro_rules! setup_builder {
261269pub ( crate ) use setup_builder;
262270
263271pub ( crate ) fn setup_two_nodes (
264- electrsd : & ElectrsD , allow_0conf : bool , anchor_channels : bool , anchors_trusted_no_reserve : bool ,
272+ electrsd : & ElectrsD , allow_0conf : bool , anchor_channels : bool ,
273+ anchors_trusted_no_reserve : bool , announce_channel : bool ,
265274) -> ( TestNode , TestNode ) {
266275 println ! ( "== Node A ==" ) ;
267- let config_a = random_config ( anchor_channels) ;
276+ let config_a = random_config ( anchor_channels, announce_channel ) ;
268277 let node_a = setup_node ( electrsd, config_a) ;
269278
270279 println ! ( "\n == Node B ==" ) ;
271- let mut config_b = random_config ( anchor_channels) ;
280+ let mut config_b = random_config ( anchor_channels, announce_channel ) ;
272281 if allow_0conf {
273282 config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
274283 }
@@ -406,15 +415,28 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
406415pub fn open_channel (
407416 node_a : & TestNode , node_b : & TestNode , funding_amount_sat : u64 , electrsd : & ElectrsD ,
408417) {
409- node_a
410- . open_announced_channel (
411- node_b. node_id ( ) ,
412- node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
413- funding_amount_sat,
414- None ,
415- None ,
416- )
417- . unwrap ( ) ;
418+ if node_a. config ( ) . node_alias . is_some ( ) {
419+ node_a
420+ . open_announced_channel (
421+ node_b. node_id ( ) ,
422+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
423+ funding_amount_sat,
424+ None ,
425+ None ,
426+ )
427+ . unwrap ( ) ;
428+ } else {
429+ node_a
430+ . open_channel (
431+ node_b. node_id ( ) ,
432+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
433+ funding_amount_sat,
434+ None ,
435+ None ,
436+ )
437+ . unwrap ( ) ;
438+ }
439+
418440 assert ! ( node_a. list_peers( ) . iter( ) . find( |c| { c. node_id == node_b. node_id( ) } ) . is_some( ) ) ;
419441
420442 let funding_txo_a = expect_channel_pending_event ! ( node_a, node_b. node_id( ) ) ;
@@ -450,15 +472,28 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
450472 println ! ( "\n A -- open_channel -> B" ) ;
451473 let funding_amount_sat = 2_080_000 ;
452474 let push_msat = ( funding_amount_sat / 2 ) * 1000 ; // balance the channel
453- node_a
454- . open_channel (
455- node_b. node_id ( ) ,
456- node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
457- funding_amount_sat,
458- Some ( push_msat) ,
459- None ,
460- )
461- . unwrap ( ) ;
475+
476+ if node_a. config ( ) . node_alias . is_some ( ) {
477+ node_a
478+ . open_announced_channel (
479+ node_b. node_id ( ) ,
480+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
481+ funding_amount_sat,
482+ Some ( push_msat) ,
483+ None ,
484+ )
485+ . unwrap ( ) ;
486+ } else {
487+ node_a
488+ . open_channel (
489+ node_b. node_id ( ) ,
490+ node_b. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ,
491+ funding_amount_sat,
492+ Some ( push_msat) ,
493+ None ,
494+ )
495+ . unwrap ( ) ;
496+ }
462497
463498 assert_eq ! ( node_a. list_peers( ) . first( ) . unwrap( ) . node_id, node_b. node_id( ) ) ;
464499 assert ! ( node_a. list_peers( ) . first( ) . unwrap( ) . is_persisted) ;
0 commit comments