@@ -204,24 +204,36 @@ pub(crate) fn random_listening_addresses() -> Vec<SocketAddress> {
204
204
pub ( crate ) fn random_node_alias ( ) -> Option < NodeAlias > {
205
205
let mut rng = thread_rng ( ) ;
206
206
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 ) ;
207
218
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 ,
215
221
}
216
222
}
217
223
218
- pub ( crate ) fn random_config ( anchor_channels : bool ) -> Config {
224
+ pub ( crate ) fn random_config ( anchor_channels : bool , announce_channel : bool ) -> Config {
219
225
let mut config = Config :: default ( ) ;
220
226
221
227
if !anchor_channels {
222
228
config. anchor_channels_config = None ;
223
229
}
224
230
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
+
225
237
config. network = Network :: Regtest ;
226
238
config. onchain_wallet_sync_interval_secs = 100000 ;
227
239
config. wallet_sync_interval_secs = 100000 ;
@@ -235,10 +247,6 @@ pub(crate) fn random_config(anchor_channels: bool) -> Config {
235
247
println ! ( "Setting random LDK listening addresses: {:?}" , rand_listening_addresses) ;
236
248
config. listening_addresses = Some ( rand_listening_addresses) ;
237
249
238
- let alias = random_node_alias ( ) ;
239
- println ! ( "Setting random LDK node alias: {:?}" , alias) ;
240
- config. node_alias = alias;
241
-
242
250
config. log_level = LogLevel :: Gossip ;
243
251
244
252
config
@@ -261,14 +269,15 @@ macro_rules! setup_builder {
261
269
pub ( crate ) use setup_builder;
262
270
263
271
pub ( 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 ,
265
274
) -> ( TestNode , TestNode ) {
266
275
println ! ( "== Node A ==" ) ;
267
- let config_a = random_config ( anchor_channels) ;
276
+ let config_a = random_config ( anchor_channels, announce_channel ) ;
268
277
let node_a = setup_node ( electrsd, config_a) ;
269
278
270
279
println ! ( "\n == Node B ==" ) ;
271
- let mut config_b = random_config ( anchor_channels) ;
280
+ let mut config_b = random_config ( anchor_channels, announce_channel ) ;
272
281
if allow_0conf {
273
282
config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
274
283
}
@@ -406,15 +415,28 @@ pub(crate) fn premine_and_distribute_funds<E: ElectrumApi>(
406
415
pub fn open_channel (
407
416
node_a : & TestNode , node_b : & TestNode , funding_amount_sat : u64 , electrsd : & ElectrsD ,
408
417
) {
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
+
418
440
assert ! ( node_a. list_peers( ) . iter( ) . find( |c| { c. node_id == node_b. node_id( ) } ) . is_some( ) ) ;
419
441
420
442
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>(
450
472
println ! ( "\n A -- open_channel -> B" ) ;
451
473
let funding_amount_sat = 2_080_000 ;
452
474
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
+ }
462
497
463
498
assert_eq ! ( node_a. list_peers( ) . first( ) . unwrap( ) . node_id, node_b. node_id( ) ) ;
464
499
assert ! ( node_a. list_peers( ) . first( ) . unwrap( ) . is_persisted) ;
0 commit comments