Skip to content

Allow stale ChannelMonitors if we are sure they don't have funds - #4146

Merged
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2025-10-less-panicy-reads
Oct 9, 2025
Merged

Allow stale ChannelMonitors if we are sure they don't have funds#4146
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2025-10-less-panicy-reads

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

In 601bf4b we started refusing to load ChannelMonitors which were created prior to LDK 0.0.110 and which were last updated prior to LDK 0.0.116. While this is likely fine for nearly all of our users, there's some risk that some (like me) have ancient un-archived ChannelMonitors.

We do need to start auto-archiving ChannelMonitors but for now we need some way for such users to at least not fail on startup. Sadly, ancient ChannelMonitors often don't contain some of the data we need to accurately calculate Balances, but in cases where they do, and where there are no claimable Balances, we can be confident we don't need the ChannelMonitors.

Thus, here, we adapt the ChannelMonitorReadable implementation used in the persistence wrappers to detect this case and simply skip loading such ChannelMonitors. Its not clear if this is sufficient, but its at least better than the current state of affairs after 601bf4b.

@TheBlueMattTheBlueMatt added this to the 0.2 milestone Oct 7, 2025
@ldk-reviews-bot

ldk-reviews-bot commented Oct 7, 2025

Copy link
Copy Markdown

I've assigned @jkczyz 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.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-10-less-panicy-reads branch 2 times, most recently from 58ad915 to 2b29c85CompareOctober 8, 2025 10:51
@codecov

codecovBot commented Oct 8, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.73%. Comparing base (2efb009) to head (b1fc759).
⚠️ Report is 15 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/util/persist.rs53.33%16 Missing and 5 partials ⚠️
lightning/src/chain/channelmonitor.rs66.66%6 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4146 +/- ##
==========================================
+ Coverage 88.63% 88.73% +0.09% 
==========================================
Files 180 180 Lines 135241 135568 +327 Branches 135241 135568 +327 ==========================================
+ Hits 119869 120294 +425 + Misses 12607 12506 -101 - Partials 2765 2768 +3 
FlagCoverage Δ
fuzzing21.71% <6.34%> (-0.05%)⬇️
tests88.57% <55.55%> (+0.09%)⬆️

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.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-10-less-panicy-reads branch from 2b29c85 to 696e213CompareOctober 8, 2025 13:19
} else {
panic!("Found monitor for channel {channel_id} with no updates since v0.0.118. \
These monitors are no longer supported. \
To continue, run a v0.1 release, send/route a payment over the channel or close it.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, so what if the monitor is already closed and you still have balances to claim? Is there any way you can realistically start up? I guess this would be pretty unlikely, unless you have an outbound payment you still need to time out on chain.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

No, you can't without manually deleting the monitor from your store. It really sucks and I'm not really happy with the state of things but it seems a bit late to walk this back :/

// return Ok(None) to allow it to be skipped and not loaded.
return Ok(None);
} else {
panic!("Found monitor for channel {channel_id} with no updates since v0.0.118. \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This mentions 0.0.118 but the commit mentions 0.0.116

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Oh, that is from 601bf4b. I'll fix but looks like it was actually in 0.0.119

});

if counterparty_node_id.is_none() {
if (holder_tx_signed || lockdown_from_offchain) && monitor.get_claimable_balances().is_empty() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we actually need to bother checking for (holder_tx_signed || lockdown_from_offchain)?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Probably not but it seemed like a nice additional check to include cause I'm not at all confident in the balance set for really old monitors.

@TheBlueMatt
TheBlueMattforce-pushed the 2025-10-less-panicy-reads branch from 696e213 to 74ec7a6CompareOctober 9, 2025 17:23
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Tweaked the commit message to refer to the correct version number and also pushed a small fixup.

@wpaulino

Copy link
Copy Markdown
Contributor

LGTM after squash

In 601bf4b we started refusing to
load `ChannelMonitor`s which were created prior to LDK 0.0.110 and
which were last updated prior to LDK 0.0.119. While this is likely
fine for nearly all of our users, there's some risk that some (like
me) have ancient un-archived `ChannelMonitor`s.
We do need to start auto-archiving `ChannelMonitor`s but for now we
need some way for such users to at least not fail on startup.
Sadly, ancient `ChannelMonitor`s often don't contain some of the
data we need to accurately calculate `Balance`s, but in cases where
they do, and where there are no claimable `Balance`s, we can be
confident we don't need the `ChannelMonitor`s.
Thus, here, we adapt the `ChannelMonitor` `Readable` implementation
used in the persistence wrappers to detect this case and simply
skip loading such `ChannelMonitor`s. Its not clear if this is
sufficient, but its at least better than the current state of
affairs after 601bf4b.
@TheBlueMatt
TheBlueMattforce-pushed the 2025-10-less-panicy-reads branch from 74ec7a6 to b1fc759CompareOctober 9, 2025 18:23
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

This is a trivial patch, at least if you take get_claimable_balances at face value. I'm not 100% confident in it for ancient monitors, but presumably ancient monitors don't have any funds remaining to claim. I'm also not sure that this is enough for all our users, but its better than the current state of things. Gonna go ahead and land because its straightforward, but @jkczyz can take a look at it later if he wants.

@TheBlueMatt
TheBlueMatt merged commit 3e79de2 into lightningdevkit:mainOct 9, 2025
22 checks passed
Comment threadlightning/src/util/persist.rs
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

This landed before 0.2 so doesn't need backport.

TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request Oct 30, 2025
If we fail to load a `ChannelMonitor` due to the new limits in LDK
0.2, its useful to communicate which monitor failed, which we do
here.
Requested at
lightningdevkit#4146 (comment)
TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request Oct 30, 2025
If we fail to load a `ChannelMonitor` due to the new limits in LDK
0.2, its useful to communicate which monitor failed, which we do
here.
Requested at
lightningdevkit#4146 (comment)
TheBlueMatt added a commit to TheBlueMatt/rust-lightning that referenced this pull request Oct 30, 2025
If we fail to load a `ChannelMonitor` due to the new limits in LDK
0.2, its useful to communicate which monitor failed, which we do
here.
Requested at
lightningdevkit#4146 (comment)
Backport of a4f4663
Sign up for freeto 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.

4 participants

@TheBlueMatt@ldk-reviews-bot@wpaulino@jkczyz