diff --git a/src/payment/bolt11.rs b/src/payment/bolt11.rs index 18c489e27a..769675398e 100644 --- a/src/payment/bolt11.rs +++ b/src/payment/bolt11.rs @@ -307,6 +307,7 @@ impl Bolt11Payment { log_error!(self.logger, "Failed to send payment: {:?}", e); match e { RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment), + RetryableSendFailure::RouteNotFound => Err(Error::PaymentSendingFailed), _ => { let kind = PaymentKind::Bolt11 { hash: payment_hash, @@ -422,6 +423,7 @@ impl Bolt11Payment { log_error!(self.logger, "Failed to send payment: {:?}", e); match e { RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment), + RetryableSendFailure::RouteNotFound => Err(Error::PaymentSendingFailed), _ => { let kind = PaymentKind::Bolt11 { hash: payment_hash, diff --git a/src/payment/spontaneous.rs b/src/payment/spontaneous.rs index 1c819582e4..1989317c1b 100644 --- a/src/payment/spontaneous.rs +++ b/src/payment/spontaneous.rs @@ -139,6 +139,7 @@ impl SpontaneousPayment { match e { RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment), + RetryableSendFailure::RouteNotFound => Err(Error::PaymentSendingFailed), _ => { let kind = PaymentKind::Spontaneous { hash: payment_hash, diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index d2c057a164..f6b963f898 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -2957,3 +2957,32 @@ async fn splice_in_with_all_balance() { node_a.stop().unwrap(); node_b.stop().unwrap(); } + +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn test_retry_on_routing_failure() { + let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); + let chain_source = random_chain_source(&bitcoind, &electrsd); + let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, true); + + let invoice_description = + Bolt11InvoiceDescription::Direct(Description::new(String::from("test-retry")).unwrap()); + let invoice = node_b + .bolt11_payment() + .receive(100_000, &invoice_description.clone().into(), 3600) + .unwrap(); + + let first_attempt = node_a.bolt11_payment().send(&invoice, None); + assert!(first_attempt.is_err(), "expecting error at first attempt"); + assert_eq!(first_attempt.unwrap_err(), NodeError::PaymentSendingFailed); + + let second_attempt = node_a.bolt11_payment().send(&invoice, None); + + assert_ne!( + second_attempt.unwrap_err(), + NodeError::DuplicatePayment, + "The invoice hash was incorrectly locked in the payment store after a routing failure!" + ); + + node_a.stop().unwrap(); + node_b.stop().unwrap(); +}