-
Notifications
You must be signed in to change notification settings - Fork 421
Correctly handle new ChannelMonitorUpdate
s to old post-FC chans
#4136
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
Correctly handle new ChannelMonitorUpdate
s to old post-FC chans
#4136
Conversation
👋 Thanks for assigning @joostjager as a reviewer! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4136 +/- ##
==========================================
+ Coverage 88.62% 88.63% +0.01%
==========================================
Files 180 180
Lines 134895 135243 +348
Branches 134895 135243 +348
==========================================
+ Hits 119546 119877 +331
- Misses 12587 12600 +13
- Partials 2762 2766 +4
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:
|
🔔 1st Reminder Hey @wpaulino! This PR has been waiting for your review. |
🔔 2nd Reminder Hey @wpaulino! This PR has been waiting for your review. |
.get_mut(&channel_id) | ||
.expect("Channels originating a payment resolution must have a monitor"); | ||
*update_id += 1; | ||
*update_id = update_id.saturating_add(1); |
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.
Given the current and future caveats described in the commit msg, does this need a log on overflow?
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.
Hmm, not sure if its really needed. Maybe the commit message isn't clear, but I don't see any issues with this with the current code. I do call out that its possible that other code changes in the future which introduces an issue, but I don't think we really need to log a warning on the assumption that future code might break really ancient channel closes.
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.
No, I think the commit message is clear.
For someone looking at this statement though, it must be hard to understand why this is safe. I thought a warning log would both help debug any future issue with this, and at the same time add a bit more documentation. Or maybe move some of the commit message to a code comment.
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 added comments.
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.
It's still pretty thin and doesn't explain why it is okay to not increment when at the max already.
🔔 3rd Reminder Hey @wpaulino! This PR has been waiting for your review. |
0813413
to
ecc0da7
Compare
In 0.1 (1481216) we started setting `ChannelMonitorUpdate::update_id` to a non-`u64::MAX` value for updates generated after a channel has been closed. This is great, but in 71a364c we then started calculating the next `update_id` by incrementing the last `update_id` we saw when we started and were looking at the `ChannelMonitor`. However, the last-applied `update_id` may well be `u64::MAX` for old `ChannelMonitor`s which were closed prior to 0.1. In that case the increment would overflow. Here we fix this naively by simply replacing the increment with a `saturating_add`. While its possible this will result in a `ChannelMonitorUpdate` being tracked as in-flight (only for the `ReleasePaymentComplete` updates added in 71a364c) at the same `update_id` as other updates already in-flight and handling post-`ChannelMonitorUpdate` actions too early, this should only apply to releasing payment complete updates, which have no post-`ChannelMonitorUpdate` action. Its also possible that this leads to a regression in the future, where we have some new post-closure update that does have a post-`ChannelMonitorUpdate` action and we run it too early, but by then presumably its fairly rare to have a `ChannelMonitor` for a channel closed pre-0.1 that still needs multiple updates.
ecc0da7
to
dd21fce
Compare
.get_mut(&channel_id) | ||
.expect("Channels originating a payment resolution must have a monitor"); | ||
*update_id += 1; | ||
*update_id = update_id.saturating_add(1); |
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.
It's still pretty thin and doesn't explain why it is okay to not increment when at the max already.
In 0.1 (1481216) we started setting
ChannelMonitorUpdate::update_id
to a non-u64::MAX
value for updates generated after a channel has been closed.This is great, but in 71a364c we then started calculating the next
update_id
by incrementing the lastupdate_id
we saw when we started and were looking at theChannelMonitor
. However, the last-appliedupdate_id
may well beu64::MAX
for oldChannelMonitor
s which were closed prior to 0.1. In that case the increment would overflow.Here we fix this naively by simply replacing the increment with a
saturating_add
. While its possible this will result in aChannelMonitorUpdate
being tracked as in-flight (only for theReleasePaymentComplete
updates added in 71a364c) at the sameupdate_id
as other updates already in-flight and handling post-ChannelMonitorUpdate
actions too early, this should only apply to releasing payment complete updates, which have no post-ChannelMonitorUpdate
action.Its also possible that this leads to a regression in the future, where we have some new post-closure update that does have a post-
ChannelMonitorUpdate
action and we run it too early, but by then presumably its fairly rare to have aChannelMonitor
for a channel closed pre-0.1 that still needs multiple updates.