@@ -1522,7 +1522,6 @@ fn test_duplicate_htlc_different_direction_onchain() {
1522
1522
}
1523
1523
1524
1524
fn do_channel_reserve_test ( test_recv : bool ) {
1525
-
1526
1525
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1527
1526
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
1528
1527
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
@@ -1556,6 +1555,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1556
1555
1557
1556
let feemsat = 239 ; // somehow we know?
1558
1557
let total_fee_msat = ( nodes. len ( ) - 2 ) as u64 * 239 ;
1558
+ let fee_spike_reserve = 2 * get_feerate ! ( nodes[ 0 ] , chan_1. 2 ) ;
1559
1559
1560
1560
let recv_value_0 = stat01. their_max_htlc_value_in_flight_msat - total_fee_msat;
1561
1561
@@ -1577,7 +1577,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1577
1577
// nodes[0]'s wealth
1578
1578
loop {
1579
1579
let amt_msat = recv_value_0 + total_fee_msat;
1580
- if stat01. value_to_self_msat - amt_msat < stat01. channel_reserve_msat + stat01. commit_tx_fee_outbound {
1580
+ if stat01. value_to_self_msat - amt_msat < stat01. channel_reserve_msat + stat01. commit_tx_fee_outbound + fee_spike_reserve {
1581
1581
break ;
1582
1582
}
1583
1583
send_payment ( & nodes[ 0 ] , & vec ! [ & nodes[ 1 ] , & nodes[ 2 ] ] [ ..] , recv_value_0, recv_value_0) ;
@@ -1598,7 +1598,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1598
1598
}
1599
1599
1600
1600
{
1601
- let recv_value = stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound ;
1601
+ let recv_value = stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound - fee_spike_reserve ;
1602
1602
// attempt to get channel_reserve violation
1603
1603
let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value + 1 ) ;
1604
1604
let err = nodes[ 0 ] . node . send_payment ( route. clone ( ) , our_payment_hash) . err ( ) . unwrap ( ) ;
@@ -1612,7 +1612,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1612
1612
1613
1613
// adding pending output
1614
1614
let commit_tx_fee_1_acked_htlc = get_feerate ! ( nodes[ 0 ] , chan_1. 2 ) * COMMITMENT_TX_WEIGHT_PER_HTLC ;
1615
- let recv_value_1 = ( stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound - commit_tx_fee_1_acked_htlc) /2 ;
1615
+ let recv_value_1 = ( stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound - commit_tx_fee_1_acked_htlc - fee_spike_reserve ) /2 ;
1616
1616
let amt_msat_1 = recv_value_1 + total_fee_msat;
1617
1617
1618
1618
let ( route_1, our_payment_hash_1, our_payment_preimage_1) = get_route_and_payment_hash ! ( recv_value_1) ;
@@ -1627,7 +1627,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1627
1627
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event_1. msgs [ 0 ] ) ;
1628
1628
1629
1629
// channel reserve test with htlc pending output > 0
1630
- let recv_value_2 = stat01. value_to_self_msat - amt_msat_1 - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound - commit_tx_fee_1_acked_htlc;
1630
+ let recv_value_2 = stat01. value_to_self_msat - amt_msat_1 - stat01. channel_reserve_msat - total_fee_msat - stat01. commit_tx_fee_outbound - commit_tx_fee_1_acked_htlc - fee_spike_reserve ;
1631
1631
{
1632
1632
let ( route, our_payment_hash, _) = get_route_and_payment_hash ! ( recv_value_2 + 1 ) ;
1633
1633
match nodes[ 0 ] . node . send_payment ( route, our_payment_hash) . err ( ) . unwrap ( ) {
@@ -1684,7 +1684,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1684
1684
let recv_value_22 = recv_value_2 - recv_value_21 - total_fee_msat - commit_tx_fee_1_holding_cell_htlc;
1685
1685
{
1686
1686
let stat = get_channel_value_stat ! ( nodes[ 0 ] , chan_1. 2 ) ;
1687
- assert_eq ! ( stat. value_to_self_msat - ( stat. pending_outbound_htlcs_amount_msat + recv_value_21 + recv_value_22 + total_fee_msat + total_fee_msat + commit_tx_fee_1_holding_cell_htlc + commit_tx_fee_1_acked_htlc + stat01. commit_tx_fee_outbound) , stat. channel_reserve_msat) ;
1687
+ assert_eq ! ( stat. value_to_self_msat - ( stat. pending_outbound_htlcs_amount_msat + recv_value_21 + recv_value_22 + total_fee_msat + total_fee_msat + commit_tx_fee_1_holding_cell_htlc + commit_tx_fee_1_acked_htlc + stat01. commit_tx_fee_outbound + fee_spike_reserve ) , stat. channel_reserve_msat) ;
1688
1688
}
1689
1689
1690
1690
// now see if they go through on both sides
@@ -1794,7 +1794,7 @@ fn do_channel_reserve_test(test_recv: bool) {
1794
1794
let expected_value_to_self = stat01. value_to_self_msat - ( recv_value_1 + total_fee_msat) - ( recv_value_21 + total_fee_msat) - ( recv_value_22 + total_fee_msat) - ( recv_value_3 + total_fee_msat) ;
1795
1795
let stat0 = get_channel_value_stat ! ( nodes[ 0 ] , chan_1. 2 ) ;
1796
1796
assert_eq ! ( stat0. value_to_self_msat, expected_value_to_self) ;
1797
- assert_eq ! ( stat0. value_to_self_msat, stat0. channel_reserve_msat + stat0. commit_tx_fee_outbound) ;
1797
+ assert_eq ! ( stat0. value_to_self_msat, stat0. channel_reserve_msat + stat0. commit_tx_fee_outbound + fee_spike_reserve ) ;
1798
1798
1799
1799
let stat2 = get_channel_value_stat ! ( nodes[ 2 ] , chan_2. 2 ) ;
1800
1800
assert_eq ! ( stat2. value_to_self_msat, stat22. value_to_self_msat + recv_value_1 + recv_value_21 + recv_value_22 + recv_value_3) ;
0 commit comments