-
Notifications
You must be signed in to change notification settings - Fork 276
Add more force-close tests for HTLC settlement #3040
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
Merged
Merged
Conversation
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
t-bast
commented
Mar 19, 2025
While auditing our force-close code, I discovered that we were missing tests for scenarios where we must fail HTLCs back upstream. There are also important properties of various components that are crucial to funds safety and weren't explicitly spelled out or tested (such as the fact that redundant HTLC settlement commands are simply ignored in favor of the first settlement command created). I also took this opportunity to slightly refactor some of the closing code, improve comments and simplify code that tried being too clever, which could bite us in the future when introducing additional channel types.
98ad619 to
81a1a07
Compare
t-bast
added a commit
to ACINQ/lightning-kmp
that referenced
this pull request
Mar 25, 2025
This commit is importing test updates and refactoring to the closing helpers from ACINQ/eclair#3040 We don't relay HTLCs, so we don't have an upstream channel to relay preimages to, but it's important to relay preimages to the payment handler to correctly mark payments as succeeded (or failed) and store the proof of payment.
pm47
reviewed
Mar 25, 2025
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/db/PendingCommandsDb.scala
Outdated
Show resolved
Hide resolved
- Add preimage helper to `Scripts.scala` - Split `failedIncomingHtlcs` and `nonRelayedHtlcs` - Improve comment about failing HTLCs when revoked commit confirms
When we detect a transaction spending an HTLC output of a revoked commit, we now always try to generate the corresponding penalty txs. If that fails, it means that the spending transaction was actually one of our HTLC-penalty txs.
pm47
approved these changes
Mar 25, 2025
t-bast
added a commit
to ACINQ/lightning-kmp
that referenced
this pull request
Mar 25, 2025
This commit is importing test updates and refactoring to the closing helpers from ACINQ/eclair#3040 We don't relay HTLCs, so we don't have an upstream channel to relay preimages to, but it's important to relay preimages to the payment handler to correctly mark payments as succeeded (or failed) and store the proof of payment.
sstone
approved these changes
Mar 26, 2025
remyers
reviewed
Mar 27, 2025
t-bast
added a commit
that referenced
this pull request
Mar 27, 2025
t-bast
added a commit
to ACINQ/lightning-kmp
that referenced
this pull request
Mar 28, 2025
This commit is importing test updates and refactoring to the closing helpers from ACINQ/eclair#3040 We don't relay HTLCs, so we don't have an upstream channel to relay preimages to, but it's important to relay preimages to the payment handler to correctly mark payments as succeeded (or failed) and store the proof of payment.
docker-lordvf6ik
added a commit
to docker-lordvf6ik/lightning-kmp
that referenced
this pull request
Sep 28, 2025
This commit is importing test updates and refactoring to the closing helpers from ACINQ/eclair#3040 We don't relay HTLCs, so we don't have an upstream channel to relay preimages to, but it's important to relay preimages to the payment handler to correctly mark payments as succeeded (or failed) and store the proof of payment.
ebonyschneider462359
added a commit
to ebonyschneider462359/lightning-kmp
that referenced
this pull request
Oct 10, 2025
This commit is importing test updates and refactoring to the closing helpers from ACINQ/eclair#3040 We don't relay HTLCs, so we don't have an upstream channel to relay preimages to, but it's important to relay preimages to the payment handler to correctly mark payments as succeeded (or failed) and store the proof of payment.
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.
While auditing our force-close code, I discovered that we were missing tests for scenarios where we must fail HTLCs back upstream. There are also important properties of various components that are crucial to funds safety and weren't explicitly spelled out or tested (such as the fact that redundant HTLC settlement commands are simply ignored in favor of the first settlement command created).
I also took this opportunity to slightly refactor some of the closing code, improve comments and simplify code that tried being too clever, which could bite us in the future when introducing additional channel types.
Below is an overview of how eclair ensures that channels are safe, at a high-level. I would encourage reviewers to take their time going through this and do their own audit of our force-close code: this is important to get right and all contributors should master that part of the code to ensure they don't introduce security issues!
Watching funding transactions
Whenever we open a channel (single-funded or dual-funded):
WatchPublishedWatchFundingConfirmedfunding_createdwhen we're not the openerfunding_signedwhen we're the openertx_signaturesWatchPublishedtriggers, we setWatchFundingConfirmedWatchFundingConfirmedtriggers, we setWatchFundingSpentwhenUnhandledhas handlers forWatchPublishedTriggeredandWatchFundingConfirmedTriggeredWhenever we make a splice transaction:
tx_signatures:WatchPublishedWatchFundingConfirmedWatchPublishedtriggers, we setWatchFundingConfirmedWatchFundingConfirmedtriggers, we setWatchFundingSpentWhenever we restart:
INPUT_RESTORED, in which:WatchPublishedWatchFundingConfirmedWatchFundingSpentWatchFundingSpentHandling closing transactions
We detect that a funding transaction (including splice transactions) is spent by receiving
WatchFundingSpentTriggered:whenUnhandledto ensure that this happens regardless of the channel stateWatchAlternativeCommitTxConfirmedWatchAlternativeCommitTxConfirmedTriggered: