Skip to content

Commit 0c0e9fa

Browse files
Move PaymentSendFailure into outbound_payment module
And re-export it in channelmanager.rs so it can remain public
1 parent f05c414 commit 0c0e9fa

File tree

2 files changed

+82
-65
lines changed

2 files changed

+82
-65
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::ln::msgs;
5151
use crate::ln::onion_utils;
5252
use crate::ln::onion_utils::HTLCFailReason;
5353
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT};
54+
pub use crate::ln::outbound_payment::PaymentSendFailure;
5455
use crate::ln::outbound_payment::PendingOutboundPayment;
5556
use crate::ln::wire::Encode;
5657
use crate::chain::keysinterface::{Sign, KeysInterface, KeysManager, Recipient};
@@ -1099,70 +1100,6 @@ impl ChannelDetails {
10991100
}
11001101
}
11011102

1102-
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
1103-
/// Err() type describing which state the payment is in, see the description of individual enum
1104-
/// states for more.
1105-
#[derive(Clone, Debug)]
1106-
pub enum PaymentSendFailure {
1107-
/// A parameter which was passed to send_payment was invalid, preventing us from attempting to
1108-
/// send the payment at all.
1109-
///
1110-
/// You can freely resend the payment in full (with the parameter error fixed).
1111-
///
1112-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
1113-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
1114-
/// for this payment.
1115-
ParameterError(APIError),
1116-
/// A parameter in a single path which was passed to send_payment was invalid, preventing us
1117-
/// from attempting to send the payment at all.
1118-
///
1119-
/// You can freely resend the payment in full (with the parameter error fixed).
1120-
///
1121-
/// The results here are ordered the same as the paths in the route object which was passed to
1122-
/// send_payment.
1123-
///
1124-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
1125-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
1126-
/// for this payment.
1127-
PathParameterError(Vec<Result<(), APIError>>),
1128-
/// All paths which were attempted failed to send, with no channel state change taking place.
1129-
/// You can freely resend the payment in full (though you probably want to do so over different
1130-
/// paths than the ones selected).
1131-
///
1132-
/// Because the payment failed outright, no payment tracking is done, you do not need to call
1133-
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
1134-
/// for this payment.
1135-
AllFailedResendSafe(Vec<APIError>),
1136-
/// Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
1137-
/// yet completed (i.e. generated an [`Event::PaymentSent`]) or been abandoned (via
1138-
/// [`ChannelManager::abandon_payment`]).
1139-
///
1140-
/// [`Event::PaymentSent`]: events::Event::PaymentSent
1141-
DuplicatePayment,
1142-
/// Some paths which were attempted failed to send, though possibly not all. At least some
1143-
/// paths have irrevocably committed to the HTLC and retrying the payment in full would result
1144-
/// in over-/re-payment.
1145-
///
1146-
/// The results here are ordered the same as the paths in the route object which was passed to
1147-
/// send_payment, and any `Err`s which are not [`APIError::MonitorUpdateInProgress`] can be
1148-
/// safely retried via [`ChannelManager::retry_payment`].
1149-
///
1150-
/// Any entries which contain `Err(APIError::MonitorUpdateInprogress)` or `Ok(())` MUST NOT be
1151-
/// retried as they will result in over-/re-payment. These HTLCs all either successfully sent
1152-
/// (in the case of `Ok(())`) or will send once a [`MonitorEvent::Completed`] is provided for
1153-
/// the next-hop channel with the latest update_id.
1154-
PartialFailure {
1155-
/// The errors themselves, in the same order as the route hops.
1156-
results: Vec<Result<(), APIError>>,
1157-
/// If some paths failed without irrevocably committing to the new HTLC(s), this will
1158-
/// contain a [`RouteParameters`] object which can be used to calculate a new route that
1159-
/// will pay all remaining unpaid balance.
1160-
failed_paths_retry: Option<RouteParameters>,
1161-
/// The payment id for the payment, which is now at least partially pending.
1162-
payment_id: PaymentId,
1163-
},
1164-
}
1165-
11661103
/// Route hints used in constructing invoices for [phantom node payents].
11671104
///
11681105
/// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager

