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

Address 2609 follow-up comments #2624

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

wpaulino
Copy link
Contributor

Fixes #2619.

@wpaulino wpaulino added this to the 0.0.117 milestone Sep 29, 2023
TheBlueMatt
TheBlueMatt previously approved these changes Sep 29, 2023
Three levels of descendant transactions starting from the channel's
funding transaction should cover all potential spendable outputs.

The first level covers the commitment transaction.

The second level covers the to_self claims, to_remote claims,
second-stage HTLC claims and justice transactions.

The third levels covers the justice transactions on second-stage HTLCs,
and to_self claims on second-stage HTLCs.
lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
Otherwise, we could give users a descriptor ahead of time that will
result in an invalid transaction spend/broadcast.
@codecov-commenter
Copy link

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (6016101) 89.03% compared to head (901571a) 88.97%.
Report is 8 commits behind head on main.

❗ Current head 901571a differs from pull request most recent head f267a30. Consider uploading reports for the commit f267a30 to get more accurate results

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2624      +/-   ##
==========================================
- Coverage   89.03%   88.97%   -0.06%     
==========================================
  Files         112      112              
  Lines       86351    86358       +7     
  Branches    86351    86358       +7     
==========================================
- Hits        76879    76836      -43     
- Misses       7235     7281      +46     
- Partials     2237     2241       +4     
Files Coverage Δ
lightning/src/chain/channelmonitor.rs 84.97% <100.00%> (+0.09%) ⬆️
lightning/src/ln/monitor_tests.rs 97.92% <100.00%> (-0.42%) ⬇️

... and 8 files with indirect coverage changes

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

@TheBlueMatt TheBlueMatt merged commit 955e810 into lightningdevkit:main Sep 29, 2023
@wpaulino wpaulino deleted the 2609-follow-up branch September 29, 2023 20:09
@@ -1680,8 +1682,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
/// missed/unhandled descriptors. For the purpose of gathering historical records, if the
/// channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
/// an empty set), you can retrieve all spendable outputs by providing all descendant spending
/// transactions starting from the channel's funding or closing transaction that have at least
/// [`ANTI_REORG_DELAY`] confirmations.
/// transactions starting from the channel's funding transaction and going down three levels.
Copy link

@tlulu tlulu Oct 17, 2023

Choose a reason for hiding this comment

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

Just to clarify, do the three levels here mean looking at these txns?

  1. Funding tx
  2. Closing tx
  3. Tx spending the closing tx outputs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The funding transaction will never match. It's the closing transaction, all spends of the closing transaction, and all spends of those which spend the closing transaction.

Copy link

Choose a reason for hiding this comment

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

Makes sense that the funding transaction isn't needed. Why is the third level needed? Isn't the closing transaction and all spends of the closing transaction enough?

Copy link
Contributor Author

@wpaulino wpaulino Oct 18, 2023

Choose a reason for hiding this comment

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

Because HTLCs are resolved in two stages when you broadcast your own commitment transaction. The first spends the HTLC output in the commitment transaction via the timeout or preimage path. The second spends the output in that timeout/preimage transaction after a CSV delay to give the counterparty a chance to claim it instead if the HTLC came from a revoked commitment.

Copy link

Choose a reason for hiding this comment

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

Oh that's right, there could be the revocation tx as well!

So this scenario would be:

  1. Commitment tx (closing tx)
  2. Revocation tx (spends the commitment tx)
  3. Tx spending the revocation tx

We need the third layer because we want to make sure that the output is spent right?

Thanks for the speedy reply btw 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have LN-related outputs to claim within each of those transactions. Any spends after that will be from your wallet.

Copy link

@tlulu tlulu Nov 2, 2023

Choose a reason for hiding this comment

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

Because HTLCs are resolved in two stages when you broadcast your own commitment transaction.

I didn't fully grok the two stage HTLC protocol until now. The way I look at it, I still only see two layers that we need to check. I.e

  1. Commitment Tx
  2. HTLC-timeout Tx (which contains the LDK spendable output)
Screenshot 2023-10-30 at 2 15 57 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the HTLC-timeout/success transaction is from a revoked commitment, then LDK will claim it with a new transaction via the revocation path, yielding another SpendableOutputDescriptor.

Copy link

Choose a reason for hiding this comment

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

Gotcha, that makes sense

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.

#2609 followups
5 participants