Skip to content

Event::PaymentSent::fee_paid_msat can be None despite docs to the contrary #4639

@phlip9

Description

@phlip9

Summary

The Event::PaymentSent::fee_paid_msat docs claim the field is never None (for events after v0.0.103), however abandon_payment -> HTLC(s) still in-flight -> successful claim_htlc -> Event::PaymentSent will have the field set to None.

It appears that PendingOutboundPayment::get_pending_fee_msat() only returns a value for PendingOutboundPayment::Retryable. In some sense, even though a payment might still succeed, PendingOutboundPayment::Abandoned "forgets" too much info, when it should instead preserve some data from PendingOutboundPayment::Retryable in case the payment actually goes through.

Ideally we don't forget the fees, so our accounting stays clean. If someone's relying on Event::PaymentSent::bolt12_invoice, they'll also lose that data unexpectedly.

Context

/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
/// and we got back the payment preimage for it).
/// ...
/// # Failure Behavior and Persistence
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
/// returning `Err(ReplayEvent ())`) and will be persisted across restarts.
PaymentSent {
	// ...
	/// The total fee which was spent at intermediate hops in this payment, across all paths.
	/// ...
	/// This is only `None` for payments initiated on LDK versions prior to 0.0.103.
	fee_paid_msat: Option<u64>,
	// ...
}

Following the docs, since we had no pending payments pre-0.0.103, we had an unwrap on this field:

match event {
  Event::PaymentSent { fee_paid_msat, .. } => {
    // ..
    let fee_paid_msat =
      fee_paid_msat.expect("No pending sends before 0.0.103");
    // ..
  }
}

See: https://github.com/lexe-app/lexe-public/blob/42b307e6e0adb2447381a7a98492b10407ff15b8/node/src/event_handler.rs#L467

And so a user node hit this edge case and panicked :'(

In the meantime, we'll just fee_paid_msat.unwrap_or(0) to stop panicking, but it would be real nice to not lose the payment fee.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions