|
10 | 10 | //! Utilities to send payments and manage outbound payment information.
|
11 | 11 |
|
12 | 12 | use crate::ln::{PaymentHash, PaymentSecret};
|
| 13 | +use crate::ln::channelmanager::PaymentId; |
13 | 14 | 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; |
15 | 17 | use crate::prelude::*;
|
16 | 18 |
|
17 | 19 | /// 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 {
|
168 | 170 | }
|
169 | 171 | }
|
170 | 172 |
|
| 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 | + |
171 | 251 | impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
|
172 | 252 | (0, Legacy) => {
|
173 | 253 | (0, session_privs, required),
|
|
0 commit comments