lightning/src/ln/outbound_payment.rs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
//! Utilities to send payments and manage outbound payment information.
1111
1212
use crate::ln::{PaymentHash, PaymentSecret};
13+
use crate::ln::channelmanager::PaymentId;
1314
use crate::ln::msgs::DecodeError;
14-
use crate::routing::router::{RouteHop, RoutePath};
15+
use crate::routing::router::{RouteHop, RouteParameters, RoutePath};
16+
use crate::util::errors::APIError;
1517
use crate::prelude::*;
1618

1719
/// Stores the session_priv for each part of a payment that is still pending. For versions 0.0.102
@@ -168,6 +170,84 @@ impl PendingOutboundPayment {
168170
}
169171
}
170172

173+
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
174+
/// Err() type describing which state the payment is in, see the description of individual enum
175+
/// states for more.
176+
#[derive(Clone, Debug)]
177+
pub enum PaymentSendFailure {
178+
/// A parameter which was passed to send_payment was invalid, preventing us from attempting to
179+
/// send the payment at all.
180+
///
181+
/// You can freely resend the payment in full (with the parameter error fixed).
182+
///
183+
/// Because the payment failed outright, no payment tracking is done, you do not need to call
184+
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
185+
/// for this payment.
186+
///
187+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
188+
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
189+
ParameterError(APIError),
190+
/// A parameter in a single path which was passed to send_payment was invalid, preventing us
191+
/// from attempting to send the payment at all.
192+
///
193+
/// You can freely resend the payment in full (with the parameter error fixed).
194+
///
195+
/// The results here are ordered the same as the paths in the route object which was passed to
196+
/// send_payment.
197+
///
198+
/// Because the payment failed outright, no payment tracking is done, you do not need to call
199+
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
200+
/// for this payment.
201+
///
202+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
203+
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
204+
PathParameterError(Vec<Result<(), APIError>>),
205+
/// All paths which were attempted failed to send, with no channel state change taking place.
206+
/// You can freely resend the payment in full (though you probably want to do so over different
207+
/// paths than the ones selected).
208+
///
209+
/// Because the payment failed outright, no payment tracking is done, you do not need to call
210+
/// [`ChannelManager::abandon_payment`] and [`ChannelManager::retry_payment`] will *not* work
211+
/// for this payment.
212+
///
213+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
214+
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
215+
AllFailedResendSafe(Vec<APIError>),
216+
/// Indicates that a payment for the provided [`PaymentId`] is already in-flight and has not
217+
/// yet completed (i.e. generated an [`Event::PaymentSent`]) or been abandoned (via
218+
/// [`ChannelManager::abandon_payment`]).
219+
///
220+
/// [`PaymentId`]: crate::ln::channelmanager::PaymentId
221+
/// [`Event::PaymentSent`]: crate::util::events::Event::PaymentSent
222+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
223+
DuplicatePayment,
224+
/// Some paths which were attempted failed to send, though possibly not all. At least some
225+
/// paths have irrevocably committed to the HTLC and retrying the payment in full would result
226+
/// in over-/re-payment.
227+
///
228+
/// The results here are ordered the same as the paths in the route object which was passed to
229+
/// send_payment, and any `Err`s which are not [`APIError::MonitorUpdateInProgress`] can be
230+
/// safely retried via [`ChannelManager::retry_payment`].
231+
///
232+
/// Any entries which contain `Err(APIError::MonitorUpdateInprogress)` or `Ok(())` MUST NOT be
233+
/// retried as they will result in over-/re-payment. These HTLCs all either successfully sent
234+
/// (in the case of `Ok(())`) or will send once a [`MonitorEvent::Completed`] is provided for
235+
/// the next-hop channel with the latest update_id.
236+
///
237+
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
238+
/// [`MonitorEvent::Completed`]: crate::chain::channelmonitor::MonitorEvent::Completed
239+
PartialFailure {
240+
/// The errors themselves, in the same order as the route hops.
241+
results: Vec<Result<(), APIError>>,
242+
/// If some paths failed without irrevocably committing to the new HTLC(s), this will
243+
/// contain a [`RouteParameters`] object which can be used to calculate a new route that
244+
/// will pay all remaining unpaid balance.
245+
failed_paths_retry: Option<RouteParameters>,
246+
/// The payment id for the payment, which is now at least partially pending.
247+
payment_id: PaymentId,
248+
},
249+
}
250+
171251
impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
172252
(0, Legacy) => {
173253
(0, session_privs, required),

0 commit comments

Comments
 (0)