Skip to content

Commit 09031f0

Browse files
committed
Rename APIError::MonitorUpdateFailed to MonitorUpdateInProgress
This much more accurately represents the error, indicating that a monitor update is in progress asynchronously and may complete at a later time.
1 parent b58c941 commit 09031f0

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

fuzz/src/chanmon_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn check_api_err(api_err: APIError) {
270270
_ => panic!("{}", err),
271271
}
272272
},
273-
APIError::MonitorUpdateFailed => {
273+
APIError::MonitorUpdateInProgress => {
274274
// We can (obviously) temp-fail a monitor update
275275
},
276276
APIError::IncompatibleShutdownScript { .. } => panic!("Cannot send an incompatible shutdown script"),

lightning-invoice/src/payment.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,11 @@ where
513513
},
514514
PaymentSendFailure::PartialFailure { failed_paths_retry, payment_id, results } => {
515515
// If a `PartialFailure` event returns a result that is an `Ok()`, it means that
516-
// part of our payment is retried. When we receive `MonitorUpdateFailed`, it
516+
// part of our payment is retried. When we receive `MonitorUpdateInProgress`, it
517517
// means that we are still waiting for our channel monitor update to be completed.
518518
for (result, path) in results.iter().zip(route.paths.into_iter()) {
519519
match result {
520-
Ok(_) | Err(APIError::MonitorUpdateFailed) => {
520+
Ok(_) | Err(APIError::MonitorUpdateInProgress) => {
521521
self.process_path_inflight_htlcs(payment_hash, path);
522522
},
523523
_ => {},
@@ -617,11 +617,11 @@ where
617617
},
618618
Err(PaymentSendFailure::PartialFailure { failed_paths_retry, results, .. }) => {
619619
// If a `PartialFailure` error contains a result that is an `Ok()`, it means that
620-
// part of our payment is retried. When we receive `MonitorUpdateFailed`, it
620+
// part of our payment is retried. When we receive `MonitorUpdateInProgress`, it
621621
// means that we are still waiting for our channel monitor update to complete.
622622
for (result, path) in results.iter().zip(route.unwrap().paths.into_iter()) {
623623
match result {
624-
Ok(_) | Err(APIError::MonitorUpdateFailed) => {
624+
Ok(_) | Err(APIError::MonitorUpdateInProgress) => {
625625
self.process_path_inflight_htlcs(payment_hash, path);
626626
},
627627
_ => {},
@@ -796,7 +796,7 @@ mod tests {
796796
use std::time::{SystemTime, Duration};
797797
use time_utils::tests::SinceEpoch;
798798
use DEFAULT_EXPIRY_TIME;
799-
use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateFailed};
799+
use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateInProgress};
800800

801801
fn invoice(payment_preimage: PaymentPreimage) -> Invoice {
802802
let payment_hash = Sha256::hash(&payment_preimage.0);
@@ -1718,7 +1718,7 @@ mod tests {
17181718
.fails_with_partial_failure(
17191719
retry.clone(), OnAttempt(1),
17201720
Some(vec![
1721-
Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateFailed)
1721+
Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateInProgress)
17221722
]))
17231723
.expect_send(Amount::ForInvoice(final_value_msat));
17241724

@@ -1731,7 +1731,7 @@ mod tests {
17311731
invoice_payer.pay_invoice(&invoice_to_pay).unwrap();
17321732
let inflight_map = invoice_payer.create_inflight_map();
17331733

1734-
// Only the second path, which failed with `MonitorUpdateFailed` should be added to our
1734+
// Only the second path, which failed with `MonitorUpdateInProgress` should be added to our
17351735
// inflight map because retries are disabled.
17361736
assert_eq!(inflight_map.len(), 2);
17371737
}
@@ -1750,7 +1750,7 @@ mod tests {
17501750
.fails_with_partial_failure(
17511751
retry.clone(), OnAttempt(1),
17521752
Some(vec![
1753-
Ok(()), Err(MonitorUpdateFailed)
1753+
Ok(()), Err(MonitorUpdateInProgress)
17541754
]))
17551755
.expect_send(Amount::ForInvoice(final_value_msat));
17561756

@@ -2044,7 +2044,7 @@ mod tests {
20442044
}
20452045

20462046
fn fails_on_attempt(self, attempt: usize) -> Self {
2047-
let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateFailed);
2047+
let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateInProgress);
20482048
self.fails_with(failure, OnAttempt(attempt))
20492049
}
20502050

lightning/src/ln/chanmon_update_fail_tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
170170
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
171171

172172
{
173-
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)), false, APIError::MonitorUpdateFailed, {});
173+
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)), false, APIError::MonitorUpdateInProgress, {});
174174
check_added_monitors!(nodes[0], 1);
175175
}
176176

@@ -221,7 +221,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
221221
let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(&nodes[0], nodes[1], 1000000);
222222
{
223223
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
224-
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateFailed, {});
224+
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateInProgress, {});
225225
check_added_monitors!(nodes[0], 1);
226226
}
227227

@@ -285,7 +285,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
285285
let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
286286
{
287287
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
288-
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateFailed, {});
288+
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateInProgress, {});
289289
check_added_monitors!(nodes[0], 1);
290290
}
291291

