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

Remove data dependency on OnchainTxHandler from onchain claims #3690

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

wpaulino
Copy link
Contributor

The ChannelMonitor and OnchainTxHandler have historically been tied together, often tracking some of the same state twice. As we introduce support for splices in the ChannelMonitor, we'd like to avoid leaking some of those details to the OnchainTxHandler. Ultimately, the OnchainTxHandler should stand on its own and support claiming funds from multiple ChannelMonitors, allowing us to save on fees by batching aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are attempting to claim an output from a specific FundingScope, while also having an additional pending FundingScope for a splice. If the pending splice confirms over the output claim, we need to cancel the claim and re-offer it with the set of relevant parameters in the new FundingScope.

This PR features a series of commits decoupling the data dependency on the OnchainTxHandler from onchain claims, opting to store any data required for the claim within its set of TLVs.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 29, 2025

👋 I see @TheBlueMatt was un-assigned.
If you'd like another reviewer assignemnt, please click here.

Copy link

codecov bot commented Mar 29, 2025

Codecov Report

Attention: Patch coverage is 97.21578% with 12 lines in your changes missing coverage. Please review.

Project coverage is 89.02%. Comparing base (c4d23bc) to head (fff884f).

Files with missing lines Patch % Lines
lightning/src/chain/package.rs 97.63% 2 Missing and 3 partials ⚠️
lightning/src/chain/onchaintx.rs 95.74% 3 Missing and 1 partial ⚠️
lightning/src/chain/channelmonitor.rs 97.61% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3690      +/-   ##
==========================================
+ Coverage   89.00%   89.02%   +0.01%     
==========================================
  Files         155      155              
  Lines      122019   122153     +134     
  Branches   122019   122153     +134     
==========================================
+ Hits       108603   108742     +139     
+ Misses      10745    10732      -13     
- Partials     2671     2679       +8     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @joostjager! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@wpaulino wpaulino requested review from TheBlueMatt and removed request for joostjager March 31, 2025 03:35
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Some initial comments, need to finish going through it all later. Also CI is sad.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Oops, I had more time than I thought. In any case I'm pretty confused by the direciton here. Should we hop on a call to discuss it?

@wpaulino wpaulino force-pushed the onchain-tx-handler-serialization-revamp branch from 07535a8 to 97d6278 Compare April 1, 2025 23:44
@wpaulino wpaulino requested a review from TheBlueMatt April 1, 2025 23:45
@@ -1034,8 +1034,8 @@ impl Writeable for ChannelTransactionParameters {
}
}

