Skip to content

Commit 029902a

Browse files
Test that we'll round up blinded intermediate node fees if needed.
See comment in the new test.
1 parent 19d574f commit 029902a

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

0 commit comments

Comments
 (0)