-
Notifications
You must be signed in to change notification settings - Fork 386
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
Setup Support for delaying ChannelMonitorUpdate
flight until an Event
completes
#2111
Setup Support for delaying ChannelMonitorUpdate
flight until an Event
completes
#2111
Conversation
2aae7c8
to
91707fb
Compare
Codecov ReportPatch coverage:
📣 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 #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56%
==========================================
Files 104 105 +1
Lines 51930 61222 +9292
Branches 51930 61222 +9292
==========================================
+ Hits 47556 56410 +8854
- Misses 4374 4812 +438
☔ View full report in Codecov by Sentry. |
91707fb
to
c595331
Compare
57bebe7
to
9852b84
Compare
lightning/src/ln/channel.rs
Outdated
@@ -3230,8 +3246,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> { | |||
} | |||
log_debug!(logger, "Received valid commitment_signed from peer in channel {}, updated HTLC state but awaiting a monitor update resolution to reply.", | |||
log_bytes!(self.channel_id)); | |||
self.pending_monitor_updates.push(monitor_update); | |||
return Ok(self.pending_monitor_updates.last().unwrap()); | |||
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown); |
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.
Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec
?
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.
Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.
9852b84
to
2ba5289
Compare
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.
Feel free to squash the existing fixups
ae76ed0
to
08ae599
Compare
Feel free to squash, will give it a final pass after a second reviewer. |
08ae599
to
d2d3036
Compare
Squashed without further changes. |
d2d3036
to
207af69
Compare
207af69
to
7014813
Compare
Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced. |
7014813
to
a626549
Compare
Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115. |
6f1263d
to
87bcf91
Compare
87bcf91
to
51c3b37
Compare
Rebased. |
Will do another full pass after squash |
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.
Looks good
$chan.get_latest_monitor_update_id() == $update_id | ||
{ | ||
$chan.complete_one_mon_update($update_id); | ||
if $chan.no_monitor_updates_pending() { |
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.
I think we can use this check in channel_monitor_updated
too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion
macro
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.
Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.
In the coming commits, we need to delay `ChannelMonitorUpdate`s until future actions (specifically `Event` handling). However, because we should only notify users once of a given `ChannelMonitorUpdate` and they must be provided in-order, we need to track which ones have or have not been given to users and, once updating resumes, fly the ones that haven't already made it to users. To do this we simply add a `bool` in the `ChannelMonitorUpdate` set stored in the `Channel` which indicates if an update flew and decline to provide new updates back to the `ChannelManager` if any updates have their flown bit unset. Further, because we'll now by releasing `ChannelMonitorUpdate`s which were already stored in the pending list, we now need to support getting a `Completed` result for a monitor which isn't the only pending monitor (or even out of order), thus we also rewrite the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event` processing in the next commit. Note that this gets dangerously close to breaking forwards compatibility - if we have an `Event` with an `EventCompletionAction` tied to it, we persist a new, even, TLV in the `ChannelManager`. Hopefully this should be uncommon, as it implies an `Event` was delayed until after a full round-trip to a peer.
This adds handling of the new `EventCompletionAction`s after `Event`s are handled, letting `ChannelMonitorUpdate`s which were blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold `ChannelMonitorUpdate`s which are pending until we're ready to pass them to users and have them be applied. However, if the `ChannelManager` is persisted while we're waiting to give the user a `ChannelMonitorUpdate` we'll be confused on restart - seeing our latest `ChannelMonitor` state as stale compared to our `ChannelManager` - a critical error. Luckily the solution is trivial, we simply need to store the pending `ChannelMonitorUpdate` state and load it with the `ChannelManager` data, allowing stale monitors on load as long as we have the missing pending updates between where we are and the latest `ChannelMonitor` state.
51c3b37
to
9dfe42c
Compare
Squashed without further changes. |
Looks good after @wpaulino takes another look! |
880d88e
to
9c36735
Compare
oops sorry that commit was buggy, sec |
Actually, just gonna drop the last/new commit, its...hard, so we need to (a) |
9c36735
to
9dfe42c
Compare
The tests on #2112 failed with that commit, specifically, like all the tests. |
This does all the work that will be required to pause
ChannelMonitorUpdate
flight until anEvent
completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commitTrack an EventCompletionAction for after an Event is processed
indicates -Still, I'm open to discussion on it -
Event
s generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.