Skip to content

Commit 1ac53ed

Browse files
authored
Merge pull request #2417 from tnull/2023-07-max-total-fee
Add config option to set maximum total routing fee
2 parents 827b17c + 6765767 commit 1ac53ed

File tree

7 files changed

+396
-144
lines changed

7 files changed

+396
-144
lines changed

lightning-invoice/src/payment.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ fn pay_invoice_using_amount<P: Deref>(
116116
if let Some(features) = invoice.features() {
117117
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
118118
}
119-
let route_params = RouteParameters {
120-
payment_params,
121-
final_value_msat: amount_msats,
122-
};
119+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msats);
123120

124121
payer.send_payment(payment_hash, recipient_onion, payment_id, route_params, retry_strategy)
125122
}
@@ -148,7 +145,7 @@ pub fn preflight_probe_invoice<C: AChannelManager>(
148145
if let Some(features) = invoice.features() {
149146
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
150147
}
151-
let route_params = RouteParameters { payment_params, final_value_msat: amount_msat };
148+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msat);
152149

153150
channelmanager.get_cm().send_preflight_probes(route_params, liquidity_limit_multiplier)
154151
.map_err(ProbingError::Sending)
@@ -178,7 +175,7 @@ pub fn preflight_probe_zero_value_invoice<C: AChannelManager>(
178175
if let Some(features) = invoice.features() {
179176
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
180177
}
181-
let route_params = RouteParameters { payment_params, final_value_msat: amount_msat };
178+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msat);
182179

183180
channelmanager.get_cm().send_preflight_probes(route_params, liquidity_limit_multiplier)
184181
.map_err(ProbingError::Sending)

lightning/src/ln/blinded_payment_tests.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ fn do_one_hop_blinded_path(success: bool) {
4747
nodes[1].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[1].keys_manager, &secp_ctx
4848
).unwrap();
4949

50-
let route_params = RouteParameters {
51-
payment_params: PaymentParameters::blinded(vec![blinded_path]),
52-
final_value_msat: amt_msat
53-
};
50+
let route_params = RouteParameters::from_payment_params_and_value(
51+
PaymentParameters::blinded(vec![blinded_path]),
52+
amt_msat,
53+
);
5454
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(),
5555
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
5656
check_added_monitors(&nodes[0], 1);
@@ -90,11 +90,11 @@ fn mpp_to_one_hop_blinded_path() {
9090

9191
let bolt12_features: Bolt12InvoiceFeatures =
9292
channelmanager::provided_invoice_features(&UserConfig::default()).to_context();
93-
let route_params = RouteParameters {
94-
payment_params: PaymentParameters::blinded(vec![blinded_path])
93+
let route_params = RouteParameters::from_payment_params_and_value(
94+
PaymentParameters::blinded(vec![blinded_path])
9595
.with_bolt12_features(bolt12_features).unwrap(),
96-
final_value_msat: amt_msat,
97-
};
96+
amt_msat,
97+
);
9898
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
9999
check_added_monitors(&nodes[0], 2);
100100

lightning/src/ln/channelmanager.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,7 @@ where
35433543
let payment_params =
35443544
PaymentParameters::from_node_id(node_id, final_cltv_expiry_delta);
35453545

3546-
let route_params = RouteParameters { payment_params, final_value_msat: amount_msat };
3546+
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amount_msat);
35473547

35483548
self.send_preflight_probes(route_params, liquidity_limit_multiplier)
35493549
}
@@ -9496,6 +9496,7 @@ where
94969496
pending_fee_msat: Some(path_fee),
94979497
total_msat: path_amt,
94989498
starting_block_height: best_block_height,
9499+
remaining_max_total_routing_fee_msat: None, // only used for retries, and we'll never retry on startup
94999500
});
95009501
log_info!(args.logger, "Added a pending payment for {} msat with payment hash {} for path with session priv {}",
95019502
path_amt, &htlc.payment_hash, log_bytes!(session_priv_bytes));

lightning/src/ln/functional_test_utils.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,11 @@ macro_rules! get_route_and_payment_hash {
18821882
$crate::get_route_and_payment_hash!($send_node, $recv_node, payment_params, $recv_value)
18831883
}};
18841884
($send_node: expr, $recv_node: expr, $payment_params: expr, $recv_value: expr) => {{
1885-
let route_params = $crate::routing::router::RouteParameters::from_payment_params_and_value($payment_params, $recv_value);
1885+
$crate::get_route_and_payment_hash!($send_node, $recv_node, $payment_params, $recv_value, None)
1886+
}};
1887+
($send_node: expr, $recv_node: expr, $payment_params: expr, $recv_value: expr, $max_total_routing_fee_msat: expr) => {{
1888+
let mut route_params = $crate::routing::router::RouteParameters::from_payment_params_and_value($payment_params, $recv_value);
1889+
route_params.max_total_routing_fee_msat = $max_total_routing_fee_msat;
18861890
let (payment_preimage, payment_hash, payment_secret) =
18871891
$crate::ln::functional_test_utils::get_payment_preimage_hash(&$recv_node, Some($recv_value), None);
18881892
let route = $crate::ln::functional_test_utils::get_route(&$send_node, &route_params);

0 commit comments

Comments
 (0)