Skip to content

Skip ChannelManager persistence after monitor update completion#4424

Draft
joostjager wants to merge 2 commits intolightningdevkit:mainfrom
joostjager:skip-cm-persist-monitor-completed
Draft

Skip ChannelManager persistence after monitor update completion#4424
joostjager wants to merge 2 commits intolightningdevkit:mainfrom
joostjager:skip-cm-persist-monitor-completed

Conversation

@joostjager
Copy link
Contributor

Since we are pulling ChannelManager persistence into the critical path, we should avoid persisting unnecessarily. When process_pending_monitor_events processes only Completed events, the resulting state changes are all recoverable on restart and do not require persistence.

Return NotifyOption from process_pending_monitor_events instead of bool, returning SkipPersistHandleEvents for Completed events and DoPersist for HTLCEvent/HolderForceClosed/CommitmentTxConfirmed.

Since we are pulling ChannelManager persistence into the critical
path, we should avoid persisting unnecessarily. When
process_pending_monitor_events processes only Completed events, the
resulting state changes are all recoverable on restart and do not
require persistence.

Return NotifyOption from process_pending_monitor_events instead of
bool, returning SkipPersistHandleEvents for Completed events and
DoPersist for HTLCEvent/HolderForceClosed/CommitmentTxConfirmed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

if result == NotifyOption::SkipPersistNoEvents {
result = NotifyOption::SkipPersistHandleEvents;
}
self.channel_monitor_updated(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to carefully review everything this calls to make sure they set the store-required flag. Might be easier to just manually set the flag if there's anything to do in handle_post_monitor_update_chan_resume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By "anything to do in handle_post_monitor_update_chan_resume", do you mean specifically a new monitor update being created? Or is there more that isn't recoverable on restart?

Added a commit that sets needs_persist_flag in handle_new_monitor_update_locked_actions_handled_by_caller right after chain_monitor.update_channel to cover that case.

Have to say that certainty level instantly drops when working on this state machine 😬

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 have an alternative approach on that is more conservative in stripping out persists: https://github.com/joostjager/rust-lightning/tree/skip-cm-persist-monitor-completed-alt

Rather than skipping persistence for all MonitorEvent::Completed events unconditionally, it inspects the result of monitor_updating_restored and only skips persistence when the effect is just queuing outbound messages (commitment_signed, revoke_and_ack). But also needs to be carefully reviewed to see if we don't miss anything.

When a ChannelMonitorUpdate is sent to the chain monitor, the
ChannelManager must be persisted so that in_flight_monitor_updates
stays in sync. Most callers already ensure this via
PersistenceNotifierGuard, but handle_monitor_update_release (reached
from the Completed event path in channel_monitor_updated) does not.

Set needs_persist_flag directly in
handle_new_monitor_update_locked_actions_handled_by_caller, right
after calling chain_monitor.update_channel, making the invariant
self-enforcing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.91%. Comparing base (d09f1d2) to head (c891c48).

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4424      +/-   ##
==========================================
- Coverage   85.91%   85.91%   -0.01%     
==========================================
  Files         156      156              
  Lines      103958   103965       +7     
  Branches   103958   103965       +7     
==========================================
+ Hits        89317    89323       +6     
+ Misses      12122    12118       -4     
- Partials     2519     2524       +5     
Flag Coverage Δ
tests 85.91% <93.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joostjager joostjager self-assigned this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants

Comments