Skip to content

Commit 46fd703

Browse files
authored
Merge pull request #2014 from valentinewallace/2023-02-rework-partial-pmt-fail
Rework auto-retry send errors
2 parents 96c8507 + a6e9123 commit 46fd703

File tree

4 files changed

+316
-153
lines changed

4 files changed

+316
-153
lines changed

lightning-invoice/src/payment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lightning::chain;
1717
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
1818
use lightning::chain::keysinterface::{NodeSigner, SignerProvider, EntropySource};
1919
use lightning::ln::{PaymentHash, PaymentSecret};
20-
use lightning::ln::channelmanager::{ChannelManager, PaymentId, PaymentSendFailure, Retry};
20+
use lightning::ln::channelmanager::{ChannelManager, PaymentId, Retry, RetryableSendFailure};
2121
use lightning::routing::router::{PaymentParameters, RouteParameters, Router};
2222
use lightning::util::logger::Logger;
2323

@@ -172,7 +172,7 @@ pub enum PaymentError {
172172
/// An error resulting from the provided [`Invoice`] or payment hash.
173173
Invoice(&'static str),
174174
/// An error occurring when sending a payment.
175-
Sending(PaymentSendFailure),
175+
Sending(RetryableSendFailure),
176176
}
177177

178178
/// A trait defining behavior of an [`Invoice`] payer.

lightning/src/ln/channelmanager.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use core::time::Duration;
7878
use core::ops::Deref;
7979

8080
// Re-export this for use in the public API.
81-
pub use crate::ln::outbound_payment::{PaymentSendFailure, Retry};
81+
pub use crate::ln::outbound_payment::{PaymentSendFailure, Retry, RetryableSendFailure};
8282

8383
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
8484
//
@@ -2437,7 +2437,7 @@ where
24372437

24382438
let per_peer_state = self.per_peer_state.read().unwrap();
24392439
let peer_state_mutex = per_peer_state.get(&counterparty_node_id)
2440-
.ok_or_else(|| APIError::InvalidRoute{err: "No peer matching the path's first hop found!" })?;
2440+
.ok_or_else(|| APIError::ChannelUnavailable{err: "No peer matching the path's first hop found!".to_owned() })?;
24412441
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
24422442
let peer_state = &mut *peer_state_lock;
24432443
if let hash_map::Entry::Occupied(mut chan) = peer_state.channel_by_id.entry(id) {
@@ -2563,12 +2563,13 @@ where
25632563

25642564
/// Similar to [`ChannelManager::send_payment`], but will automatically find a route based on
25652565
/// `route_params` and retry failed payment paths based on `retry_strategy`.
2566-
pub fn send_payment_with_retry(&self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<(), PaymentSendFailure> {
2566+
pub fn send_payment_with_retry(&self, payment_hash: PaymentHash, payment_secret: &Option<PaymentSecret>, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<(), RetryableSendFailure> {
25672567
let best_block_height = self.best_block.read().unwrap().height();
25682568
self.pending_outbound_payments
25692569
.send_payment(payment_hash, payment_secret, payment_id, retry_strategy, route_params,
25702570
&self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
25712571
&self.entropy_source, &self.node_signer, best_block_height, &self.logger,
2572+
&self.pending_events,
25722573
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
25732574
self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
25742575
}
@@ -2640,12 +2641,12 @@ where
26402641
/// payments.
26412642
///
26422643
/// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
2643-
pub fn send_spontaneous_payment_with_retry(&self, payment_preimage: Option<PaymentPreimage>, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<PaymentHash, PaymentSendFailure> {
2644+
pub fn send_spontaneous_payment_with_retry(&self, payment_preimage: Option<PaymentPreimage>, payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry) -> Result<PaymentHash, RetryableSendFailure> {
26442645
let best_block_height = self.best_block.read().unwrap().height();
26452646
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, payment_id,
26462647
retry_strategy, route_params, &self.router, self.list_usable_channels(),
26472648
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
2648-
&self.logger,
2649+
&self.logger, &self.pending_events,
26492650
|path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv|
26502651
self.send_payment_along_path(path, payment_params, payment_hash, payment_secret, total_value, cur_height, payment_id, keysend_preimage, session_priv))
26512652
}

0 commit comments

Comments
 (0)