-
Notifications
You must be signed in to change notification settings - Fork 385
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
Include RecipientOnionFields
in Event::PaymentClaimed
#3084
Include RecipientOnionFields
in Event::PaymentClaimed
#3084
Conversation
This allows for obtaining the value without needing to re-look it up. An upcoming commit will include RecipientOnionFields in the inserted value. Having it available afterwards prevents needing to clone it.
This will be used to include the same field in Event::PaymentClaimed.
.and_modify(|_| { | ||
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever"); | ||
log_error!(self.logger, "Got a duplicate pending claimable event on payment hash {}! Please report this bug", | ||
&payment_hash); | ||
}) |
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.
Noted that there is a small change of behavior here. When this case is hit, the entry is not overridden.
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.
This seems fine as it should be a duplicate anyway. Should the very unlikely error message above also state that the old event is not overridden?
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.
Mhh, while claiming duplicates isn't super nice as it indicates a bug on the sender side, do we still need to support it? If not, should we enforce the failure of duplicates rather than leaving it up to the user? At least currently our PaymentClaimable
docs state "Note that LDK will not stop you from registering duplicate payment hashes for inbound payments."
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.
IIUC, this is actually an invariant check and should never happen. We'll only insert into ClaimablePayments::claimable_payments
if ClaimablePayments::pending_claiming_payments
doesn't contain the same payment hash.
rust-lightning/lightning/src/ln/channelmanager.rs
Lines 5455 to 5466 in df01208
if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) { | |
fail_htlc!(claimable_htlc, payment_hash); | |
} | |
let ref mut claimable_payment = claimable_payments.claimable_payments | |
.entry(payment_hash) | |
// Note that if we insert here we MUST NOT fail_htlc!() | |
.or_insert_with(|| { | |
committed_to_claimable = true; | |
ClaimablePayment { | |
purpose: $purpose.clone(), htlcs: Vec::new(), onion_fields: None, | |
} | |
}); |
So I think we don't allow two outstanding payments for the same payment hash, but we will allow consecutive ones.
cc: @TheBlueMatt for confirmation.
Maybe ClaimablePayments
should have been one map storing an enum?
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.
Yes, we debug-panic and log an error because this absolutely shouldn't happen. I'm not sure it matters too much if we overwrite vs keeping as-is - either way we're gonna give the user spurious PaymentClaimed events, whether too early too late or not at all.
RecipientOnionFields are included in Event::PaymentClaimable, so naturally they should be included in Event::PaymentClaimed, too.
2bad99a
to
8499214
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #3084 +/- ##
========================================
Coverage 89.87% 89.88%
========================================
Files 117 117
Lines 96952 97130 +178
Branches 96952 97130 +178
========================================
+ Hits 87134 87301 +167
- Misses 7273 7285 +12
+ Partials 2545 2544 -1 ☔ View full report in Codecov by Sentry. |
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.
Thorough review and LGTM.
.and_modify(|_| { | ||
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever"); | ||
log_error!(self.logger, "Got a duplicate pending claimable event on payment hash {}! Please report this bug", | ||
&payment_hash); | ||
}) |
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.
This seems fine as it should be a duplicate anyway. Should the very unlikely error message above also state that the old event is not overridden?
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.
Generally LGTM, although I'm not super sure about whether we should or shouldn't support claiming duplicate payments.
.and_modify(|_| { | ||
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever"); | ||
log_error!(self.logger, "Got a duplicate pending claimable event on payment hash {}! Please report this bug", | ||
&payment_hash); | ||
}) |
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.
Mhh, while claiming duplicates isn't super nice as it indicates a bug on the sender side, do we still need to support it? If not, should we enforce the failure of duplicates rather than leaving it up to the user? At least currently our PaymentClaimable
docs state "Note that LDK will not stop you from registering duplicate payment hashes for inbound payments."
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.
Gonna go ahead and land this. We can do a followup if there's a need.
@@ -680,13 +680,15 @@ struct ClaimingPayment { | |||
receiver_node_id: PublicKey, | |||
htlcs: Vec<events::ClaimedHTLC>, | |||
sender_intended_value: Option<u64>, | |||
onion_fields: Option<RecipientOnionFields>, |
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.
We should write when it was added/that its always filled in in a comment.
.and_modify(|_| { | ||
debug_assert!(false, "Shouldn't get a duplicate pending claim event ever"); | ||
log_error!(self.logger, "Got a duplicate pending claimable event on payment hash {}! Please report this bug", | ||
&payment_hash); | ||
}) |
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.
Yes, we debug-panic and log an error because this absolutely shouldn't happen. I'm not sure it matters too much if we overwrite vs keeping as-is - either way we're gonna give the user spurious PaymentClaimed events, whether too early too late or not at all.
RecipientOnionFields
is included inEvent::PaymentClaimable
. For completeness, include it inEvent::PaymentClaimed
as well.Fixes #2988.