mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Account for leftover fee budget when retrying PartialFailure
s
This commit is contained in:
parent
b1a878fe81
commit
ac57163895
1 changed files with 15 additions and 7 deletions
|
@ -1322,14 +1322,19 @@ impl OutboundPayments {
|
||||||
let mut has_ok = false;
|
let mut has_ok = false;
|
||||||
let mut has_err = false;
|
let mut has_err = false;
|
||||||
let mut pending_amt_unsent = 0;
|
let mut pending_amt_unsent = 0;
|
||||||
|
let mut total_ok_fees_msat = 0;
|
||||||
for (res, path) in results.iter().zip(route.paths.iter()) {
|
for (res, path) in results.iter().zip(route.paths.iter()) {
|
||||||
if res.is_ok() { has_ok = true; }
|
if res.is_ok() {
|
||||||
|
has_ok = true;
|
||||||
|
total_ok_fees_msat += path.fee_msat();
|
||||||
|
}
|
||||||
if res.is_err() { has_err = true; }
|
if res.is_err() { has_err = true; }
|
||||||
if let &Err(APIError::MonitorUpdateInProgress) = res {
|
if let &Err(APIError::MonitorUpdateInProgress) = res {
|
||||||
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
|
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
|
||||||
// PartialFailure.
|
// PartialFailure.
|
||||||
has_err = true;
|
has_err = true;
|
||||||
has_ok = true;
|
has_ok = true;
|
||||||
|
total_ok_fees_msat += path.fee_msat();
|
||||||
} else if res.is_err() {
|
} else if res.is_err() {
|
||||||
pending_amt_unsent += path.final_value_msat();
|
pending_amt_unsent += path.final_value_msat();
|
||||||
}
|
}
|
||||||
|
@ -1339,12 +1344,15 @@ impl OutboundPayments {
|
||||||
results,
|
results,
|
||||||
payment_id,
|
payment_id,
|
||||||
failed_paths_retry: if pending_amt_unsent != 0 {
|
failed_paths_retry: if pending_amt_unsent != 0 {
|
||||||
if let Some(payment_params) = route.route_params.as_ref().map(|p| p.payment_params.clone()) {
|
if let Some(route_params) = &route.route_params {
|
||||||
Some(RouteParameters {
|
let mut route_params = route_params.clone();
|
||||||
payment_params,
|
// We calculate the leftover fee budget we're allowed to spend by
|
||||||
final_value_msat: pending_amt_unsent,
|
// subtracting the used fee from the total fee budget.
|
||||||
max_total_routing_fee_msat: None,
|
route_params.max_total_routing_fee_msat = route_params
|
||||||
})
|
.max_total_routing_fee_msat.map(|m| m.saturating_sub(total_ok_fees_msat));
|
||||||
|
route_params.final_value_msat = pending_amt_unsent;
|
||||||
|
|
||||||
|
Some(route_params)
|
||||||
} else { None }
|
} else { None }
|
||||||
} else { None },
|
} else { None },
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue