Fix async release before HTLC decode#4548
Fix async release before HTLC decode#4548valentinewallace wants to merge 2 commits intolightningdevkit:mainfrom
Conversation
|
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
|
After thoroughly reviewing every file and hunk in this PR diff — tracing all race condition windows, lock ordering, state machine transitions, and serialization correctness — I found no new issues. Review SummaryNo issues found. Prior comment statusAll prior review comments are resolved or no longer applicable in this version of the PR:
Architecture assessmentThe approach is clean and correct:
|
tnull
left a comment
There was a problem hiding this comment.
Mostly looks good, CI is just failing due to some broken doc links AFAICT.
Also validated this still works in conjunction with #4463 / for lightningdevkit/ldk-node#817.
ae776b9 to
bd632fb
Compare
|
Addressed feedback with diff (plus an extra push for a whitespace fix). |
bd632fb to
f764872
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4548 +/- ##
==========================================
+ Coverage 86.99% 87.01% +0.01%
==========================================
Files 163 163
Lines 108635 108682 +47
Branches 108635 108682 +47
==========================================
+ Hits 94511 94572 +61
+ Misses 11647 11631 -16
- Partials 2477 2479 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
lightning/src/ln/channelmanager.rs
Outdated
| ); | ||
| if pending_add.forward_info.routing.should_hold_htlc() { | ||
| let hold_htlc = if pending_add.forward_info.routing.should_hold_htlc() { | ||
| // Check whether a ReleaseHeldHtlc arrived after the manager pulled a copy of this |
There was a problem hiding this comment.
This feel like it should be fixed by taking an additional lock in handle_release_held_htlc rather than checking for it here?
There was a problem hiding this comment.
I don't believe so -- did you see this race condition? #4542 (comment) Maybe we don't support that kind of multithreaded usage anyway?
There was a problem hiding this comment.
Btw, if we try to acquire the decode_update_add_htlcs lock prior to taking the channel lock, which I think would fix a different race you may be pointing out here, it currently results in a lock order violation.
There was a problem hiding this comment.
Ok fixed in a nicer way that will avoid similar race conditions in the future, see the first commit
f764872 to
1231cb8
Compare
This avoids race conditions where we're unable to properly update an HTLC's state because we need to update its state in the ChannelManager, but the HTLC is stuck in transit from the Channel to ChannelManager::decode_update_add_htlcs. Now the HTLC will atomically go from the Channel to the ChannelManager decode queue under the same lock.
Handle `ReleaseHeldHtlc` messages that arrive before the sender-side LSP has even queued the held HTLC for onion decoding. Unlike lightningdevkit#4106, which covers releases arriving after the HTLC is in `decode_update_add_htlcs` but before it reaches `pending_intercepted_htlcs`, this preserves releases that arrive one step earlier and would otherwise be dropped as HTLC not found. Co-Authored-By: HAL 9000 Co-Authored-By: Elias Rohrer <dev@tnull.de>
1231cb8 to
2ebc372
Compare
Handle
ReleaseHeldHtlcmessages that arrive before the sender-side LSP has even queued the held HTLC for onion decoding. Unlike #4106, which covers releases arriving after the HTLC is indecode_update_add_htlcsbut before it reachespending_intercepted_htlcs, this preserves releases that arrive one step earlier and would otherwise be dropped as HTLC not found.Supersedes #4542