Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Replace use of HolderSignedTx with HolderCommitment - #3664

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx
Mar 31, 2025
Merged

Replace use of HolderSignedTx with HolderCommitment#3664
wpaulino merged 2 commits into
lightningdevkit:mainfrom
wpaulino:deprecate-holder-signed-tx

Conversation

@wpaulino

Copy link
Copy Markdown
Contributor

As we move to a custom commitment transactions world, we'll no longer be able to rely on HolderSignedTx and should instead track the actual commitment transaction itself. This commit does so by introducing a new HolderCommitment struct, which we'll use as a replacement to HolderSignedTx to hold all relevant holder commitment data, including the HolderCommitmentTransaction, without data duplication.

Luckily, this is a backwards and forwards compatible change due to the OnchainTxHandler tracking the latest HolderCommitmentTransactions. In the future, we aim to remove them from the OnchainTxHandler entirely and begin storing them at the ChannelMonitor level.

Aside from how the data is represented internally, there shouldn't be any functional changes within this patch.

Depends on #3663.

@ldk-reviews-bot

ldk-reviews-bot commented Mar 12, 2025

Copy link
Copy Markdown

👋 Thanks for assigning @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@wpaulinowpaulino added the weekly goal Someone wants to land this this week label Mar 12, 2025
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
let holder_commitment = HolderCommitment::try_from((
current_holder_commitment_tx, &current_holder_signed_tx,
)).map_err(|_| DecodeError::InvalidValue)?;
if HolderSignedTx::from(&holder_commitment) != current_holder_signed_tx {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's gonna happen here? Are we just gonna keep writing the legacy versions and converting, or should we have some upgrade path?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Was planning to address this in a follow-up PR that removes them from OnchainTxHandler such that we can no longer rely on getting them from there and instead store them as a new TLV in the monitor.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 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.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does seem like the kind of thing that might want an 👋 upgrade test 👋

@codecov

codecovBot commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.71963% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.15%. Comparing base (030a784) to head (5d13fdc).
Report is 28 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/chain/channelmonitor.rs89.57%19 Missing and 13 partials ⚠️
lightning/src/ln/channel.rs88.88%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3664 +/- ##
==========================================
- Coverage 89.25% 89.15% -0.11% 
==========================================
Files 155 155 Lines 119959 121059 +1100 Branches 119959 121059 +1100 ==========================================
+ Hits 107069 107925 +856 - Misses 10276 10478 +202 - Partials 2614 2656 +42 

☔ 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.

@wpaulino

Copy link
Copy Markdown
ContributorAuthor

This does seem like the kind of thing that might want an 👋 upgrade test 👋

Will need to wait for #3584 first

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 2884bad to fdc1706CompareMarch 12, 2025 23:04
@dunxen

Copy link
Copy Markdown
Contributor

Needs rebase.

@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from fdc1706 to 73f82fbCompareMarch 17, 2025 16:53

@tankyleotankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't make it through everything, some initial comments.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Made it through everything. Nothing out of the ordinary pops out aside from what other reviewers have raised.

I'm also unclear how this helps with custom commitment transactions in particular ? Thanks for clarifying here.

Will let @wpaulino confirm, but IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 73f82fb to 24dffdbCompareMarch 17, 2025 23:55
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

@tankyleo

tankyleo commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

IIUC prior to this PR we were only storing parts of the commitment transaction, so anything additional in a custom one would be missing.

Correct. We were already tracking the actual commitment transaction at the OnchainTxHandler, so HolderSignedTx was redundant. The plan is to move the commitment transaction storage from OnchainTxHandler -> ChannelMonitor.

Ok! From my side here's how I've been approaching custom transactions in channel monitor. Many details I haven't worked out yet but big picture:

  • While storing the fully built holder commitment transactions is ok as we only store two, we will likely not store all the previous counterparty commitment transactions (even custom ones), as the storage cost would be too high.
  • For this problem, me and Matt have been going for a roundtrip to some signer-like object to generate the claims.
  • ie "hey signer ! here's a commitment tx that confirmed, what can we claim out of this?"
  • this could work for all the counterparty transactions (revoked and non-revoked), and I've been making it work for holder transactions too.

Experimental API currently looks like this:

/// Returns claims on a counterparty commitment transactionfngenerate_claims_from_counterparty_tx(&self,per_commitment_point:&PublicKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a counterparty's revoked commitment transactionfngenerate_claims_from_revoked_tx(&self,per_commitment_key:&SecretKey,channel_parameters:&ChannelTransactionParameters,tx:&Transaction,per_commitment_claimable_data:&Vec<(HTLCOutputInCommitment,Option<Box<HTLCSource>>)>,height:u32,secp_ctx:&Secp256k1<secp256k1::All>,) -> (Vec<PackageTemplate>,CommitmentTxCounterpartyOutputInfo);/// Returns claims on a holder's commitment transactionfngenerate_claims_from_holder_tx(&self,holder_tx:&HolderSignedTx,conf_height:u32,channel_parameters:&ChannelTransactionParameters,payment_preimages:&HashMap<PaymentHash,(PaymentPreimage,Vec<PaymentClaimDetails>)>,secp_ctx:&Secp256k1<secp256k1::All>,) -> Vec<PackageTemplate>;

What's missing:

  • When we force close, we want to generate claims even though our holder commit tx hasn't confirmed yet.
  • When we learn a preimage, we want to generate claims against already confirmed outputs.
  • Generate claims on htlc transactions.

Let me know if this syncs up with what you were thinking @wpaulino happy to chat here or elsewhere.

This branch here contains this API together with an implementation that passes the test suite:

https://github.com/tankyleo/rust-lightning/tree/check

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from pending discussions. Please re-request a review once those are resolved.

@wpaulino
wpaulino requested a review from jkczyzMarch 18, 2025 17:01
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

@tankyleo your proposal seems fine so far. The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway. The rest is mostly unrelated to this change, so happy to chat about this work offline.

@tankyleo

Copy link
Copy Markdown
Contributor

The only change as a result of this PR would be to the function argument in generate_claims_from_holder_tx, we would've probably wanted to provide the HolderCommitmentTransaction there to begin with anyway.

Yes agreed

The rest is mostly unrelated to this change, so happy to chat about this work offline.

Sounds good

jkczyz
jkczyz previously approved these changes Mar 18, 2025
@TheBlueMatt
TheBlueMatt removed their request for review March 18, 2025 19:13
Ok(LatestHolderCommitmentTXInfo {
commitment_tx: holder_commitment_tx,
htlc_outputs: htlcs_and_sigs,
htlc_outputs: dust_htlcs,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we rename this now that its something different?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It might still have the old meaning when we read. Would you rather change it now anyway or wait until we know for sure we'll only ever find dust_htlcs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe mostly_dust_htlcs? :). I mean we can certainly do it later, just seems easy for a bug to slip in because of a bad name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'd rather defer it. I don't think a bug could happen where non-dust HTLCs are included because we still have code to support that, and the current name already assumed dust HTLCs must be included.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Currently, non-dust HTLCs are duplicated across the commitment
transaction itself, and the full set of HTLCs (dust & non-dust) along
with their `HTLCSource` considered in the commitment transaction. As of
v0.0.15, we've had support for providing non-dust HTLC sources
separately such that we no longer track duplicate non-dust HTLC data,
but only enabled it under testing environments. This commit enables it
such that it always happens.
Note that we still need to support reading
`ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates that
did not separate the non-dust HTLC sources in case they were written in
an older version and they've yet to be processed.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 41d9463 to 7f626c8CompareMarch 25, 2025 17:03
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase due to a conflict with #3606 and implemented write_as_legacy.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from 7f626c8 to a891a04CompareMarch 25, 2025 22:31
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from a891a04 to e8ec314CompareMarch 26, 2025 22:58
@TheBlueMatt
TheBlueMatt removed their request for review March 27, 2025 13:27
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from e8ec314 to 80ac853CompareMarch 27, 2025 15:56
TheBlueMatt
TheBlueMatt previously approved these changes Mar 27, 2025
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch 2 times, most recently from 92df40e to b8007c9CompareMarch 28, 2025 17:29
TheBlueMatt
TheBlueMatt previously approved these changes Mar 28, 2025

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be nice to reduce the clones in a few places still, but we can also do it in a followup.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
As we move to a custom commitment transactions world, we'll no longer be
able to rely on `HolderSignedTx` and should instead track the actual
commitment transaction itself. This commit does so by introducing a new
`HolderCommitment` struct, which we'll use as a replacement to
`HolderSignedTx` to hold all relevant holder commitment data, including
the `HolderCommitmentTransaction`, without data duplication.
Luckily, this is a backwards and forwards compatible change due to the
`OnchainTxHandler` tracking the latest `HolderCommitmentTransaction`s.
In the future, we aim to remove them from the `OnchainTxHandler`
entirely and begin storing them at the `ChannelMonitor` level.
Aside from how the data is represented internally, there shouldn't be
any functional changes within this patch.
@wpaulino
wpaulinoforce-pushed the deprecate-holder-signed-tx branch from d279b82 to 5d13fdcCompareMarch 28, 2025 21:41
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 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.

@wpaulino
wpaulino merged commit 7af3c8f into lightningdevkit:mainMar 31, 2025
@wpaulino
wpaulino deleted the deprecate-holder-signed-tx branch March 31, 2025 22:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@wpaulino@ldk-reviews-bot@TheBlueMatt@dunxen@tankyleo@jkczyz