Skip to content

Commit 3ba651c

Browse files
f functional test cleanups
1 parent f26a2d2 commit 3ba651c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ fn test_basic_channel_reserve() {
15551555
}
15561556

15571557
#[test]
1558-
fn test_channel_reserve_violation_close_pending_htlc() {
1558+
fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
15591559
let chanmon_cfgs = create_chanmon_cfgs(3);
15601560
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
15611561
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
@@ -1573,7 +1573,8 @@ fn test_channel_reserve_violation_close_pending_htlc() {
15731573
}}
15741574
};
15751575

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;
15771578
let chan_stat = get_channel_value_stat!(nodes[0], chan_1.2);
15781579
let feerate = get_feerate!(nodes[0], chan_1.2);
15791580

@@ -1595,9 +1596,9 @@ fn test_channel_reserve_violation_close_pending_htlc() {
15951596

15961597
// Attempt to trigger a channel reserve violation --> payment failure.
15971598
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);
15991600

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()
16011602
let secp_ctx = Secp256k1::new();
16021603
let session_priv = SecretKey::from_slice(&{
16031604
let mut session_key = [0; 32];
@@ -1611,7 +1612,7 @@ fn test_channel_reserve_violation_close_pending_htlc() {
16111612
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route_2.paths[0], &session_priv).unwrap();
16121613
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route_2.paths[0], recv_value_2, &None, cur_height).unwrap();
16131614
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 {
16151616
channel_id: chan_1.2,
16161617
htlc_id: 1,
16171618
amount_msat: htlc_msat,
@@ -1620,7 +1621,7 @@ fn test_channel_reserve_violation_close_pending_htlc() {
16201621
onion_routing_packet: onion_packet,
16211622
};
16221623

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);
16241625
// Check that the payment failed and the channel is closed in response to the malicious UpdateAdd.
16251626
nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Remote HTLC add would put them under remote reserve value".to_string(), 1);
16261627
assert_eq!(nodes[1].node.list_channels().len(), 1);
@@ -1635,7 +1636,7 @@ fn commit_tx_fee_msat(feerate: u64, num_htlcs: u64) -> u64 {
16351636
}
16361637

16371638
#[test]
1638-
fn channel_reserve_test() {
1639+
fn test_channel_reserve_holding_cell_htlcs() {
16391640
let chanmon_cfgs = create_chanmon_cfgs(3);
16401641
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
16411642
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
@@ -1670,7 +1671,7 @@ fn channel_reserve_test() {
16701671
}
16711672

16721673
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;
16741675
let feerate = get_feerate!(nodes[0], chan_1.2);
16751676

16761677
let recv_value_0 = stat01.their_max_htlc_value_in_flight_msat - total_fee_msat;
@@ -1692,7 +1693,9 @@ fn channel_reserve_test() {
16921693
// 3 for the 3 HTLCs that will be sent, 2* and +1 for the fee spike reserve.
16931694
// Also, ensure that each payment has enough to be over the dust limit to
16941695
// 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 {
16961699
break;
16971700
}
16981701
send_payment(&nodes[0], &vec![&nodes[1], &nodes[2]][..], recv_value_0, recv_value_0);
@@ -1713,6 +1716,15 @@ fn channel_reserve_test() {
17131716

17141717
// adding pending output.
17151718
// 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.
17161728
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;
17171729
let amt_msat_1 = recv_value_1 + total_fee_msat;
17181730

0 commit comments

Comments
 (0)