@@ -1962,12 +1962,12 @@ fn test_path_paused_mpp() {
19621962
chanmon_cfgs[0].persister.set_next_update_ret(Some(ChannelMonitorUpdateStatus::InProgress));
19631963

19641964
// Now check that we get the right return value, indicating that the first path succeeded but
1965-
// the second got a MonitorUpdateFailed err. This implies PaymentSendFailure::PartialFailure as
1966-
// some paths succeeded, preventing retry.
1965+
// the second got a MonitorUpdateInProgress err. This implies
1966+
// PaymentSendFailure::PartialFailure as some paths succeeded, preventing retry.
19671967
if let Err(PaymentSendFailure::PartialFailure { results, ..}) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)) {
19681968
assert_eq!(results.len(), 2);
19691969
if let Ok(()) = results[0] {} else { panic!(); }
1970-
if let Err(APIError::MonitorUpdateFailed) = results[1] {} else { panic!(); }
1970+
if let Err(APIError::MonitorUpdateInProgress) = results[1] {} else { panic!(); }
19711971
} else { panic!(); }
19721972
check_added_monitors!(nodes[0], 2);
19731973
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);

lightning/src/ln/channelmanager.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1166,12 +1166,12 @@ pub enum PaymentSendFailure {
11661166
/// in over-/re-payment.
11671167
///
11681168
/// The results here are ordered the same as the paths in the route object which was passed to
1169-
/// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1170-
/// retried (though there is currently no API with which to do so).
1169+
/// send_payment, and any Errs which are not APIError::MonitorUpdateInProgress can be safely
1170+
/// retried via [`ChannelManager::retry_payment`].
11711171
///
1172-
/// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1173-
/// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1174-
/// case of Ok(())) or will send once a [`MonitorEvent::Completed`] is provided for the
1172+
/// Any entries which contain Err(APIError::MonitorUpdateInprogress) or Ok(()) MUST NOT be
1173+
/// retried as they will result in over-/re-payment. These HTLCs all either successfully sent
1174+
/// (in the case of Ok(())) or will send once a [`MonitorEvent::Completed`] is provided for the
11751175
/// next-hop channel with the latest update_id.
11761176
PartialFailure {
11771177
/// The errors themselves, in the same order as the route hops.
@@ -2469,13 +2469,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24692469
insert_outbound_payment!();
24702470
},
24712471
(ChannelMonitorUpdateStatus::InProgress, Err(_)) => {
2472-
// Note that MonitorUpdateFailed here indicates (per function docs)
2473-
// that we will resend the commitment update once monitor updating
2474-
// is restored. Therefore, we must return an error indicating that
2475-
// it is unsafe to retry the payment wholesale, which we do in the
2476-
// send_payment check for MonitorUpdateFailed, below.
2472+
// Note that MonitorUpdateInProgress here indicates (per function
2473+
// docs) that we will resend the commitment update once monitor
2474+
// updating completes. Therefore, we must return an error
2475+
// indicating that it is unsafe to retry the payment wholesale,
2476+
// which we do in the send_payment check for
2477+
// MonitorUpdateInProgress, below.
24772478
insert_outbound_payment!(); // Only do this after possibly break'ing on Perm failure above.
2478-
return Err(APIError::MonitorUpdateFailed);
2479+
return Err(APIError::MonitorUpdateInProgress);
24792480
},
24802481
_ => unreachable!(),
24812482
}
@@ -2526,12 +2527,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
25262527
/// PaymentSendFailure for more info.
25272528
///
25282529
/// In general, a path may raise:
2529-
/// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
2530+
/// * [`APIError::RouteError`] when an invalid route or forwarding parameter (cltv_delta, fee,
25302531
/// node public key) is specified.
2531-
/// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
2532+
/// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
25322533
/// (including due to previous monitor update failure or new permanent monitor update
25332534
/// failure).
2534-
/// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
2535+
/// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
25352536
/// relevant updates.
25362537
///
25372538
/// Note that depending on the type of the PaymentSendFailure the HTLC may have been
@@ -2595,8 +2596,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
25952596
for (res, path) in results.iter().zip(route.paths.iter()) {
25962597
if res.is_ok() { has_ok = true; }
25972598
if res.is_err() { has_err = true; }
2598-
if let &Err(APIError::MonitorUpdateFailed) = res {
2599-
// MonitorUpdateFailed is inherently unsafe to retry, so we call it a
2599+
if let &Err(APIError::MonitorUpdateInProgress) = res {
2600+
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
26002601
// PartialFailure.
26012602
has_err = true;
26022603
has_ok = true;

lightning/src/util/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum APIError {
4848
},
4949
/// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
5050
/// attempted action to fail.
51-
MonitorUpdateFailed,
51+
MonitorUpdateInProgress,
5252
/// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
5353
/// with the channel counterparty as negotiated in [`InitFeatures`].
5454
///
@@ -70,7 +70,7 @@ impl fmt::Debug for APIError {
7070
APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate),
7171
APIError::RouteError {ref err} => write!(f, "Route error: {}", err),
7272
APIError::ChannelUnavailable {ref err} => write!(f, "Channel unavailable: {}", err),
73-
APIError::MonitorUpdateFailed => f.write_str("Client indicated a channel monitor update failed"),
73+
APIError::MonitorUpdateInProgress => f.write_str("Client indicated a channel monitor update is in progress but not yet complete"),
7474
APIError::IncompatibleShutdownScript { ref script } => {
7575
write!(f, "Provided a scriptpubkey format not accepted by peer: {}", script)
7676
},

0 commit comments

Comments
 (0)