impl ReadableArgs<u64> for ChannelTransactionParameters {
fn read<R: io::Read>(reader: &mut R, read_args: u64) -> Result<Self, DecodeError> {
impl ReadableArgs<Option<u64>> for ChannelTransactionParameters {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the same changes are also in #3651 fwiw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah will drop the commit if that lands first

@wpaulino wpaulino force-pushed the onchain-tx-handler-serialization-revamp branch from 97d6278 to 6f8f853 Compare April 2, 2025 20:59
@wpaulino wpaulino requested review from TheBlueMatt and jkczyz April 2, 2025 20:59
@TheBlueMatt
Copy link
Collaborator

Looks like this needs rebase already :(

TheBlueMatt
TheBlueMatt previously approved these changes Apr 3, 2025
@wpaulino wpaulino force-pushed the onchain-tx-handler-serialization-revamp branch 2 times, most recently from 63dd53b to 57e774c Compare April 4, 2025 17:52
@wpaulino
Copy link
Contributor Author

wpaulino commented Apr 4, 2025

Addressed all pending feedback and rebased due to a minor conflict.

@wpaulino wpaulino requested a review from TheBlueMatt April 4, 2025 17:54
@TheBlueMatt TheBlueMatt removed their request for review April 4, 2025 17:59
@TheBlueMatt
Copy link
Collaborator

I'll wait for another reviewer to approve this to look again, I think it was fine.

wpaulino added 6 commits April 4, 2025 11:37
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

This commit removes the internal usage of
`OnchainTxHandler::destination_script` and deprecates it, opting to
instead provide it as a function argument wherever needed.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `HolderCommitmentTransaction` for the specific
`FundingScope` the `HolderFundingOutput` claim originated from. This
allows us to remove the dependency on `OnchainTxHandler` when obtaining
the current `HolderCommitmentTransaction` and ensures any alternative
commitment transaction state due to splicing does not leak into the
`OnchainTxHandler`. As a result, we can now include all the information
required to emit a `BumpTransactionEvent::ChannelClose` within its
intermediate representation `ClaimEvent::BumpCommitment`, as opposed to
relying on the `ChannelMonitor` to provide it.

Along the way, this commit also fixes a bug where
`BumpTransactionEvent::ChannelClose` could be emitted with an unsigned
commitment transaction, resulting in the child transaction not being
broadcastable due to a non-existent ancestor. This isn't a huge deal as
we have retry logic for such claims; once the signer returns a valid
signature, the event is re-emitted properly.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `ChannelTransactionParameters` for the specific
`FundingScope` the `HolderFundingOutput` claim originated from. This
allows us to remove the dependency on `OnchainTxHandler` when obtaining
the current `ChannelTransactionParameters` and ensures any alternative
state due to splicing does not leak into the `OnchainTxHandler`.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

This commit tracks the `HTLCDescriptor` for the specific `FundingScope`
the `HolderHTLCOutput` claim originated from. Previously, when claiming
`HolderHTLCOutput`s, the `OnchainTxHandler` had to check which holder
commitment the HTLC belonged to in order to produce an `HTLCDescriptor`
for signing. We still maintain the legacy logic for existing claims
which have not had an `HTLCDescriptor` written yet.

Along the way, we refactor the claim process for such outputs to
decouple them from the `OnchainTxHandler`. As a result, the
`OnchainTxHandler` is only used to obtain references to the signer and
secp256k1 context.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `ChannelTransactionParameters` for the specific
`FundingScope` the `CounterpartyReceivedHTLCOutput` claim originated
from. This allows us to remove the dependency on `OnchainTxHandler` when
obtaining the current `ChannelTransactionParameters` and ensures any
alternative state due to splicing does not leak into the
`OnchainTxHandler`.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `ChannelTransactionParameters` for the specific
`FundingScope` the `CounterpartyOfferedHTLCOutput` claim originated
from. This allows us to remove the dependency on `OnchainTxHandler` when
obtaining the current `ChannelTransactionParameters` and ensures any
alternative state due to splicing does not leak into the
`OnchainTxHandler`.
wpaulino added 3 commits April 4, 2025 11:37
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `ChannelTransactionParameters` for the specific
`FundingScope` the `RevokedHTLCOutput` claim originated from. This
allows us to remove the dependency on `OnchainTxHandler` when obtaining
the current `ChannelTransactionParameters` and ensures any alternative
state due to splicing does not leak into the `OnchainTxHandler`.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

Once splices are supported, we may run into cases where we are
attempting to claim an output from a specific `FundingScope`, while also
having an additional pending `FundingScope` for a splice. If the pending
splice confirms over the output claim, we need to cancel the claim and
re-offer it with the set of relevant parameters in the new
`FundingScope`.

This commit tracks the `ChannelTransactionParameters` for the specific
`FundingScope` the `RevokedOutput` claim originated from. This allows us
to remove the dependency on `OnchainTxHandler` when obtaining the
current `ChannelTransactionParameters` and ensures any alternative state
due to splicing does not leak into the `OnchainTxHandler`.
The `ChannelMonitor` and `OnchainTxHandler` have historically been tied
together, often tracking some of the same state twice. As we introduce
support for splices in the `ChannelMonitor`, we'd like to avoid leaking
some of those details to the `OnchainTxHandler`. Ultimately, the
`OnchainTxHandler` should stand on its own and support claiming funds
from multiple `ChannelMonitor`s, allowing us to save on fees by batching
aggregatable claims across multiple in-flight closing channels.

This commit tracks the `ChannelTransactionParameters` for the current
`FundingScope` of a `ChannelMonitor` and deprecates the one found in
`OnchainTxHandler`.
@wpaulino wpaulino force-pushed the onchain-tx-handler-serialization-revamp branch from 57e774c to fff884f Compare April 4, 2025 18:37
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

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.

3 participants