@@ -207,7 +207,7 @@ macro_rules! setup_builder {
207207pub ( crate ) use setup_builder;
208208
209209pub ( 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 ,
211211) -> ( TestNode , TestNode ) {
212212 println ! ( "== Node A ==" ) ;
213213 let config_a = random_config ( anchor_channels) ;
@@ -218,6 +218,14 @@ pub(crate) fn setup_two_nodes(
218218 if allow_0conf {
219219 config_b. trusted_peers_0conf . push ( node_a. node_id ( ) ) ;
220220 }
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+ }
221229 let node_b = setup_node ( electrsd, config_b) ;
222230 ( node_a, node_b)
223231}
@@ -417,20 +425,40 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
417425 node_b. sync_wallets ( ) . unwrap ( ) ;
418426
419427 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;
424435 assert ! ( node_a. list_balances( ) . spendable_onchain_balance_sats < node_a_upper_bound_sat) ;
425436 assert ! ( node_a. list_balances( ) . spendable_onchain_balance_sats > node_a_lower_bound_sat) ;
426437 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
429440 ) ;
430441
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+ ) ;
432459
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( ) ) ;
434462
435463 println ! ( "\n B receive" ) ;
436464 let invoice_amount_1_msat = 2500_000 ;
@@ -589,9 +617,9 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
589617 println ! ( "\n B close_channel (force: {})" , force_close) ;
590618 if force_close {
591619 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 ( ) ;
593621 } 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 ( ) ;
595623 }
596624
597625 expect_event ! ( node_a, ChannelClosed ) ;
@@ -604,84 +632,84 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
604632 node_b. sync_wallets ( ) . unwrap ( ) ;
605633
606634 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 ] {
610638 LightningBalance :: ClaimableAwaitingConfirmations {
611639 counterparty_node_id,
612640 confirmation_height,
613641 ..
614642 } => {
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 ;
617645 let blocks_to_go = confirmation_height - cur_height;
618646 generate_blocks_and_wait ( & bitcoind, electrsd, blocks_to_go as usize ) ;
619- node_a. sync_wallets ( ) . unwrap ( ) ;
620647 node_b. sync_wallets ( ) . unwrap ( ) ;
648+ node_a. sync_wallets ( ) . unwrap ( ) ;
621649 } ,
622650 _ => panic ! ( "Unexpected balance state!" ) ,
623651 }
624652
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 ] {
628656 PendingSweepBalance :: BroadcastAwaitingConfirmation { .. } => { } ,
629657 _ => panic ! ( "Unexpected balance state!" ) ,
630658 }
631659 generate_blocks_and_wait ( & bitcoind, electrsd, 1 ) ;
632- node_a. sync_wallets ( ) . unwrap ( ) ;
633660 node_b. sync_wallets ( ) . unwrap ( ) ;
661+ node_a. sync_wallets ( ) . unwrap ( ) ;
634662
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 ] {
638666 PendingSweepBalance :: AwaitingThresholdConfirmations { .. } => { } ,
639667 _ => panic ! ( "Unexpected balance state!" ) ,
640668 }
641669 generate_blocks_and_wait ( & bitcoind, electrsd, 5 ) ;
642- node_a. sync_wallets ( ) . unwrap ( ) ;
643670 node_b. sync_wallets ( ) . unwrap ( ) ;
671+ node_a. sync_wallets ( ) . unwrap ( ) ;
644672
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( ) ) ;
647675
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 ] {
651679 LightningBalance :: ClaimableAwaitingConfirmations {
652680 counterparty_node_id,
653681 confirmation_height,
654682 ..
655683 } => {
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 ;
658686 let blocks_to_go = confirmation_height - cur_height;
659687 generate_blocks_and_wait ( & bitcoind, electrsd, blocks_to_go as usize ) ;
660- node_b. sync_wallets ( ) . unwrap ( ) ;
661688 node_a. sync_wallets ( ) . unwrap ( ) ;
689+ node_b. sync_wallets ( ) . unwrap ( ) ;
662690 } ,
663691 _ => panic ! ( "Unexpected balance state!" ) ,
664692 }
665693
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 ] {
669697 PendingSweepBalance :: BroadcastAwaitingConfirmation { .. } => { } ,
670698 _ => panic ! ( "Unexpected balance state!" ) ,
671699 }
672700 generate_blocks_and_wait ( & bitcoind, electrsd, 1 ) ;
673- node_b. sync_wallets ( ) . unwrap ( ) ;
674701 node_a. sync_wallets ( ) . unwrap ( ) ;
702+ node_b. sync_wallets ( ) . unwrap ( ) ;
675703
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 ] {
679707 PendingSweepBalance :: AwaitingThresholdConfirmations { .. } => { } ,
680708 _ => panic ! ( "Unexpected balance state!" ) ,
681709 }
682710 generate_blocks_and_wait ( & bitcoind, electrsd, 5 ) ;
683- node_b. sync_wallets ( ) . unwrap ( ) ;
684711 node_a. sync_wallets ( ) . unwrap ( ) ;
712+ node_b. sync_wallets ( ) . unwrap ( ) ;
685713 }
686714
687715 let sum_of_all_payments_sat = ( push_msat
@@ -701,6 +729,9 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
701729 assert ! ( node_b. list_balances( ) . spendable_onchain_balance_sats > node_b_lower_bound_sat) ;
702730 assert ! ( node_b. list_balances( ) . spendable_onchain_balance_sats <= node_b_upper_bound_sat) ;
703731
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+
704735 // Check we handled all events
705736 assert_eq ! ( node_a. next_event( ) , None ) ;
706737 assert_eq ! ( node_b. next_event( ) , None ) ;
0 commit comments