Skip to content

Commit 6d038ad

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 1c19bcc commit 6d038ad

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

lightning-invoice/src/payment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ mod tests {
15631563
}
15641564

15651565
fn fails_on_attempt(self, attempt: usize) -> Self {
1566-
let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateFailed);
1566+
let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateInProgress);
15671567
self.fails_with(failure, OnAttempt(attempt))
15681568
}
15691569

lightning/src/ln/chanmon_update_fail_tests.rs

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

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

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

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

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

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

lightning/src/ln/channelmanager.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1172,12 +1172,12 @@ pub enum PaymentSendFailure {
11721172
/// in over-/re-payment.
11731173
///
11741174
/// The results here are ordered the same as the paths in the route object which was passed to
1175-
/// send_payment, and any Errs which are not APIError::MonitorUpdateFailed can be safely
1176-
/// retried (though there is currently no API with which to do so).
1175+
/// send_payment, and any Errs which are not APIError::MonitorUpdateInProgress can be safely
1176+
/// retried via [`ChannelManager::retry_payment`].
11771177
///
1178-
/// Any entries which contain Err(APIError::MonitorUpdateFailed) or Ok(()) MUST NOT be retried
1179-
/// as they will result in over-/re-payment. These HTLCs all either successfully sent (in the
1180-
/// case of Ok(())) or will send once a [`MonitorEvent::Completed`] is provided for the
1178+
/// Any entries which contain Err(APIError::MonitorUpdateInprogress) or Ok(()) MUST NOT be
1179+
/// retried as they will result in over-/re-payment. These HTLCs all either successfully sent
1180+
/// (in the case of Ok(())) or will send once a [`MonitorEvent::Completed`] is provided for the
11811181
/// next-hop channel with the latest update_id.
11821182
PartialFailure {
11831183
/// The errors themselves, in the same order as the route hops.
@@ -2476,13 +2476,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24762476
insert_outbound_payment!();
24772477
},
24782478
(ChannelMonitorUpdateStatus::InProgress, Err(_)) => {
2479-
// Note that MonitorUpdateFailed here indicates (per function docs)
2480-
// that we will resend the commitment update once monitor updating
2481-
// is restored. Therefore, we must return an error indicating that
2482-
// it is unsafe to retry the payment wholesale, which we do in the
2483-
// send_payment check for MonitorUpdateFailed, below.
2479+
// Note that MonitorUpdateInProgress here indicates (per function
2480+
// docs) that we will resend the commitment update once monitor
2481+
// updating completes. Therefore, we must return an error
2482+
// indicating that it is unsafe to retry the payment wholesale,
2483+
// which we do in the send_payment check for
2484+
// MonitorUpdateInProgress, below.
24842485
insert_outbound_payment!(); // Only do this after possibly break'ing on Perm failure above.
2485-
return Err(APIError::MonitorUpdateFailed);
2486+
return Err(APIError::MonitorUpdateInProgress);
24862487
},
24872488
_ => unreachable!(),
24882489
}
@@ -2533,12 +2534,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
25332534
/// PaymentSendFailure for more info.
25342535
///
25352536
/// In general, a path may raise:
2536-
/// * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
2537+
/// * [`APIError::RouteError`] when an invalid route or forwarding parameter (cltv_delta, fee,
25372538
/// node public key) is specified.
2538-
/// * APIError::ChannelUnavailable if the next-hop channel is not available for updates
2539+
/// * [`APIError::ChannelUnavailable`] if the next-hop channel is not available for updates
25392540
/// (including due to previous monitor update failure or new permanent monitor update
25402541
/// failure).
2541-
/// * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
2542+
/// * [`APIError::MonitorUpdateInProgress`] if a new monitor update failure prevented sending the
25422543
/// relevant updates.
25432544
///
25442545
/// Note that depending on the type of the PaymentSendFailure the HTLC may have been
@@ -2602,8 +2603,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
26022603
for (res, path) in results.iter().zip(route.paths.iter()) {
26032604
if res.is_ok() { has_ok = true; }
26042605
if res.is_err() { has_err = true; }
2605-
if let &Err(APIError::MonitorUpdateFailed) = res {
2606-
// MonitorUpdateFailed is inherently unsafe to retry, so we call it a
2606+
if let &Err(APIError::MonitorUpdateInProgress) = res {
2607+
// MonitorUpdateInProgress is inherently unsafe to retry, so we call it a
26072608
// PartialFailure.
26082609
has_err = true;
26092610
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)