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

Deduplicate PendingHTLCsForwardable events on generation #2026

Conversation

valentinewallace
Copy link
Contributor

Ensure that when we generate a PendingHTLCsForwardable event, there isn't one already queued.

Completes the follow-ups from #1916.

Partially addresses #1932.

@wpaulino wpaulino added this to the 0.0.114 milestone Feb 10, 2023
@valentinewallace
Copy link
Contributor Author

On second glance this needs more work. Will update soon.

@valentinewallace valentinewallace marked this pull request as draft February 11, 2023 01:47
@valentinewallace valentinewallace force-pushed the 2023-02-dedup-pending-forwardable-evs branch from 9644d2c to 6074e8a Compare February 11, 2023 20:46
@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2023

Codecov Report

Base: 87.22% // Head: 87.20% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (a2489b1) compared to base (2f36c92).
Patch coverage: 88.31% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2026      +/-   ##
==========================================
- Coverage   87.22%   87.20%   -0.02%     
==========================================
  Files         100      101       +1     
  Lines       44051    44175     +124     
  Branches    44051    44175     +124     
==========================================
+ Hits        38424    38524     +100     
- Misses       5627     5651      +24     
Impacted Files Coverage Δ
lightning/src/ln/functional_test_utils.rs 88.43% <0.00%> (-0.07%) ⬇️
lightning/src/sync/fairrwlock.rs 75.00% <0.00%> (ø)
lightning/src/sync/mod.rs 50.00% <50.00%> (ø)
lightning/src/ln/outbound_payment.rs 79.96% <76.47%> (-0.33%) ⬇️
lightning/src/ln/payment_tests.rs 95.65% <90.90%> (-0.29%) ⬇️
lightning/src/sync/debug_sync.rs 80.00% <92.85%> (-0.35%) ⬇️
lightning/src/ln/channelmanager.rs 85.81% <94.73%> (-0.04%) ⬇️
lightning/src/sync/nostd_sync.rs 37.50% <100.00%> (+2.20%) ⬆️
lightning/src/sync/test_lockorder_checks.rs 100.00% <100.00%> (ø)
lightning/src/util/test_utils.rs 66.73% <100.00%> (ø)
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@valentinewallace valentinewallace force-pushed the 2023-02-dedup-pending-forwardable-evs branch from 6074e8a to 6e7c91e Compare February 11, 2023 20:50
@valentinewallace
Copy link
Contributor Author

Ended up having to pull in some changes from #2008 so I based it on that.

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.

Tentative LGTM, but I need to do more digging on the retry stuff to understand abandoning in 2dcb379

fn push_pending_forwards_ev(&self) {
let mut pending_events = self.pending_events.lock().unwrap();
let forward_ev_exists = pending_events.iter()
.find(|ev| if let events::Event::PendingHTLCsForwardable { .. } = ev { true } else { false })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol if our MSRV was just one minor version up (1.42) we could just

.find(|ev| matches!(ev, events::Event::PendingHTLCsForwardable))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soclose 🥲

@TheBlueMatt
Copy link
Collaborator

Needs rebase.

@valentinewallace valentinewallace force-pushed the 2023-02-dedup-pending-forwardable-evs branch from 2dcb379 to 91be2cc Compare February 17, 2023 16:02
// We only want to push a PendingHTLCsForwardable event if no others are queued.
fn push_pending_forwards_ev(&self) {
let mut pending_events = self.pending_events.lock().unwrap();
let forward_ev_exists = pending_events.iter()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, oops, this check isn't sufficient - I mean it reduces duplication, but the issue is we send the user a PendingHTLCsForwardable event, then they wait (during which time we don't have one lying around here) and then they call pending_htlcs_forwardable. Avoiding duplicating entirely is gonna be a bit hard, but I think we could at least only have two in-flight ones at once by filtering the outbound_payment-generated one on needs_abandon (but under the same lock as the update in fail_htlc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see the case we're not covering. I don't think we'd want needs_abandon, though, seems we'd want a new needs_retry check IIUC. Will add this. (Note that needs_abandon should only apply to restart since we set all payments as non-retryable on deser.)

@valentinewallace valentinewallace force-pushed the 2023-02-dedup-pending-forwardable-evs branch from 91be2cc to a2489b1 Compare February 17, 2023 22:43
@TheBlueMatt
Copy link
Collaborator

Thanks, LGTM, I think.

@TheBlueMatt TheBlueMatt merged commit 558b2f2 into lightningdevkit:main Feb 19, 2023
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.

5 participants