-
Notifications
You must be signed in to change notification settings - Fork 461
Fix missing PaymentSent::fee_paid_msat
#4651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,10 @@ pub(crate) enum PendingOutboundPayment { | |
| /// The total payment amount across all paths, used to be able to issue `PaymentSent` if | ||
| /// an HTLC still happens to succeed after we marked the payment as abandoned. | ||
| total_msat: Option<u64>, | ||
| /// Preserved from `Retryable` so we can still report `fee_paid_msat` if an HTLC succeeds | ||
| /// after the payment was abandoned. `None` for payments abandoned prior to this field being | ||
| /// added, or for payments that were never in the `Retryable` state. | ||
| pending_fee_msat: Option<u64>, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -252,6 +256,7 @@ impl PendingOutboundPayment { | |
| fn get_pending_fee_msat(&self) -> Option<u64> { | ||
| match self { | ||
| PendingOutboundPayment::Retryable { pending_fee_msat, .. } => pending_fee_msat.clone(), | ||
| PendingOutboundPayment::Abandoned { pending_fee_msat, .. } => pending_fee_msat.clone(), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
@@ -308,6 +313,7 @@ impl PendingOutboundPayment { | |
| _ => new_hash_set(), | ||
| }; | ||
| let total_msat = self.total_msat(); | ||
| let pending_fee_msat = self.get_pending_fee_msat(); | ||
| match self { | ||
| Self::Retryable { payment_hash, .. } | | ||
| Self::InvoiceReceived { payment_hash, .. } | | ||
|
|
@@ -318,6 +324,7 @@ impl PendingOutboundPayment { | |
| payment_hash: *payment_hash, | ||
| reason: Some(reason), | ||
| total_msat, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious here if we should be setting this to the sum of the current paths currently in-flight, and not the fixed total msat ? |
||
| pending_fee_msat, | ||
| }; | ||
| }, | ||
| _ => {} | ||
|
|
@@ -354,6 +361,14 @@ impl PendingOutboundPayment { | |
| if let Some(max_total_routing_fee_msat) = remaining_max_total_routing_fee_msat.as_mut() { | ||
| *max_total_routing_fee_msat = max_total_routing_fee_msat.saturating_add(path_fee_msat); | ||
| } | ||
| } else if let PendingOutboundPayment::Abandoned { pending_fee_msat, .. } = self { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this block should we also subtract |
||
| // Keep `pending_fee_msat` in sync with the remaining in-flight HTLCs so that if | ||
| // any path still succeeds after abandonment, the eventual `PaymentSent` reports | ||
| // only the fee actually paid. | ||
| let path = path.expect("Removing a failed payment should always come with a path"); | ||
| if let Some(fee_msat) = pending_fee_msat.as_mut() { | ||
| *fee_msat -= path.fee_msat(); | ||
| } | ||
| } | ||
| } | ||
| remove_res | ||
|
|
@@ -2778,6 +2793,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment, | |
| (1, reason, upgradable_option), | ||
| (2, payment_hash, required), | ||
| (3, total_msat, option), | ||
| (5, pending_fee_msat, option), | ||
| }, | ||
| (5, AwaitingInvoice) => { | ||
| (0, expiration, required), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This wording slightly overstates the scope. For payments that stayed in
Retryablestate (i.e., were never abandoned while in-flight),fee_paid_msathas beenSomesince 0.0.103. TheNonegap between 0.0.103 and 0.4 only applies to payments that were abandoned with HTLCs in-flight and then unexpectedly claimed.Something like "May be
Nonefor payments abandoned on LDK versions prior to 0.4, or initiated prior to 0.0.103." would be more precise. Not blocking — the current "May be" phrasing is technically correct.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like keeping it simple but open to feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to resolve myself.