Skip to content

Drop forwarded HTLCs which were still pending at persist-time #1915

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

If, after forwarding an intercepted payment to our counterparty, we
restart with a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update not having been persisted,
we'll still have the intercepted HTLC in the
pending_intercepted_htlcs map on start (and potentially a pending
HTLCIntercepted event). This will cause us to allow the user to
handle the forwarded HTLC twice, potentially double-forwarding it.

This builds on 0bb87dd, which
provided a preemptive fix for the general relay case (though it was
not an actual issue at the time). We simply check for the HTLCs
having been forwarded on startup and remove them from the map.

Fixes #1858

@TheBlueMatt TheBlueMatt added this to the 0.0.113 milestone Dec 13, 2022
@tnull tnull self-requested a review December 13, 2022 08:35
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.

Looks good!

Just to improve the test's readability, it might be nice to leave a quick note on/before check_closed_event! call (https://github.com/TheBlueMatt/rust-lightning/blob/236780d261d76afe28e784bf43d9f75d3c71ecfa/lightning/src/ln/reload_tests.rs#L897) mentioning that this implies checking no HTLCIntercepted event is emitted in the use_intercept case?

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

CI isn't happy on older versions of rustc. LGTM otherwise.

error[E0070]: invalid left-hand side of assignment
   --> lightning/src/ln/reload_tests.rs:865:49
    |
865 |         (intercept_id, expected_outbound_amount_msat) = match events[0] {
    |         --------------------------------------------- ^
    |         |
    |         cannot assign to this expression
    |
    = note: destructuring assignments are not currently supported
    = note: for more information, see https://github.com/rust-lang/rfcs/issues/372

@codecov-commenter
Copy link

Codecov Report

Base: 90.71% // Head: 90.72% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (7889856) compared to base (5e14c24).
Patch coverage: 94.44% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1915      +/-   ##
==========================================
+ Coverage   90.71%   90.72%   +0.01%     
==========================================
  Files          94       94              
  Lines       49559    49603      +44     
  Branches    49559    49603      +44     
==========================================
+ Hits        44955    45001      +46     
+ Misses       4604     4602       -2     
Impacted Files Coverage Δ
lightning-invoice/src/utils.rs 97.02% <ø> (-0.75%) ⬇️
lightning/src/ln/channelmanager.rs 86.73% <88.88%> (+0.19%) ⬆️
lightning/src/ln/reload_tests.rs 95.55% <97.22%> (+0.05%) ⬆️
lightning/src/ln/functional_tests.rs 96.93% <0.00%> (-0.22%) ⬇️
lightning/src/chain/channelmonitor.rs 90.80% <0.00%> (-0.20%) ⬇️
lightning/src/chain/onchaintx.rs 95.17% <0.00%> (+0.62%) ⬆️
lightning/src/util/events.rs 29.35% <0.00%> (+3.89%) ⬆️

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.

@tnull
Copy link
Contributor

tnull commented Dec 13, 2022

Feel free to squash, I think.

If, after forwarding an intercepted payment to our counterparty, we
restart with a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update not having been persisted,
we'll still have the intercepted HTLC in the
`pending_intercepted_htlcs` map on start (and potentially a pending
`HTLCIntercepted` event). This will cause us to allow the user to
handle the forwarded HTLC twice, potentially double-forwarding it.

This builds on 0bb87dd, which
provided a preemptive fix for the general relay case (though it was
not an actual issue at the time). We simply check for the HTLCs
having been forwarded on startup and remove them from the map.

Fixes lightningdevkit#1858
@TheBlueMatt TheBlueMatt force-pushed the 2022-12-jit-reload-consistency branch from 7889856 to 2d68183 Compare December 13, 2022 19:34
@TheBlueMatt
Copy link
Collaborator Author

Squashed.

@TheBlueMatt TheBlueMatt merged commit d4dc05b into lightningdevkit:main Dec 13, 2022
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.

JIT Forwards Reload Consistency
4 participants