Skip to content

Persist unresolved ChannelMonitors on empty height change #3442

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

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented Dec 5, 2024

This hopefully fixes #3121.

@tnull tnull self-requested a review December 5, 2024 18:01
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Thanks!

have_monitors_to_prune = true;
let (is_fully_resolved, needs_persistence) = monitor_holder.monitor.process_claim_resolution_status(&logger);
if is_fully_resolved || needs_persistence {
have_monitors_to_persist_or_prune = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can keep the bool as it was, we don't need the write lock to persist a monitor, we can do that in this loop and only do the bottom block if we need to prune.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/// This function returns true only if [`Self::get_claimable_balances`] has been empty for at least
/// This function returns a tuple of two booleans, the first indicating whether the monitor is
/// fully resolved, and the second whether the monitor needs persistence as a consequence of
/// checking its claim resolution status.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is kinda weird "checking -> needs persistence" should be explained a bit. Maybe "the second whether the monitor needs persistence to ensure it is reliably marked as resolved in 4032 blocks."?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/// 4032 blocks as an additional protection against any bugs resulting in spuriously empty balance sets.
pub fn is_fully_resolved<L: Logger>(&self, logger: &L) -> bool {
pub fn process_claim_resolution_status<L: Logger>(&self, logger: &L) -> (bool, bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe check_update_fully_resolved_status? claim (singular) is a bit weird as we're not talking about a specific claim but rather all possible funds to claim. Also nice to give it a clear "update" in the name cause we might need to persist and we're updating the fully-resolved-status so that it clears in 4k blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly hate every name I could come up with and this one, too, but I guess it's the least bad option. I added an and, but can drop it if you prefer

@TheBlueMatt TheBlueMatt added this to the 0.1 milestone Dec 5, 2024
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.14%. Comparing base (726dd5c) to head (0a3c718).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3442      +/-   ##
==========================================
+ Coverage   89.69%   90.14%   +0.45%     
==========================================
  Files         130      130              
  Lines      107335   110095    +2760     
  Branches   107335   110095    +2760     
==========================================
+ Hits        96273    99249    +2976     
+ Misses       8660     8522     -138     
+ Partials     2402     2324      -78     

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

@arik-so arik-so marked this pull request as ready for review December 6, 2024 11:21
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Two doc nits otherwise LGTM, feel free to just fix the nits and squash in one go.

@@ -1994,10 +1994,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {

/// Checks if the monitor is fully resolved. Resolved monitor is one that has claimed all of
/// its outputs and balances (i.e. [`Self::get_claimable_balances`] returns an empty set).
/// Additionally updates the empty balances height if necessary.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure we expect users to know what the "empty balances height" is :).

Suggested change
/// Additionally updates the empty balances height if necessary.
/// Additionally may update state to track when the balances set became empty.

@arik-so arik-so force-pushed the archive-monitor-persistence-trigger branch from 0a3c718 to 6f9300f Compare December 6, 2024 16:27
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

This is trivial, it just a new return value and code to handle it. Commit really could have used a description but its not worth holding this up on that.

@TheBlueMatt TheBlueMatt merged commit 020be44 into lightningdevkit:main Dec 6, 2024
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.

Persist ChannelMonitor after first setting balances_empty_height in archive_fully_resolved_channel_monitors
2 participants