@@ -584,11 +584,14 @@ fn test_update_fee_that_funder_cannot_afford() {
584
584
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
585
585
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
586
586
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
587
- let channel_value = 1888 ;
588
- let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , channel_value, 700000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
587
+ let channel_value = 5000 ;
588
+ let push_sats = 700 ;
589
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , channel_value, push_sats * 1000 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
589
590
let channel_id = chan. 2 ;
591
+ let bs_channel_reserve_sats = Channel :: < EnforcingSigner > :: get_holder_selected_channel_reserve_satoshis ( channel_value) ;
590
592
591
- let feerate = 260 ;
593
+ // Calculate the maximum feerate that A can afford:
594
+ let feerate = ( ( channel_value - bs_channel_reserve_sats - push_sats) * 1000 / COMMITMENT_TX_BASE_WEIGHT ) as u32 ;
592
595
{
593
596
let mut feerate_lock = chanmon_cfgs[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) ;
594
597
* feerate_lock = feerate;
@@ -601,24 +604,22 @@ fn test_update_fee_that_funder_cannot_afford() {
601
604
602
605
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , update_msg. commitment_signed, false ) ;
603
606
604
- //Confirm that the new fee based on the last local commitment txn is what we expected based on the feerate of 260 set above.
605
- //This value results in a fee that is exactly what the funder can afford (277 sat + 1000 sat channel reserve)
607
+ // Confirm that the new fee based on the last local commitment txn is what we expected based on the feerate set above.
606
608
{
607
609
let commitment_tx = get_local_commitment_txn ! ( nodes[ 1 ] , channel_id) [ 0 ] . clone ( ) ;
608
610
609
- //We made sure neither party's funds are below the dust limit so -2 non-HTLC txns from number of outputs
610
- let num_htlcs = commitment_tx. output . len ( ) - 2 ;
611
- let total_fee: u64 = feerate as u64 * ( COMMITMENT_TX_BASE_WEIGHT + ( num_htlcs as u64 ) * COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 ;
611
+ //We made sure neither party's funds are below the dust limit and there are no HTLCs here
612
+ assert_eq ! ( commitment_tx. output. len( ) , 2 ) ;
613
+ let total_fee: u64 = feerate as u64 * COMMITMENT_TX_BASE_WEIGHT / 1000 ;
612
614
let mut actual_fee = commitment_tx. output . iter ( ) . fold ( 0 , |acc, output| acc + output. value ) ;
613
615
actual_fee = channel_value - actual_fee;
614
616
assert_eq ! ( total_fee, actual_fee) ;
615
617
}
616
618
617
- //Add 2 to the previous fee rate to the final fee increases by 1 (with no HTLCs the fee is essentially
618
- //fee_rate*(724/1000) so the increment of 1*0.724 is rounded back down)
619
619
{
620
+ // Increment the feerate by a small constant, accouting for rounding errors
620
621
let mut feerate_lock = chanmon_cfgs[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) ;
621
- * feerate_lock = feerate + 2 ;
622
+ * feerate_lock += 4 ;
622
623
}
623
624
nodes[ 0 ] . node . timer_tick_occurred ( ) ;
624
625
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
0 commit comments