@@ -207,7 +207,7 @@ macro_rules! setup_builder {
207
207
pub ( crate ) use setup_builder;
208
208
209
209
pub ( crate ) fn setup_two_nodes (
210
- electrsd : & ElectrsD , allow_0conf : bool , anchor_channels : bool ,
210
+ electrsd : & ElectrsD , allow_0conf : bool , anchor_channels : bool , anchors_trusted_no_reserve : bool ,
211
211
) -> ( TestNode , TestNode ) {
212
212
println ! ( "== Node A ==" ) ;
213
213
let config_a = random_config ( anchor_channels) ;
@@ -218,6 +218,14 @@ pub(crate) fn setup_two_nodes(
218
218
if allow_0conf {
219
219
config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
220
220
}
221
+ if anchor_channels && anchors_trusted_no_reserve {
222
+ config_b
223
+ . anchor_channels_config
224
+ . as_mut ( )
225
+ . unwrap ( )
226
+ . trusted_peers_no_reserve
227
+ . push ( node_a. node_id ( ) ) ;
228
+ }
221
229
let node_b = setup_node ( electrsd, config_b) ;
222
230
( node_a, node_b)
223
231
}
@@ -417,20 +425,40 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
417
425
node_b. sync_wallets ( ) . unwrap ( ) ;
418
426
419
427
let onchain_fee_buffer_sat = 1500 ;
420
- let anchor_reserve_sat = if expect_anchor_channel { 25_000 } else { 0 } ;
421
- let node_a_upper_bound_sat = premine_amount_sat - anchor_reserve_sat - funding_amount_sat;
422
- let node_a_lower_bound_sat =
423
- premine_amount_sat - anchor_reserve_sat - funding_amount_sat - onchain_fee_buffer_sat;
428
+ let node_a_anchor_reserve_sat = if expect_anchor_channel { 25_000 } else { 0 } ;
429
+ let node_a_upper_bound_sat =
430
+ premine_amount_sat - node_a_anchor_reserve_sat - funding_amount_sat;
431
+ let node_a_lower_bound_sat = premine_amount_sat
432
+ - node_a_anchor_reserve_sat
433
+ - funding_amount_sat
434
+ - onchain_fee_buffer_sat;
424
435
assert ! ( node_a. list_balances( ) . spendable_onchain_balance_sats < node_a_upper_bound_sat) ;
425
436
assert ! ( node_a. list_balances( ) . spendable_onchain_balance_sats > node_a_lower_bound_sat) ;
426
437
assert_eq ! (
427
- node_b . list_balances( ) . spendable_onchain_balance_sats ,
428
- premine_amount_sat - anchor_reserve_sat
438
+ node_a . list_balances( ) . total_anchor_channels_reserve_sats ,
439
+ node_a_anchor_reserve_sat
429
440
) ;
430
441
431
- expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
442
+ let node_b_anchor_reserve_sat = if node_b
443
+ . config ( )
444
+ . anchor_channels_config
445
+ . map_or ( true , |acc| acc. trusted_peers_no_reserve . contains ( & node_a. node_id ( ) ) )
446
+ {
447
+ 0
448
+ } else {
449
+ 25_000
450
+ } ;
451
+ assert_eq ! (
452
+ node_b. list_balances( ) . spendable_onchain_balance_sats,
453
+ premine_amount_sat - node_b_anchor_reserve_sat
454
+ ) ;
455
+ assert_eq ! (
456
+ node_b. list_balances( ) . total_anchor_channels_reserve_sats,
457
+ node_b_anchor_reserve_sat
458
+ ) ;
432
459
433
- let user_channel_id = expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
460
+ let user_channel_id = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
461
+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
434
462
435
463
println ! ( "\n B receive" ) ;
436
464
let invoice_amount_1_msat = 2500_000 ;
@@ -589,9 +617,9 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
589
617
println ! ( "\n B close_channel (force: {})" , force_close) ;
590
618
if force_close {
591
619
std:: thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
592
- node_b . close_channel ( & user_channel_id, node_a . node_id ( ) , true ) . unwrap ( ) ;
620
+ node_a . close_channel ( & user_channel_id, node_b . node_id ( ) , true ) . unwrap ( ) ;
593
621
} else {
594
- node_b . close_channel ( & user_channel_id, node_a . node_id ( ) , false ) . unwrap ( ) ;
622
+ node_a . close_channel ( & user_channel_id, node_b . node_id ( ) , false ) . unwrap ( ) ;
595
623
}
596
624
597
625
expect_event ! ( node_a, ChannelClosed ) ;
@@ -604,84 +632,84 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
604
632
node_b. sync_wallets ( ) . unwrap ( ) ;
605
633
606
634
if force_close {
607
- // Check node_a properly sees all balances and sweeps them.
608
- assert_eq ! ( node_a . list_balances( ) . lightning_balances. len( ) , 1 ) ;
609
- match node_a . list_balances ( ) . lightning_balances [ 0 ] {
635
+ // Check node_b properly sees all balances and sweeps them.
636
+ assert_eq ! ( node_b . list_balances( ) . lightning_balances. len( ) , 1 ) ;
637
+ match node_b . list_balances ( ) . lightning_balances [ 0 ] {
610
638
LightningBalance :: ClaimableAwaitingConfirmations {
611
639
counterparty_node_id,
612
640
confirmation_height,
613
641
..
614
642
} => {
615
- assert_eq ! ( counterparty_node_id, node_b . node_id( ) ) ;
616
- let cur_height = node_a . status ( ) . current_best_block . height ;
643
+ assert_eq ! ( counterparty_node_id, node_a . node_id( ) ) ;
644
+ let cur_height = node_b . status ( ) . current_best_block . height ;
617
645
let blocks_to_go = confirmation_height - cur_height;
618
646
generate_blocks_and_wait ( & bitcoind, electrsd, blocks_to_go as usize ) ;
619
- node_a. sync_wallets ( ) . unwrap ( ) ;
620
647
node_b. sync_wallets ( ) . unwrap ( ) ;
648
+ node_a. sync_wallets ( ) . unwrap ( ) ;
621
649
} ,
622
650
_ => panic ! ( "Unexpected balance state!" ) ,
623
651
}
624
652
625
- assert ! ( node_a . list_balances( ) . lightning_balances. is_empty( ) ) ;
626
- assert_eq ! ( node_a . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
627
- match node_a . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
653
+ assert ! ( node_b . list_balances( ) . lightning_balances. is_empty( ) ) ;
654
+ assert_eq ! ( node_b . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
655
+ match node_b . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
628
656
PendingSweepBalance :: BroadcastAwaitingConfirmation { .. } => { } ,
629
657
_ => panic ! ( "Unexpected balance state!" ) ,
630
658
}
631
659
generate_blocks_and_wait ( & bitcoind, electrsd, 1 ) ;
632
- node_a. sync_wallets ( ) . unwrap ( ) ;
633
660
node_b. sync_wallets ( ) . unwrap ( ) ;
661
+ node_a. sync_wallets ( ) . unwrap ( ) ;
634
662
635
- assert ! ( node_a . list_balances( ) . lightning_balances. is_empty( ) ) ;
636
- assert_eq ! ( node_a . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
637
- match node_a . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
663
+ assert ! ( node_b . list_balances( ) . lightning_balances. is_empty( ) ) ;
664
+ assert_eq ! ( node_b . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
665
+ match node_b . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
638
666
PendingSweepBalance :: AwaitingThresholdConfirmations { .. } => { } ,
639
667
_ => panic ! ( "Unexpected balance state!" ) ,
640
668
}
641
669
generate_blocks_and_wait ( & bitcoind, electrsd, 5 ) ;
642
- node_a. sync_wallets ( ) . unwrap ( ) ;
643
670
node_b. sync_wallets ( ) . unwrap ( ) ;
671
+ node_a. sync_wallets ( ) . unwrap ( ) ;
644
672
645
- assert ! ( node_a . list_balances( ) . lightning_balances. is_empty( ) ) ;
646
- assert ! ( node_a . list_balances( ) . pending_balances_from_channel_closures. is_empty( ) ) ;
673
+ assert ! ( node_b . list_balances( ) . lightning_balances. is_empty( ) ) ;
674
+ assert ! ( node_b . list_balances( ) . pending_balances_from_channel_closures. is_empty( ) ) ;
647
675
648
- // Check node_b properly sees all balances and sweeps them.
649
- assert_eq ! ( node_b . list_balances( ) . lightning_balances. len( ) , 1 ) ;
650
- match node_b . list_balances ( ) . lightning_balances [ 0 ] {
676
+ // Check node_a properly sees all balances and sweeps them.
677
+ assert_eq ! ( node_a . list_balances( ) . lightning_balances. len( ) , 1 ) ;
678
+ match node_a . list_balances ( ) . lightning_balances [ 0 ] {
651
679
LightningBalance :: ClaimableAwaitingConfirmations {
652
680
counterparty_node_id,
653
681
confirmation_height,
654
682
..
655
683
} => {
656
- assert_eq ! ( counterparty_node_id, node_a . node_id( ) ) ;
657
- let cur_height = node_b . status ( ) . current_best_block . height ;
684
+ assert_eq ! ( counterparty_node_id, node_b . node_id( ) ) ;
685
+ let cur_height = node_a . status ( ) . current_best_block . height ;
658
686
let blocks_to_go = confirmation_height - cur_height;
659
687
generate_blocks_and_wait ( & bitcoind, electrsd, blocks_to_go as usize ) ;
660
- node_b. sync_wallets ( ) . unwrap ( ) ;
661
688
node_a. sync_wallets ( ) . unwrap ( ) ;
689
+ node_b. sync_wallets ( ) . unwrap ( ) ;
662
690
} ,
663
691
_ => panic ! ( "Unexpected balance state!" ) ,
664
692
}
665
693
666
- assert ! ( node_b . list_balances( ) . lightning_balances. is_empty( ) ) ;
667
- assert_eq ! ( node_b . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
668
- match node_b . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
694
+ assert ! ( node_a . list_balances( ) . lightning_balances. is_empty( ) ) ;
695
+ assert_eq ! ( node_a . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
696
+ match node_a . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
669
697
PendingSweepBalance :: BroadcastAwaitingConfirmation { .. } => { } ,
670
698
_ => panic ! ( "Unexpected balance state!" ) ,
671
699
}
672
700
generate_blocks_and_wait ( & bitcoind, electrsd, 1 ) ;
673
- node_b. sync_wallets ( ) . unwrap ( ) ;
674
701
node_a. sync_wallets ( ) . unwrap ( ) ;
702
+ node_b. sync_wallets ( ) . unwrap ( ) ;
675
703
676
- assert ! ( node_b . list_balances( ) . lightning_balances. is_empty( ) ) ;
677
- assert_eq ! ( node_b . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
678
- match node_b . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
704
+ assert ! ( node_a . list_balances( ) . lightning_balances. is_empty( ) ) ;
705
+ assert_eq ! ( node_a . list_balances( ) . pending_balances_from_channel_closures. len( ) , 1 ) ;
706
+ match node_a . list_balances ( ) . pending_balances_from_channel_closures [ 0 ] {
679
707
PendingSweepBalance :: AwaitingThresholdConfirmations { .. } => { } ,
680
708
_ => panic ! ( "Unexpected balance state!" ) ,
681
709
}
682
710
generate_blocks_and_wait ( & bitcoind, electrsd, 5 ) ;
683
- node_b. sync_wallets ( ) . unwrap ( ) ;
684
711
node_a. sync_wallets ( ) . unwrap ( ) ;
712
+ node_b. sync_wallets ( ) . unwrap ( ) ;
685
713
}
686
714
687
715
let sum_of_all_payments_sat = ( push_msat
@@ -701,6 +729,9 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
701
729
assert ! ( node_b. list_balances( ) . spendable_onchain_balance_sats > node_b_lower_bound_sat) ;
702
730
assert ! ( node_b. list_balances( ) . spendable_onchain_balance_sats <= node_b_upper_bound_sat) ;
703
731
732
+ assert_eq ! ( node_a. list_balances( ) . total_anchor_channels_reserve_sats, 0 ) ;
733
+ assert_eq ! ( node_b. list_balances( ) . total_anchor_channels_reserve_sats, 0 ) ;
734
+
704
735
// Check we handled all events
705
736
assert_eq ! ( node_a. next_event( ) , None ) ;
706
737
assert_eq ! ( node_b. next_event( ) , None ) ;
0 commit comments