@@ -309,17 +309,20 @@ fn archive_fully_resolved_monitors() {
309
309
}
310
310
}
311
311
312
- fn do_chanmon_claim_value_coop_close ( anchors : bool ) {
312
+ fn do_chanmon_claim_value_coop_close ( keyed_anchors : bool , p2a_anchor : bool ) {
313
313
// Tests `get_claimable_balances` returns the correct values across a simple cooperative claim.
314
314
// Specifically, this tests that the channel non-HTLC balances show up in
315
315
// `get_claimable_balances` until the cooperative claims have confirmed and generated a
316
316
// `SpendableOutputs` event, and no longer.
317
317
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
318
318
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
319
319
let mut user_config = test_default_channel_config ( ) ;
320
- if anchors {
320
+ if keyed_anchors {
321
321
user_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
322
322
user_config. manually_accept_inbound_channels = true ;
323
+ } else if p2a_anchor {
324
+ user_config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
325
+ user_config. manually_accept_inbound_channels = true ;
323
326
}
324
327
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
325
328
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
@@ -333,7 +336,7 @@ fn do_chanmon_claim_value_coop_close(anchors: bool) {
333
336
let channel_type_features = get_channel_type_features ! ( nodes[ 0 ] , nodes[ 1 ] , chan_id) ;
334
337
335
338
let commitment_tx_fee = chan_feerate * chan_utils:: commitment_tx_base_weight ( & channel_type_features) / 1000 ;
336
- let anchor_outputs_value = if anchors { channel:: ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } ;
339
+ let anchor_outputs_value = if keyed_anchors { channel:: ANCHOR_OUTPUT_VALUE_SATOSHI * 2 } else { 0 } ;
337
340
assert_eq ! ( vec![ Balance :: ClaimableOnChannelClose {
338
341
balance_candidates: vec![ HolderCommitmentTransactionBalance {
339
342
amount_satoshis: 1_000_000 - 1_000 - commitment_tx_fee - anchor_outputs_value,
@@ -434,8 +437,9 @@ fn do_chanmon_claim_value_coop_close(anchors: bool) {
434
437
435
438
#[ test]
436
439
fn chanmon_claim_value_coop_close ( ) {
437
- do_chanmon_claim_value_coop_close ( false ) ;
438
- do_chanmon_claim_value_coop_close ( true ) ;
440
+ do_chanmon_claim_value_coop_close ( false , false ) ;
441
+ do_chanmon_claim_value_coop_close ( true , false ) ;
442
+ do_chanmon_claim_value_coop_close ( false , true ) ;
439
443
}
440
444
441
445
fn sorted_vec < T : Ord > ( mut v : Vec < T > ) -> Vec < T > {
@@ -454,7 +458,7 @@ fn fuzzy_assert_eq<V: core::convert::TryInto<u64>>(a: V, b: V) {
454
458
assert ! ( b_u64 >= a_u64 - 5 ) ;
455
459
}
456
460
457
- fn do_test_claim_value_force_close ( anchors : bool , prev_commitment_tx : bool ) {
461
+ fn do_test_claim_value_force_close ( keyed_anchors : bool , p2a_anchor : bool , prev_commitment_tx : bool ) {
458
462
// Tests `get_claimable_balances` with an HTLC across a force-close.
459
463
// We build a channel with an HTLC pending, then force close the channel and check that the
460
464
// `get_claimable_balances` return value is correct as transactions confirm on-chain.
@@ -468,9 +472,12 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
468
472
}
469
473
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
470
474
let mut user_config = test_default_channel_config ( ) ;
471
- if anchors {
475
+ if keyed_anchors {
472
476
user_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
473
477
user_config. manually_accept_inbound_channels = true ;
478
+ } else if p2a_anchor {
479
+ user_config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
480
+ user_config. manually_accept_inbound_channels = true ;
474
481
}
475
482
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( user_config. clone ( ) ) , Some ( user_config) ] ) ;
476
483
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
@@ -535,13 +542,13 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
535
542
// as claimable. A lists both its to-self balance and the (possibly-claimable) HTLCs.
536
543
let commitment_tx_fee = chan_feerate as u64 *
537
544
( chan_utils:: commitment_tx_base_weight ( & channel_type_features) + 2 * chan_utils:: COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
538
- let anchor_outputs_value = if anchors { 2 * channel:: ANCHOR_OUTPUT_VALUE_SATOSHI } else { 0 } ;
545
+ let anchor_outputs_value = if keyed_anchors { 2 * channel:: ANCHOR_OUTPUT_VALUE_SATOSHI } else { 0 } ;
539
546
let amount_satoshis = 1_000_000 - 3_000 - 4_000 - 1_000 - 3 - commitment_tx_fee - anchor_outputs_value - 1 ; /* msat amount that is burned to fees */
540
547
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableOnChannelClose {
541
548
balance_candidates: vec![ HolderCommitmentTransactionBalance {
542
549
amount_satoshis,
543
550
// In addition to `commitment_tx_fee`, this also includes the dust HTLC, and the total msat amount rounded down from non-dust HTLCs
544
- transaction_fee_satoshis: 1_000_000 - 4_000 - 3_000 - 1_000 - amount_satoshis - anchor_outputs_value,
551
+ transaction_fee_satoshis: if p2a_anchor { 0 } else { 1_000_000 - 4_000 - 3_000 - 1_000 - amount_satoshis - anchor_outputs_value } ,
545
552
} ] ,
546
553
confirmed_balance_candidate_index: 0 ,
547
554
outbound_payment_htlc_rounded_msat: 3300 ,
@@ -611,7 +618,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
611
618
balance_candidates: vec![ HolderCommitmentTransactionBalance {
612
619
amount_satoshis, // Channel funding value in satoshis
613
620
// In addition to `commitment_tx_fee`, this also includes the dust HTLC, and the total msat amount rounded down from non-dust HTLCs
614
- transaction_fee_satoshis: 1_000_000 - 4_000 - 3_000 - 1_000 - amount_satoshis - anchor_outputs_value,
621
+ transaction_fee_satoshis: if p2a_anchor { 0 } else { 1_000_000 - 4_000 - 3_000 - 1_000 - amount_satoshis - anchor_outputs_value } ,
615
622
} ] ,
616
623
confirmed_balance_candidate_index: 0 ,
617
624
outbound_payment_htlc_rounded_msat: 3000 + if prev_commitment_tx {
@@ -645,7 +652,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
645
652
mine_transaction ( & nodes[ 0 ] , & remote_txn[ 0 ] ) ;
646
653
mine_transaction ( & nodes[ 1 ] , & remote_txn[ 0 ] ) ;
647
654
648
- if anchors {
655
+ if keyed_anchors || p2a_anchor {
649
656
let mut events = nodes[ 1 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
650
657
assert_eq ! ( events. len( ) , 1 ) ;
651
658
match events. pop ( ) . unwrap ( ) {
@@ -674,8 +681,8 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
674
681
// b_broadcast_txn should spend the HTLCs output of the commitment tx for 3_000 and 4_000 sats
675
682
check_spends ! ( b_broadcast_txn[ 0 ] , remote_txn[ 0 ] , coinbase_tx) ;
676
683
check_spends ! ( b_broadcast_txn[ 1 ] , remote_txn[ 0 ] , coinbase_tx) ;
677
- assert_eq ! ( b_broadcast_txn[ 0 ] . input. len( ) , if anchors { 2 } else { 1 } ) ;
678
- assert_eq ! ( b_broadcast_txn[ 1 ] . input. len( ) , if anchors { 2 } else { 1 } ) ;
684
+ assert_eq ! ( b_broadcast_txn[ 0 ] . input. len( ) , if keyed_anchors || p2a_anchor { 2 } else { 1 } ) ;
685
+ assert_eq ! ( b_broadcast_txn[ 1 ] . input. len( ) , if keyed_anchors || p2a_anchor { 2 } else { 1 } ) ;
679
686
assert_eq ! ( remote_txn[ 0 ] . output[ b_broadcast_txn[ 0 ] . input[ 0 ] . previous_output. vout as usize ] . value. to_sat( ) , 3_000 ) ;
680
687
assert_eq ! ( remote_txn[ 0 ] . output[ b_broadcast_txn[ 1 ] . input[ 0 ] . previous_output. vout as usize ] . value. to_sat( ) , 4_000 ) ;
681
688
@@ -807,7 +814,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
807
814
// After reaching the commitment output CSV, we'll get a SpendableOutputs event for it and have
808
815
// only the HTLCs claimable on node B.
809
816
connect_blocks ( & nodes[ 1 ] , node_b_commitment_claimable - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
810
- test_spendable_output ( & nodes[ 1 ] , & remote_txn[ 0 ] , anchors ) ;
817
+ test_spendable_output ( & nodes[ 1 ] , & remote_txn[ 0 ] , keyed_anchors || p2a_anchor ) ;
811
818
812
819
assert_eq ! ( sorted_vec( vec![ Balance :: ClaimableAwaitingConfirmations {
813
820
amount_satoshis: 3_000 ,
@@ -819,7 +826,7 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
819
826
// After reaching the claimed HTLC output CSV, we'll get a SpendableOutptus event for it and
820
827
// have only one HTLC output left spendable.
821
828
connect_blocks ( & nodes[ 1 ] , node_b_htlc_claimable - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
822
- test_spendable_output ( & nodes[ 1 ] , & b_broadcast_txn[ 0 ] , anchors ) ;
829
+ test_spendable_output ( & nodes[ 1 ] , & b_broadcast_txn[ 0 ] , keyed_anchors || p2a_anchor ) ;
823
830
824
831
assert_eq ! ( vec![ received_htlc_timeout_claiming_balance. clone( ) ] ,
825
832
nodes[ 1 ] . chain_monitor. chain_monitor. get_monitor( chan_id) . unwrap( ) . get_claimable_balances( ) ) ;
@@ -847,10 +854,12 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) {
847
854
848
855
#[ test]
849
856
fn test_claim_value_force_close ( ) {
850
- do_test_claim_value_force_close ( false , true ) ;
851
- do_test_claim_value_force_close ( false , false ) ;
852
- do_test_claim_value_force_close ( true , true ) ;
853
- do_test_claim_value_force_close ( true , false ) ;
857
+ do_test_claim_value_force_close ( false , false , true ) ;
858
+ do_test_claim_value_force_close ( false , false , false ) ;
859
+ do_test_claim_value_force_close ( true , false , true ) ;
860
+ do_test_claim_value_force_close ( true , false , false ) ;
861
+ do_test_claim_value_force_close ( false , true , true ) ;
862
+ do_test_claim_value_force_close ( false , true , false ) ;
854
863
}
855
864
856
865
fn do_test_balances_on_local_commitment_htlcs ( anchors : bool ) {
@@ -2496,7 +2505,7 @@ fn test_monitor_timer_based_claim() {
2496
2505
do_test_monitor_rebroadcast_pending_claims ( true ) ;
2497
2506
}
2498
2507
2499
- fn do_test_yield_anchors_events ( have_htlcs : bool ) {
2508
+ fn do_test_yield_anchors_events ( have_htlcs : bool , p2a_anchor : bool ) {
2500
2509
// Tests that two parties supporting anchor outputs can open a channel, route payments over
2501
2510
// it, and finalize its resolution uncooperatively. Once the HTLCs are locked in, one side will
2502
2511
// force close once the HTLCs expire. The force close should stem from an event emitted by LDK,
@@ -2508,6 +2517,7 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2508
2517
let mut anchors_config = test_default_channel_config ( ) ;
2509
2518
anchors_config. channel_handshake_config . announce_for_forwarding = true ;
2510
2519
anchors_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
2520
+ anchors_config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = p2a_anchor;
2511
2521
anchors_config. manually_accept_inbound_channels = true ;
2512
2522
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( anchors_config. clone ( ) ) , Some ( anchors_config) ] ) ;
2513
2523
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
@@ -2551,7 +2561,7 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2551
2561
{
2552
2562
handle_bump_close_event ( & nodes[ 1 ] ) ;
2553
2563
let txn = nodes[ 1 ] . tx_broadcaster . txn_broadcast ( ) ;
2554
- assert_eq ! ( txn. len( ) , 1 ) ;
2564
+ if p2a_anchor { assert_eq ! ( txn. len( ) , 2 ) } else { assert_eq ! ( txn . len ( ) , 1 ) } ;
2555
2565
check_spends ! ( txn[ 0 ] , funding_tx) ;
2556
2566
}
2557
2567
@@ -2601,7 +2611,10 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2601
2611
} ;
2602
2612
check_spends ! ( commitment_tx, funding_tx) ;
2603
2613
2604
- if have_htlcs {
2614
+ if have_htlcs && p2a_anchor {
2615
+ assert_eq ! ( commitment_tx. output[ 1 ] . value. to_sat( ) , 1_000 ) ; // HTLC A -> B
2616
+ assert_eq ! ( commitment_tx. output[ 2 ] . value. to_sat( ) , 2_000 ) ; // HTLC B -> A
2617
+ } else if have_htlcs {
2605
2618
assert_eq ! ( commitment_tx. output[ 2 ] . value. to_sat( ) , 1_000 ) ; // HTLC A -> B
2606
2619
assert_eq ! ( commitment_tx. output[ 3 ] . value. to_sat( ) , 2_000 ) ; // HTLC B -> A
2607
2620
}
@@ -2626,12 +2639,12 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2626
2639
assert_eq ! ( txn. len( ) , if nodes[ 1 ] . connect_style. borrow( ) . updates_best_block_first( ) { 3 } else { 1 } ) ;
2627
2640
if nodes[ 1 ] . connect_style . borrow ( ) . updates_best_block_first ( ) {
2628
2641
check_spends ! ( txn[ 1 ] , funding_tx) ;
2629
- check_spends ! ( txn[ 2 ] , txn[ 1 ] ) ; // Anchor output spend.
2642
+ check_spends ! ( txn[ 2 ] , txn[ 1 ] , coinbase_tx ) ; // Anchor output spend.
2630
2643
}
2631
2644
let htlc_claim_tx = & txn[ 0 ] ;
2632
2645
assert_eq ! ( htlc_claim_tx. input. len( ) , 2 ) ;
2633
- assert_eq ! ( htlc_claim_tx. input[ 0 ] . previous_output. vout, 2 ) ;
2634
- assert_eq ! ( htlc_claim_tx. input[ 1 ] . previous_output. vout, 3 ) ;
2646
+ assert_eq ! ( htlc_claim_tx. input[ 0 ] . previous_output. vout, if p2a_anchor { 1 } else { 2 } ) ;
2647
+ assert_eq ! ( htlc_claim_tx. input[ 1 ] . previous_output. vout, if p2a_anchor { 2 } else { 3 } ) ;
2635
2648
check_spends ! ( htlc_claim_tx, commitment_tx) ;
2636
2649
}
2637
2650
@@ -2681,8 +2694,10 @@ fn do_test_yield_anchors_events(have_htlcs: bool) {
2681
2694
2682
2695
#[ test]
2683
2696
fn test_yield_anchors_events ( ) {
2684
- do_test_yield_anchors_events ( true ) ;
2685
- do_test_yield_anchors_events ( false ) ;
2697
+ do_test_yield_anchors_events ( true , false ) ;
2698
+ do_test_yield_anchors_events ( false , false ) ;
2699
+ do_test_yield_anchors_events ( true , true ) ;
2700
+ do_test_yield_anchors_events ( false , true ) ;
2686
2701
}
2687
2702
2688
2703
#[ test]
0 commit comments