Skip to content

Hold in-flight monitor updates until background event processing#4377

Open
wpaulino wants to merge 1 commit intolightningdevkit:mainfrom
wpaulino:hold-in-flight-updates-until-background-event-processing
Open

Hold in-flight monitor updates until background event processing#4377
wpaulino wants to merge 1 commit intolightningdevkit:mainfrom
wpaulino:hold-in-flight-updates-until-background-event-processing

Conversation

@wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Feb 4, 2026

We previously assumed background events would eventually be processed prior to another ChannelManager write, so we would immediately remove all in-flight monitor updates that completed since the last ChannelManager serialization. This isn't always the case, so we now keep them all around until we're ready to handle them, i.e., when process_background_events is called.

This was discovered while fuzzing chanmon_consistency_target on the main branch with some changes that allow it to connect blocks. It was triggered by reloading the ChannelManager after a monitor update completion for an outgoing HTLC, calling ChannelManager::best_block_updated, and reloading the ChannelManager once again. A test is included that provides a minimal reproduction of this case.

@wpaulino wpaulino added this to the 0.3 milestone Feb 4, 2026
@wpaulino wpaulino requested a review from TheBlueMatt February 4, 2026 01:09
@wpaulino wpaulino self-assigned this Feb 4, 2026
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 4, 2026

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.01%. Comparing base (817ab5e) to head (55d9ef0).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 91.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4377      +/-   ##
==========================================
- Coverage   86.01%   86.01%   -0.01%     
==========================================
  Files         156      156              
  Lines      102857   102879      +22     
  Branches   102857   102879      +22     
==========================================
+ Hits        88476    88492      +16     
- Misses      11871    11875       +4     
- Partials     2510     2512       +2     
Flag Coverage Δ
tests 86.01% <91.66%> (-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.

for event in background_events.drain(..) {
match event {
BackgroundEvent::MonitorUpdateRegeneratedOnStartup { counterparty_node_id, funding_txo, channel_id, update } => {
// We previously assumed background events would eventually be processed prior
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure we need this change in this case? The whole point of RegeneratedOnStartup is that we don't care if we lose it cause it'll be regenerated when we restart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I misinterpreted how this specific case works.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@wpaulino wpaulino force-pushed the hold-in-flight-updates-until-background-event-processing branch from 2a15c45 to c880d85 Compare February 5, 2026 00:21
@wpaulino wpaulino requested a review from TheBlueMatt February 5, 2026 00:21
We previously assumed background events would eventually be processed
prior to another `ChannelManager` write, so we would immediately remove
all in-flight monitor updates that completed since the last
`ChannelManager` serialization. This isn't always the case, so we now
keep them all around until we're ready to handle them, i.e., when
`process_background_events` is called.

This was discovered while fuzzing `chanmon_consistency_target` on the
main branch with some changes that allow it to connect blocks. It was
triggered by reloading the `ChannelManager` after a monitor update
completion for an outgoing HTLC, calling
`ChannelManager::best_block_updated`, and reloading the `ChannelManager`
once again. A test is included that provides a minimal reproduction of
this case.
@wpaulino wpaulino force-pushed the hold-in-flight-updates-until-background-event-processing branch from c880d85 to 55d9ef0 Compare February 5, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants