Skip to content
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

Merged
merged 7 commits into from
May 30, 2024

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented May 24, 2024

RecipientOnionFields is included in Event::PaymentClaimable. For completeness, include it in Event::PaymentClaimed as well.

Fixes #2988.

jkczyz added 3 commits May 24, 2024 11:30
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.
Comment on lines +6329 to +6333
.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);
})
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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."

Copy link
Contributor Author

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.

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?

Copy link
Collaborator

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.

@jkczyz jkczyz force-pushed the 2024-05-onion-fields branch from 2bad99a to 8499214 Compare May 24, 2024 21:53
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 94.61078% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 89.88%. Comparing base (a95338a) to head (8499214).
Report is 2 commits behind head on main.

Files Patch % Lines
lightning/src/ln/channelmanager.rs 78.26% 3 Missing and 2 partials ⚠️
lightning/src/events/mod.rs 0.00% 4 Missing ⚠️

❗ 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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@dunxen dunxen left a 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.

Comment on lines +6329 to +6333
.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);
})
Copy link
Contributor

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?

Copy link
Contributor

@tnull tnull left a 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.

Comment on lines +6329 to +6333
.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);
})
Copy link
Contributor

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."

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a 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>,
Copy link
Collaborator

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.

Comment on lines +6329 to +6333
.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);
})
Copy link
Collaborator

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.

@TheBlueMatt TheBlueMatt merged commit 7d2d047 into lightningdevkit:main May 30, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return onion_fields in PaymentClaimed
5 participants