@@ -6,8 +6,8 @@ use crate::ln::chan_utils::{
6
6
COMMITMENT_TX_WEIGHT_PER_HTLC ,
7
7
} ;
8
8
use crate :: ln:: channel:: {
9
- get_holder_selected_channel_reserve_satoshis, CONCURRENT_INBOUND_HTLC_FEE_BUFFER ,
10
- MIN_AFFORDABLE_HTLC_COUNT ,
9
+ get_holder_selected_channel_reserve_satoshis, ANCHOR_OUTPUT_VALUE_SATOSHI ,
10
+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER , MIN_AFFORDABLE_HTLC_COUNT ,
11
11
} ;
12
12
use crate :: ln:: channelmanager:: PaymentId ;
13
13
use crate :: ln:: functional_test_utils:: * ;
@@ -388,11 +388,22 @@ pub fn test_update_fee_vanilla() {
388
388
check_added_monitors ( & nodes[ 1 ] , 1 ) ;
389
389
}
390
390
391
- #[ xtest( feature = "_externalize_tests" ) ]
392
- pub fn test_update_fee_that_funder_cannot_afford ( ) {
391
+ pub fn do_test_update_fee_that_funder_cannot_afford ( channel_type_features : ChannelTypeFeatures ) {
393
392
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
394
393
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
395
- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
394
+
395
+ let mut default_config = test_default_channel_config ( ) ;
396
+ if channel_type_features == ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) {
397
+ default_config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
398
+ // this setting is also needed to create an anchor channel
399
+ default_config. manually_accept_inbound_channels = true ;
400
+ }
401
+
402
+ let node_chanmgrs = create_node_chanmgrs (
403
+ 2 ,
404
+ & node_cfgs,
405
+ & [ Some ( default_config. clone ( ) ) , Some ( default_config. clone ( ) ) ] ,
406
+ ) ;
396
407
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
397
408
398
409
let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
@@ -409,22 +420,26 @@ pub fn test_update_fee_that_funder_cannot_afford() {
409
420
) ;
410
421
let channel_id = chan. 2 ;
411
422
let secp_ctx = Secp256k1 :: new ( ) ;
412
- let default_config = UserConfig :: default ( ) ;
413
423
let bs_channel_reserve_sats =
414
424
get_holder_selected_channel_reserve_satoshis ( channel_value, & default_config) ;
415
-
416
- let channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
425
+ let ( anchor_outputs_value_sats, outputs_num_no_htlcs) =
426
+ if channel_type_features. supports_anchors_zero_fee_htlc_tx ( ) {
427
+ ( ANCHOR_OUTPUT_VALUE_SATOSHI * 2 , 4 )
428
+ } else {
429
+ ( 0 , 2 )
430
+ } ;
417
431
418
432
// Calculate the maximum feerate that A can afford. Note that we don't send an update_fee
419
433
// CONCURRENT_INBOUND_HTLC_FEE_BUFFER HTLCs before actually running out of local balance, so we
420
434
// calculate two different feerates here - the expected local limit as well as the expected
421
435
// remote limit.
422
- let feerate = ( ( channel_value - bs_channel_reserve_sats - push_sats) * 1000
423
- / ( commitment_tx_base_weight ( & channel_type_features)
424
- + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) )
425
- as u32 ;
426
- let non_buffer_feerate = ( ( channel_value - bs_channel_reserve_sats - push_sats) * 1000
427
- / commitment_tx_base_weight ( & channel_type_features) ) as u32 ;
436
+ let feerate =
437
+ ( ( channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
438
+ / ( commitment_tx_base_weight ( & channel_type_features)
439
+ + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC ) ) as u32 ;
440
+ let non_buffer_feerate =
441
+ ( ( channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
442
+ / commitment_tx_base_weight ( & channel_type_features) ) as u32 ;
428
443
{
429
444
let mut feerate_lock = chanmon_cfgs[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) ;
430
445
* feerate_lock = feerate;
@@ -441,8 +456,8 @@ pub fn test_update_fee_that_funder_cannot_afford() {
441
456
{
442
457
let commitment_tx = get_local_commitment_txn ! ( nodes[ 1 ] , channel_id) [ 0 ] . clone ( ) ;
443
458
444
- //We made sure neither party's funds are below the dust limit and there are no HTLCs here
445
- assert_eq ! ( commitment_tx. output. len( ) , 2 ) ;
459
+ // We made sure neither party's funds are below the dust limit and there are no HTLCs here
460
+ assert_eq ! ( commitment_tx. output. len( ) , outputs_num_no_htlcs ) ;
446
461
let total_fee: u64 = commit_tx_fee_msat ( feerate, 0 , & channel_type_features) / 1000 ;
447
462
let mut actual_fee =
448
463
commitment_tx. output . iter ( ) . fold ( 0 , |acc, output| acc + output. value . to_sat ( ) ) ;
@@ -486,8 +501,8 @@ pub fn test_update_fee_that_funder_cannot_afford() {
486
501
& remote_point,
487
502
push_sats,
488
503
channel_value
489
- - push_sats - commit_tx_fee_msat ( non_buffer_feerate + 4 , 0 , & channel_type_features )
490
- / 1000 ,
504
+ - push_sats - anchor_outputs_value_sats
505
+ - commit_tx_fee_msat ( non_buffer_feerate + 4 , 0 , & channel_type_features ) / 1000 ,
491
506
non_buffer_feerate + 4 ,
492
507
nondust_htlcs,
493
508
& local_chan. funding ( ) . channel_transaction_parameters . as_counterparty_broadcastable ( ) ,
@@ -526,6 +541,14 @@ pub fn test_update_fee_that_funder_cannot_afford() {
526
541
check_closed_event ! ( nodes[ 1 ] , 1 , reason, [ node_a_id] , channel_value) ;
527
542
}
528
543
544
+ #[ xtest( feature = "_externalize_tests" ) ]
545
+ pub fn test_update_fee_that_funder_cannot_afford ( ) {
546
+ do_test_update_fee_that_funder_cannot_afford ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ;
547
+ do_test_update_fee_that_funder_cannot_afford (
548
+ ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ,
549
+ ) ;
550
+ }
551
+
529
552
#[ xtest( feature = "_externalize_tests" ) ]
530
553
pub fn test_update_fee_that_saturates_subs ( ) {
531
554
// Check that when a remote party sends us an `update_fee` message that results in a total fee
0 commit comments