Ensure monitors are not archived if they have a preimage we need#3450
Merged
TheBlueMatt merged 1 commit intolightningdevkit:mainfrom Dec 11, 2024
Merged
Conversation
When a `ChannelMonitor` sees a payment preimage on chain for an outbound HTLC, it creates a `MonitorEvent` containing the preimage to pass to the inbound edge. The inclusion of the transaction containing the payment preimage (plus six confirmations) also results in the corresponding `Balance` being removed from the live balance set, allowing the `ChannelMonitor` to be pruned (after a further 4032 blocks). While `MonitorEvent`s should always be processed in a timely manner, if a node is suffering from a bug where they are not, its possible for 4038 blocks to pass with the preimage-containing `MonitorEvent` still pending. If that happens, its possible the `ChannelMonitor` is archived even though the preimage in it is needed in another channel (or `ChannelMonitor`), causing funds loss. Luckily the fix is simple - check for pending events before allowing a `ChannelMonitor` to be archived. Fixes lightningdevkit#2153
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3450 +/- ##
==========================================
- Coverage 89.69% 89.68% -0.02%
==========================================
Files 130 130
Lines 107403 107465 +62
Branches 107403 107465 +62
==========================================
+ Hits 96340 96382 +42
- Misses 8670 8683 +13
- Partials 2393 2400 +7 ☔ View full report in Codecov by Sentry. |
arik-so
approved these changes
Dec 10, 2024
Contributor
arik-so
left a comment
There was a problem hiding this comment.
LGTM, too.
1.63.0 test failure appears unrelated; I restarted it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
ChannelMonitorsees a payment preimage on chain for an outbound HTLC, it creates aMonitorEventcontaining the preimage to pass to the inbound edge. The inclusion of the transaction containing the payment preimage (plus six confirmations) also results in the correspondingBalancebeing removed from the live balance set, allowing theChannelMonitorto be pruned (after a further 4032 blocks).While
MonitorEvents should always be processed in a timely manner, if a node is suffering from a bug where they are not, its possible for 4038 blocks to pass with the preimage-containingMonitorEventstill pending. If that happens, its possible theChannelMonitoris archived even though the preimage in it is needed in another channel (orChannelMonitor), causing funds loss.Luckily the fix is simple - check for pending events before allowing a
ChannelMonitorto be archived.Fixes #2153