Skip to content

Retry pending payments on restart #171

Open

Description

@tnull

When restarting, we currently don't retry any pending payments, but we should.

See ChannelManager docs

Activity

  1. jbesraa commented on Oct 4, 2023

    @jbesraa
    Contributor

    Happy to pick this up

  2. jbesraa commented on Oct 4, 2023

    @jbesraa
    Contributor

    So I was looking around to understand how we get the different params to send_payment_with_route and came up with this code. I fetch recent_payments from list_recent_payments that is mentioned in the docs and it looks like the function we want

    does this make sense? is this the correct approach?

     16     /// Retry a pending payment after going offline.
    |   15     pub fn retry_payment(&self) {
    |   14         let cm = Arc::clone(&self.channel_manager);
    |   13         let recent_payments = cm.list_recent_payments();
    |   12         for payment in recent_payments {
    |   11             match payment {
    |   10                 RecentPaymentDetails::Pending { payment_hash, total_msat } => {
    |    9                     let payment_in_store: PaymentDetails = self.payment_store.get(&payment_hash).unwrap();
    |    8                     let invoice = Bolt11Invoice::from_str(std::str::from_utf8(&payment_in_store.hash.0).unwrap()).unwrap();
    |    7                     let payer = self.channel_manager.get_our_node_id();
    |    6                     let usable_channels = self.channel_manager.list_usable_channels();
    |    5                     let first_hops = usable_channels.iter().collect::<Vec<_>>();
    |    4                     let inflight_htlcs = self.channel_manager.compute_inflight_htlcs();
    |    3                     let payment_params = PaymentParameters::from_node_id(
    |    2                         invoice.recover_payee_pub_key(),
    |    1                         invoice.min_final_cltv_expiry_delta() as u32,
    | 730                      );
    |    1                     let route_params = RouteParameters { payment_params, final_value_msat: total_msat };
    |    2                     let route = self
    |    3                         .router
    |    4                         .find_route(&payer, &route_params, Some(&first_hops), inflight_htlcs)
    |    5                         .map_err(|e| {
    |    6                             log_error!(self.logger, "Failed to find path for payment probe: {:?}", e);
    |    7                             // Error::ProbeSendingFailed
    |    8                         }).unwrap();
    |    9                     let payment_id = PaymentId(invoice.payment_hash().into_inner());
    |   10                     let payment_secret = Some(*invoice.payment_secret());
    |   11                     let recipient_onion = RecipientOnionFields { payment_secret, payment_metadata: None };
    |   12                     let _ = cm.send_payment_with_route(
    |   13                         &route,
    |   14                         payment_hash,
    |   15                         recipient_onion,
    |   16                         payment_id,
    |   17                     );
    |   18                 }
    |   19                 _ => {}
    |   20             }
    |   21         }
    |   22     }
    |   23
  3. jbesraa commented on Oct 22, 2023

    @jbesraa
    Contributor

    @tnull would love your input here (:

  4. tnull commented on Oct 31, 2023

    @tnull
    CollaboratorAuthor

    @tnull would love your input here (:

    Excuse the delay getting back to this.

    So I was looking around to understand how we get the different params to send_payment_with_route and came up with this code. I fetch recent_payments from list_recent_payments that is mentioned in the docs and it looks like the function we want

    does this make sense? is this the correct approach?

    Unfortunately I suspect that we currently don't store sufficient data to retry the payment as is (i.e., the payment hash is not the serialized invoice, so Bolt11Invoice::from_str as you suggest above wont work.

    I'll assign myself here and will look into what steps we need to take, e.g., if we first have to implement invoice storage to this properly.

  5. self-assigned this
    on Oct 31, 2023
  6. added this to the 0.3 milestone on Nov 15, 2023
  7. modified the milestones: 0.3, 0.4 on May 20, 2024
  8. modified the milestones: 0.4, 0.5 on Sep 12, 2024
  9. modified the milestones: 0.5, 0.6 on Jan 24, 2025
  10. modified the milestones: 0.6, 0.7 on Jun 9, 2025
  11. modified the milestones: 0.7, 0.8 on Nov 10, 2025
  12. tnull commented on Aug 10, 2026

    @tnull
    CollaboratorAuthor

    This will slip to v0.9 I'm afraid.

    We're also back to the drawing board on what parts of this should live on LDK and what should be LDK Node's responsibilities.

  13. modified the milestones: 0.8, 0.9 on Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions