Skip to content

Ensure ChannelMonitorUpdates are ordered with full monitor writes #3196

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
merged 1 commit into from
Jul 23, 2024

Conversation

TheBlueMatt
Copy link
Collaborator

When we update a channel, then while connecting a block persist a full ChannelMonitor prior to persisting the
ChannelMonitorUpdate, users can end up seeing a full ChannelMonitor with a given latest_update_id prior to seeing the ChannelMonitorUpdate with the same update_id. This could cause users to have a full ChannelMonitor on disk as well as a ChannelMonitorUpdate which was already applied. While this isn't an issue for the LDK-provided update-based Persist, its somewhat surprising for users so we avoid it.

I fought for a while with actually changing the locking structure to enforce this, but it ended up breaking the LockedChannelMonitor stuff so I gave up.

When we update a channel, then while connecting a block persist a
full `ChannelMonitor` prior to persisting the
`ChannelMonitorUpdate`, users can end up seeing a full
`ChannelMonitor` with a given `latest_update_id` prior to seeing
the `ChannelMonitorUpdate` with the same `update_id`. This
could cause users to have a full `ChannelMonitor` on disk as well
as a `ChannelMonitorUpdate` which was already applied. While this
isn't an issue for the LDK-provided update-based `Persist`, its
somewhat surprising for users so we avoid it.
@TheBlueMatt TheBlueMatt added this to the 0.0.124 milestone Jul 20, 2024
Copy link

codecov bot commented Jul 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.74%. Comparing base (9ce3dd5) to head (036c31c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3196      +/-   ##
==========================================
- Coverage   89.78%   89.74%   -0.04%     
==========================================
  Files         121      121              
  Lines      100932   100933       +1     
  Branches   100932   100933       +1     
==========================================
- Hits        90619    90582      -37     
- Misses       7635     7663      +28     
- Partials     2678     2688      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

/// update_persisted_channel, the user returns a
/// Note that this lock must be held from [`ChannelMonitor::update_monitor`] through to
/// [`Persist::update_persisted_channel`] to prevent a race where we call
/// [`Persist::update_persisted_channel`], the user returns a
/// [`ChannelMonitorUpdateStatus::InProgress`], and then calls channel_monitor_updated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since you're already here, mind ticking/linkng channel_monitor_updated / Vec as well?

/// persist a full [`ChannelMonitor`] prior to persisting the [`ChannelMonitorUpdate`]. This
/// could cause users to have a full [`ChannelMonitor`] on disk as well as a
/// [`ChannelMonitorUpdate`] which was already applied. While this isn't an issue for the
/// LDK-provided update-based [`Persist`], its somewhat surprising for users so we avoid it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// LDK-provided update-based [`Persist`], its somewhat surprising for users so we avoid it.
/// LDK-provided update-based [`Persist`], it is somewhat surprising for users so we avoid it.

Copy link
Contributor

@G8XSU G8XSU left a comment

Choose a reason for hiding this comment

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

Lgtm!

@tnull
Copy link
Contributor

tnull commented Jul 23, 2024

Going ahead and land this, nits could still be addressed in a follow up.

@tnull tnull merged commit 951174a into lightningdevkit:main Jul 23, 2024
18 of 19 checks passed
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.

3 participants