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