-
Notifications
You must be signed in to change notification settings - Fork 385
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
Claim HTLCs with preimage from currently confirmed commitment #2623
Conversation
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.
308affa
to
d82e6ba
Compare
Codecov ReportAttention:
❗ 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
☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
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.