Skip to content
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

Claim HTLCs with preimage from currently confirmed commitment #2623

Conversation

wpaulino
Copy link
Contributor

This PR ensures that we produce HTLC preimage claims from the intended commitment when we see a counterparty commitment confirm onchain and another commitment (either another counterparty one or a holder) confirms instead via a reorg. Previously, in such a case, we'd always claim from the latest or previous counterparty commitment, even when the currently confirmed commitment is a different one.

@wpaulino wpaulino added this to the 0.0.117 milestone Sep 29, 2023
@TheBlueMatt
Copy link
Collaborator

Please reorder the commits so that we pass tests as of each commit.

We should always claim HTLCs from the currently confirmed commitment,
rather than always claiming from the latest or previous counterparty
commitment if we've seen either confirm onchain at a prior point.
This test adds coverage for receiving a preimage after seeing a
counterparty commitment confirm, followed by a reorg and the
confirmation of a different commitment instead.

The first test covers the case where a holder commitment confirms after
the counterparty commitment reorg.

The second test covers the case where a previous counterparty commitment
confirms after the latest counterparty commitment reorg.
@wpaulino wpaulino force-pushed the htlc-claim-receive-preimage-after-close branch from 308affa to d82e6ba Compare September 29, 2023 16:59
@codecov-commenter
Copy link

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (6016101) 89.03% compared to head (d82e6ba) 88.98%.
Report is 6 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2623      +/-   ##
==========================================
- Coverage   89.03%   88.98%   -0.05%     
==========================================
  Files         112      112              
  Lines       86351    86497     +146     
  Branches    86351    86497     +146     
==========================================
+ Hits        76879    76970      +91     
- Misses       7235     7288      +53     
- Partials     2237     2239       +2     
Files Coverage Δ
lightning/src/ln/reorg_tests.rs 99.36% <99.16%> (-0.05%) ⬇️
lightning/src/chain/channelmonitor.rs 84.71% <69.69%> (-0.18%) ⬇️

... and 6 files with indirect coverage changes

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

@TheBlueMatt TheBlueMatt merged commit fbc86cb into lightningdevkit:main Sep 29, 2023
13 of 15 checks passed
@wpaulino wpaulino deleted the htlc-claim-receive-preimage-after-close branch September 29, 2023 18:54
Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Post-merge Code Review ACK d82e6ba, though didn’t look more than into the test.

Effectively this can be a safety issue in case of reorgs.

if let Some(commitment_number) = self.counterparty_commitment_txn_on_chain.get(&txid) {
claim_htlcs!(*commitment_number, txid);
if txid == confirmed_spend_txid {
if let Some(commitment_number) = self.counterparty_commitment_txn_on_chain.get(&txid) {
Copy link

Choose a reason for hiding this comment

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

Sounds counterparty_commitment_txn_on_chain and FundingSpendConfirmation could be merged in a single data struct, as there is a redundancy we might store the same txid both as a FundingSpendConfirmation { commitment_tx_to_counterparty_output and hashmap entry.

Sign up for free to 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.

None yet

5 participants