@@ -1555,7 +1555,7 @@ fn test_basic_channel_reserve() {
1555
1555
}
1556
1556
1557
1557
#[ test]
1558
- fn test_channel_reserve_violation_close_pending_htlc ( ) {
1558
+ fn test_chan_reserve_violation_inbound_htlc_inbound_chan ( ) {
1559
1559
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1560
1560
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
1561
1561
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
@@ -1573,7 +1573,8 @@ fn test_channel_reserve_violation_close_pending_htlc() {
1573
1573
} }
1574
1574
} ;
1575
1575
1576
- let total_fee_msat = ( nodes. len ( ) - 2 ) as u64 * 239 ;
1576
+ let feemsat = 239 ;
1577
+ let total_fee_msat = ( nodes. len ( ) - 2 ) as u64 * feemsat;
1577
1578
let chan_stat = get_channel_value_stat ! ( nodes[ 0 ] , chan_1. 2 ) ;
1578
1579
let feerate = get_feerate ! ( nodes[ 0 ] , chan_1. 2 ) ;
1579
1580
@@ -1595,9 +1596,9 @@ fn test_channel_reserve_violation_close_pending_htlc() {
1595
1596
1596
1597
// Attempt to trigger a channel reserve violation --> payment failure.
1597
1598
let recv_value_2 = chan_stat. value_to_self_msat - amt_msat_1 - chan_stat. channel_reserve_msat - total_fee_msat - commit_tx_fee_msat ( feerate, 2 ) + 1 ;
1598
- let ( route_2, our_payment_hash_1 , _) = get_route_and_payment_hash ! ( recv_value_2) ;
1599
+ let ( route_2, _ , _) = get_route_and_payment_hash ! ( recv_value_2) ;
1599
1600
1600
- // Need to manually create update_add_htlc messages to go around the channel reserve check in send_htlc()
1601
+ // Need to manually create the update_add_htlc message to go around the channel reserve check in send_htlc()
1601
1602
let secp_ctx = Secp256k1 :: new ( ) ;
1602
1603
let session_priv = SecretKey :: from_slice ( & {
1603
1604
let mut session_key = [ 0 ; 32 ] ;
@@ -1611,7 +1612,7 @@ fn test_channel_reserve_violation_close_pending_htlc() {
1611
1612
let onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route_2. paths [ 0 ] , & session_priv) . unwrap ( ) ;
1612
1613
let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( & route_2. paths [ 0 ] , recv_value_2, & None , cur_height) . unwrap ( ) ;
1613
1614
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & our_payment_hash_1) ;
1614
- let msg_1 = msgs:: UpdateAddHTLC {
1615
+ let msg = msgs:: UpdateAddHTLC {
1615
1616
channel_id : chan_1. 2 ,
1616
1617
htlc_id : 1 ,
1617
1618
amount_msat : htlc_msat,
@@ -1620,7 +1621,7 @@ fn test_channel_reserve_violation_close_pending_htlc() {
1620
1621
onion_routing_packet : onion_packet,
1621
1622
} ;
1622
1623
1623
- nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & msg_1 ) ;
1624
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & msg ) ;
1624
1625
// Check that the payment failed and the channel is closed in response to the malicious UpdateAdd.
1625
1626
nodes[ 1 ] . logger . assert_log ( "lightning::ln::channelmanager" . to_string ( ) , "Remote HTLC add would put them under remote reserve value" . to_string ( ) , 1 ) ;
1626
1627
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 1 ) ;
@@ -1635,7 +1636,7 @@ fn commit_tx_fee_msat(feerate: u64, num_htlcs: u64) -> u64 {
1635
1636
}
1636
1637
1637
1638
#[ test]
1638
- fn channel_reserve_test ( ) {
1639
+ fn test_channel_reserve_holding_cell_htlcs ( ) {
1639
1640
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
1640
1641
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
1641
1642
let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
@@ -1670,7 +1671,7 @@ fn channel_reserve_test() {
1670
1671
}
1671
1672
1672
1673
let feemsat = 239 ; // somehow we know?
1673
- let total_fee_msat = ( nodes. len ( ) - 2 ) as u64 * 239 ;
1674
+ let total_fee_msat = ( nodes. len ( ) - 2 ) as u64 * feemsat ;
1674
1675
let feerate = get_feerate ! ( nodes[ 0 ] , chan_1. 2 ) ;
1675
1676
1676
1677
let recv_value_0 = stat01. their_max_htlc_value_in_flight_msat - total_fee_msat;
@@ -1692,7 +1693,9 @@ fn channel_reserve_test() {
1692
1693
// 3 for the 3 HTLCs that will be sent, 2* and +1 for the fee spike reserve.
1693
1694
// Also, ensure that each payment has enough to be over the dust limit to
1694
1695
// ensure it'll be included in each commit tx fee calculation.
1695
- if stat01. value_to_self_msat < stat01. channel_reserve_msat + 2 * commit_tx_fee_msat ( feerate, 3 + 1 ) + 3 * ( stat01. their_dust_limit_msat + 1000 ) + amt_msat {
1696
+ let commit_tx_fee_all_htlcs = 2 * commit_tx_fee_msat ( feerate, 3 + 1 ) ;
1697
+ let ensure_htlc_amounts_above_dust_buffer = 3 * ( stat01. their_dust_limit_msat + 1000 ) ;
1698
+ if stat01. value_to_self_msat < stat01. channel_reserve_msat + commit_tx_fee_all_htlcs + ensure_htlc_amounts_above_dust_buffer + amt_msat {
1696
1699
break ;
1697
1700
}
1698
1701
send_payment ( & nodes[ 0 ] , & vec ! [ & nodes[ 1 ] , & nodes[ 2 ] ] [ ..] , recv_value_0, recv_value_0) ;
@@ -1713,6 +1716,15 @@ fn channel_reserve_test() {
1713
1716
1714
1717
// adding pending output.
1715
1718
// 2* and +1 HTLCs on the commit tx fee for the fee spike reserve.
1719
+ // The reason we're dividing by two here is as follows: the dividend is the total outbound liquidity
1720
+ // after fees, the channel reserve, and the fee spike buffer are removed. We eventually want to
1721
+ // divide this quantity into 3 portions, that will each be sent in an HTLC. This allows us
1722
+ // to test channel channel reserve policy at the edges of what amount is sendable, i.e.
1723
+ // cases where 1 msat over X amount will cause a payment failure, but anything less than
1724
+ // that can be sent successfully. So, dividing by two is a somewhat arbitrary way of getting
1725
+ // the amount of the first of these aforementioned 3 payments. The reason we split into 3 payments
1726
+ // is to test the behavior of the holding cell with respect to channel reserve and commit tx fee
1727
+ // policy.
1716
1728
let recv_value_1 = ( stat01. value_to_self_msat - stat01. channel_reserve_msat - total_fee_msat - 2 * commit_tx_fee_msat ( feerate, 2 + 1 ) ) /2 ;
1717
1729
let amt_msat_1 = recv_value_1 + total_fee_msat;
1718
1730
0 commit comments