Skip to content

Commit 49b28b0

Browse files
Test that we'll round up blinded intermediate node fees if needed.
See comment in the new test.
1 parent 96f06d3 commit 49b28b0

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,3 +1116,54 @@ fn min_htlc() {
11161116
expect_payment_failed_conditions(&nodes[0], payment_hash, false,
11171117
PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32]));
11181118
}
1119+
1120+
#[test]
1121+
fn high_prop_fees() {
1122+
// Previously, the (rng-found) feerates below caught a bug where an intermediate node would
1123+
// calculate an amt_to_forward that underpaid them by 1 msat, caused by rounding up the outbound
1124+
// amount on top of an already rounded-up total routing fee. Ensure that we'll conditionally round
1125+
// down intermediate nodes' outbound amounts based on whether rounding up will result in
1126+
// undercharging for relay.
1127+
let chanmon_cfgs = create_chanmon_cfgs(5);
1128+
let node_cfgs = create_node_cfgs(5, &chanmon_cfgs);
1129+
1130+
let mut node_1_cfg = test_default_channel_config();
1131+
node_1_cfg.channel_config.forwarding_fee_base_msat = 247371;
1132+
node_1_cfg.channel_config.forwarding_fee_proportional_millionths = 86552;
1133+
1134+
let mut node_2_cfg = test_default_channel_config();
1135+
node_2_cfg.channel_config.forwarding_fee_base_msat = 198921;
1136+
node_2_cfg.channel_config.forwarding_fee_proportional_millionths = 681759;
1137+
1138+
let mut node_3_cfg = test_default_channel_config();
1139+
node_3_cfg.channel_config.forwarding_fee_base_msat = 132845;
1140+
node_3_cfg.channel_config.forwarding_fee_proportional_millionths = 552561;
1141+
1142+
let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, Some(node_1_cfg), Some(node_2_cfg), Some(node_3_cfg), None]);
1143+
let nodes = create_network(5, &node_cfgs, &node_chanmgrs);
1144+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
1145+
let chan_1_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
1146+
let chan_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0);
1147+
let chan_3_4 = create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 1_000_000, 0);
1148+
1149+
let amt_msat = 100_000;
1150+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[4], Some(amt_msat), None);
1151+
let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret,
1152+
chan_1_2.1.contents.htlc_minimum_msat, chan_1_2.1.contents.htlc_maximum_msat,
1153+
vec![nodes[1].node.get_our_node_id(), nodes[2].node.get_our_node_id(),
1154+
nodes[3].node.get_our_node_id(), nodes[4].node.get_our_node_id()],
1155+
&[&chan_1_2.0.contents, &chan_2_3.0.contents, &chan_3_4.0.contents],
1156+
&chanmon_cfgs[4].keys_manager);
1157+
route_params.max_total_routing_fee_msat = None;
1158+
1159+
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
1160+
check_added_monitors(&nodes[0], 1);
1161+
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3], &nodes[4]]], amt_msat, payment_hash, payment_secret);
1162+
nodes[4].node.claim_funds(payment_preimage);
1163+
let expected_path = &[&nodes[1], &nodes[2], &nodes[3], &nodes[4]];
1164+
let expected_route = &[&expected_path[..]];
1165+
let mut args = ClaimAlongRouteArgs::new(&nodes[0], &expected_route[..], payment_preimage)
1166+
.allow_1_msat_fee_overpay();
1167+
let expected_fee = pass_claimed_payment_along_route(args);
1168+
expect_payment_sent(&nodes[0], payment_preimage, Some(Some(expected_fee)), true, true);
1169+
}

0 commit comments

Comments
 (0)