12
12
use crate :: sign:: { ecdsa:: EcdsaChannelSigner , OutputSpender , SpendableOutputDescriptor } ;
13
13
use crate :: chain:: channelmonitor:: { ANTI_REORG_DELAY , LATENCY_GRACE_PERIOD_BLOCKS , Balance , BalanceSource } ;
14
14
use crate :: chain:: transaction:: OutPoint ;
15
- use crate :: chain:: chaininterface:: { LowerBoundedFeeEstimator , compute_feerate_sat_per_1000_weight} ;
15
+ use crate :: chain:: chaininterface:: { ConfirmationTarget , LowerBoundedFeeEstimator , compute_feerate_sat_per_1000_weight} ;
16
16
use crate :: events:: bump_transaction:: { BumpTransactionEvent , WalletSource } ;
17
17
use crate :: events:: { Event , MessageSendEvent , MessageSendEventsProvider , ClosureReason , HTLCDestination } ;
18
18
use crate :: ln:: channel;
@@ -2458,8 +2458,7 @@ fn test_monitor_timer_based_claim() {
2458
2458
do_test_monitor_rebroadcast_pending_claims ( true ) ;
2459
2459
}
2460
2460
2461
- #[ test]
2462
- fn test_yield_anchors_events ( ) {
2461
+ fn do_test_yield_anchors_events ( have_htlcs : bool ) {
2463
2462
// Tests that two parties supporting anchor outputs can open a channel, route payments over
2464
2463
// it, and finalize its resolution uncooperatively. Once the HTLCs are locked in, one side will
2465
2464
// force close once the HTLCs expire. The force close should stem from an event emitted by LDK,
@@ -2478,45 +2477,72 @@ fn test_yield_anchors_events() {
2478
2477
let ( _, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value (
2479
2478
& nodes, 0 , 1 , 1_000_000 , 500_000_000
2480
2479
) ;
2481
- let ( payment_preimage_1, payment_hash_1, ..) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
2482
- let ( payment_preimage_2, payment_hash_2, ..) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 2_000_000 ) ;
2480
+ let mut payment_preimage_1 = None ;
2481
+ let mut payment_hash_1 = None ;
2482
+ let mut payment_preimage_2 = None ;
2483
+ let mut payment_hash_2 = None ;
2484
+ if have_htlcs {
2485
+ let ( preimage_1, hash_1, ..) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
2486
+ let ( preimage_2, hash_2, ..) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 2_000_000 ) ;
2487
+ payment_preimage_1 = Some ( preimage_1) ;
2488
+ payment_hash_1 = Some ( hash_1) ;
2489
+ payment_preimage_2 = Some ( preimage_2) ;
2490
+ payment_hash_2 = Some ( hash_2) ;
2491
+ }
2483
2492
2484
2493
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
2485
2494
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
2486
2495
2487
- * nodes[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) *= 2 ;
2496
+ // Note that if we use the wrong target, we will immediately broadcast the commitment
2497
+ // transaction as no bump is required.
2498
+ if have_htlcs {
2499
+ nodes[ 0 ] . fee_estimator . target_override . lock ( ) . unwrap ( ) . insert ( ConfirmationTarget :: UrgentOnChainSweep , 500 ) ;
2500
+ } else {
2501
+ nodes[ 0 ] . fee_estimator . target_override . lock ( ) . unwrap ( ) . insert ( ConfirmationTarget :: OutputSpendingFee , 500 ) ;
2502
+ }
2488
2503
2489
2504
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
2490
2505
assert ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcast( ) . is_empty( ) ) ;
2491
2506
2492
2507
connect_blocks ( & nodes[ 1 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
2508
+ if !have_htlcs {
2509
+ nodes[ 1 ] . node . force_close_broadcasting_latest_txn ( & chan_id, & nodes[ 0 ] . node . get_our_node_id ( ) , "" . to_string ( ) ) . unwrap ( ) ;
2510
+ }
2493
2511
{
2494
2512
let txn = nodes[ 1 ] . tx_broadcaster . txn_broadcast ( ) ;
2495
2513
assert_eq ! ( txn. len( ) , 1 ) ;
2496
2514
check_spends ! ( txn[ 0 ] , funding_tx) ;
2497
2515
}
2498
2516
2499
- get_monitor ! ( nodes[ 0 ] , chan_id) . provide_payment_preimage (
2500
- & payment_hash_2, & payment_preimage_2, & node_cfgs[ 0 ] . tx_broadcaster ,
2501
- & LowerBoundedFeeEstimator :: new ( node_cfgs[ 0 ] . fee_estimator ) , & nodes[ 0 ] . logger
2502
- ) ;
2503
- get_monitor ! ( nodes[ 1 ] , chan_id) . provide_payment_preimage (
2504
- & payment_hash_1, & payment_preimage_1, & node_cfgs[ 1 ] . tx_broadcaster ,
2505
- & LowerBoundedFeeEstimator :: new ( node_cfgs[ 1 ] . fee_estimator ) , & nodes[ 1 ] . logger
2506
- ) ;
2517
+ if have_htlcs {
2518
+ get_monitor ! ( nodes[ 0 ] , chan_id) . provide_payment_preimage (
2519
+ & payment_hash_2. unwrap ( ) , & payment_preimage_2. unwrap ( ) , & node_cfgs[ 0 ] . tx_broadcaster ,
2520
+ & LowerBoundedFeeEstimator :: new ( node_cfgs[ 0 ] . fee_estimator ) , & nodes[ 0 ] . logger
2521
+ ) ;
2522
+ get_monitor ! ( nodes[ 1 ] , chan_id) . provide_payment_preimage (
2523
+ & payment_hash_1. unwrap ( ) , & payment_preimage_1. unwrap ( ) , & node_cfgs[ 1 ] . tx_broadcaster ,
2524
+ & LowerBoundedFeeEstimator :: new ( node_cfgs[ 1 ] . fee_estimator ) , & nodes[ 1 ] . logger
2525
+ ) ;
2526
+ } else {
2527
+ nodes[ 0 ] . node . force_close_broadcasting_latest_txn ( & chan_id, & nodes[ 1 ] . node . get_our_node_id ( ) , "" . to_string ( ) ) . unwrap ( ) ;
2528
+ }
2507
2529
2508
2530
check_closed_broadcast ( & nodes[ 0 ] , 1 , true ) ;
2509
2531
let a_events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2510
2532
assert_eq ! ( a_events. len( ) , if have_htlcs { 3 } else { 1 } ) ;
2511
- assert ! ( a_events. iter( ) . any( |ev| matches!( ev, Event :: PendingHTLCsForwardable { .. } ) ) ) ;
2512
- assert ! ( a_events. iter( ) . any( |ev| matches!( ev, Event :: HTLCHandlingFailed { .. } ) ) ) ;
2533
+ if have_htlcs {
2534
+ assert ! ( a_events. iter( ) . any( |ev| matches!( ev, Event :: PendingHTLCsForwardable { .. } ) ) ) ;
2535
+ assert ! ( a_events. iter( ) . any( |ev| matches!( ev, Event :: HTLCHandlingFailed { .. } ) ) ) ;
2536
+ }
2513
2537
assert ! ( a_events. iter( ) . any( |ev| matches!( ev, Event :: ChannelClosed { .. } ) ) ) ;
2514
2538
2515
2539
check_closed_broadcast ( & nodes[ 1 ] , 1 , true ) ;
2516
2540
let b_events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
2517
2541
assert_eq ! ( b_events. len( ) , if have_htlcs { 3 } else { 1 } ) ;
2518
- assert ! ( b_events. iter( ) . any( |ev| matches!( ev, Event :: PendingHTLCsForwardable { .. } ) ) ) ;
2519
- assert ! ( b_events. iter( ) . any( |ev| matches!( ev, Event :: HTLCHandlingFailed { .. } ) ) ) ;
2542
+ if have_htlcs {
2543
+ assert ! ( b_events. iter( ) . any( |ev| matches!( ev, Event :: PendingHTLCsForwardable { .. } ) ) ) ;
2544
+ assert ! ( b_events. iter( ) . any( |ev| matches!( ev, Event :: HTLCHandlingFailed { .. } ) ) ) ;
2545
+ }
2520
2546
assert ! ( b_events. iter( ) . any( |ev| matches!( ev, Event :: ChannelClosed { .. } ) ) ) ;
2521
2547
2522
2548
let mut holder_events = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
@@ -2546,14 +2572,21 @@ fn test_yield_anchors_events() {
2546
2572
} ;
2547
2573
check_spends ! ( commitment_tx, funding_tx) ;
2548
2574
2549
- assert_eq ! ( commitment_tx. output[ 2 ] . value. to_sat( ) , 1_000 ) ; // HTLC A -> B
2550
- assert_eq ! ( commitment_tx. output[ 3 ] . value. to_sat( ) , 2_000 ) ; // HTLC B -> A
2575
+ if have_htlcs {
2576
+ assert_eq ! ( commitment_tx. output[ 2 ] . value. to_sat( ) , 1_000 ) ; // HTLC A -> B
2577
+ assert_eq ! ( commitment_tx. output[ 3 ] . value. to_sat( ) , 2_000 ) ; // HTLC B -> A
2578
+ }
2551
2579
2552
2580
mine_transactions ( & nodes[ 0 ] , & [ & commitment_tx, & anchor_tx] ) ;
2553
2581
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
2554
2582
mine_transactions ( & nodes[ 1 ] , & [ & commitment_tx, & anchor_tx] ) ;
2555
2583
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2556
2584
2585
+ if !have_htlcs {
2586
+ // If we don't have any HTLCs, we're done, the rest of the test is about HTLC transactions
2587
+ return ;
2588
+ }
2589
+
2557
2590
{
2558
2591
let mut txn = nodes[ 1 ] . tx_broadcaster . unique_txn_broadcast ( ) ;
2559
2592
assert_eq ! ( txn. len( ) , if nodes[ 1 ] . connect_style. borrow( ) . updates_best_block_first( ) { 3 } else { 2 } ) ;
@@ -2568,8 +2601,8 @@ fn test_yield_anchors_events() {
2568
2601
assert_eq ! ( htlc_timeout_tx. input[ 0 ] . previous_output. vout, 2 ) ;
2569
2602
check_spends ! ( htlc_timeout_tx, commitment_tx) ;
2570
2603
2571
- if let Some ( commitment_tx ) = txn. pop ( ) {
2572
- check_spends ! ( commitment_tx , funding_tx) ;
2604
+ if let Some ( new_commitment_tx ) = txn. pop ( ) {
2605
+ check_spends ! ( new_commitment_tx , funding_tx) ;
2573
2606
}
2574
2607
}
2575
2608
@@ -2614,7 +2647,12 @@ fn test_yield_anchors_events() {
2614
2647
_ => panic ! ( "Unexpected event" ) ,
2615
2648
}
2616
2649
}
2650
+ }
2617
2651
2652
+ #[ test]
2653
+ fn test_yield_anchors_events ( ) {
2654
+ do_test_yield_anchors_events ( true ) ;
2655
+ do_test_yield_anchors_events ( false ) ;
2618
2656
}
2619
2657
2620
2658
#[ test]
0 commit comments