Skip to content

Implement accepting dual-funded channels without contributing - #3137

Merged
jkczyz merged 15 commits into
lightningdevkit:mainfrom
dunxen:2024-06-non-public-API-v2-channels
Nov 20, 2024
Merged

Implement accepting dual-funded channels without contributing#3137
jkczyz merged 15 commits into
lightningdevkit:mainfrom
dunxen:2024-06-non-public-API-v2-channels

Conversation

@dunxen

@dunxendunxen commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

We split this out from #2302 for easier review and to address the common non-public API parts of the V2 channel establishment implementation.

This will allow the holder to be an acceptor, but not initiator of V2 channels. We also don't expose an API for contributing to an inbound channel.

The functionality to initiate V2 channels and fund inbound channels forms part of #2302.

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch 3 times, most recently from b981cd7 to 0caf60eCompareJune 20, 2024 16:14
@dunxen
dunxen marked this pull request as ready for review June 20, 2024 16:27
@dunxendunxen mentioned this pull request Jun 20, 2024
4 tasks
@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from 0caf60e to 44821afCompareJune 24, 2024 16:55
@codecov-commenter

codecov-commenter commented Jun 24, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 60.06849% with 583 lines in your changes missing coverage. Please review.

Project coverage is 89.29%. Comparing base (4322b19) to head (8b0f4b5).

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs47.67%227 Missing and 21 partials ⚠️
lightning/src/ln/channel.rs59.73%162 Missing and 18 partials ⚠️
lightning/src/ln/interactivetxs.rs49.16%150 Missing and 3 partials ⚠️
lightning/src/ln/dual_funding_tests.rs99.02%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3137 +/- ##
==========================================
- Coverage 89.69% 89.29% -0.41% 
==========================================
Files 129 130 +1 Lines 105437 106910 +1473 Branches 105437 106910 +1473 ==========================================
+ Hits 94573 95464 +891 - Misses 8117 8665 +548 - Partials 2747 2781 +34 

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

@optout21optout21 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.

Looks great, mostly localized code improvements suggested.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/mod.rs Outdated
@optout21

Copy link
Copy Markdown
Contributor

As I see, the dual_funding cfg flag has been removed (not a problem)

@optout21

Copy link
Copy Markdown
Contributor

Looks to me that #2989 is in fact included in this PR (good!)

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch 4 times, most recently from 0db700b to 7dceeddCompareJuly 3, 2024 09:44
@dunxen
dunxen requested review from TheBlueMatt and optout21 and removed request for optout21July 3, 2024 09:51
optout21
optout21 previously approved these changes Jul 3, 2024
Comment threadlightning/src/events/mod.rs Outdated
@dunxen
dunxen requested a review from jkczyzJuly 4, 2024 15:02

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

Some initial comments, sorry this took so long to get back to.

Comment threadlightning/src/events/mod.rs
Comment threadlightning/src/events/mod.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
if chan.interactive_tx_signing_session.is_some() {
let monitor = try_chan_phase_entry!(self,
chan.commitment_signed_initial_v2(&msg, best_block, &self.signer_provider, &&logger), chan_phase_entry);
if let Ok(persist_status) = self.chain_monitor.watch_channel(chan.context.get_funding_txo().unwrap(), monitor) {

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.

If the persist status is pending we need to handle the later stuff in monitor_updating_restored. Really the whole contents of the block here should be in monitor_updating_restored.

Comment threadlightning/src/ln/channel.rs Outdated

@dunxendunxen left a comment

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.

Thanks @TheBlueMatt, for review and some good points raised. I'll address these ASAP ❤️

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from 7dceedd to 64c35f4CompareJuly 10, 2024 16:05
@dunxen

Copy link
Copy Markdown
ContributorAuthor

Still working on remaining initial feedback.

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from 64c35f4 to a46da5aCompareJuly 11, 2024 14:55
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

No rush, let me know when you want another pass.

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch 2 times, most recently from 0613f64 to 93896c4CompareJuly 16, 2024 10:36
Here we add the `interactive_tx_constructor` field to the `Channel`,
`OutboundV2Channel`, and `InboundV2Channel` structs.
For now this is unneeded as we do not provide any inputs as channel
acceptor and we do not allow creating outbound channels yet. It will
be re-added when that functionality is introduced.
1. InteractiveTxConstructorArgs is introduced to act as a single, more
readable input to InteractiveTxConstructor::new().
2. Various documentation updates.
@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from 90a4695 to cd26443CompareNovember 18, 2024 13:20

@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. @TheBlueMatt Could you take a look?

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from cd26443 to 984862eCompareNovember 18, 2024 18:17

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

Made it most of the way through. I think basically all the comments here can be addressed in a followup, so will get through the rest hopefully soon so we can land it. In the mean time, feel free to squash fixups and fix any of the smaller comments here you want in the process.

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
HandleTxCompleteResult(Ok(tx_complete))
}

fn funding_tx_constructed<L: Deref>(

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 tx_complete just call this directly when required rather than having channelmanager.rs call tx_complete then call this based only on the return value of tx_complete? Would reduce the logic in channelmanager.rs.

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.

Just note that we'll still want this as a function since it's called by signer_unblocked for async signing.

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.

See #3411

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.

Fair, still good to consolidate logic in channel.rs where possible.

Comment threadlightning/src/ln/channel.rs
(51, is_manual_broadcast, option), // Added in 0.0.124
(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
(55, self.context.next_funding_txid, option) // Added in 0.1.0

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.

Yea, would be nice to remove this before we release and instead figure out the next_funding_txid field based on the funding transaction in the Channel and the current channel state.

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.

Removed in #3417.

@dunxendunxenNov 22, 2024

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.

The follow-up PR #3423 should populate it on read.


blocked_monitor_updates: blocked_monitor_updates.unwrap(),
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
// If we've sent `commtiment_signed` for an interactively constructed transaction

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.

Mmm, so really this is the "we were done with negotiation" flag in the channel_reestablish message. It does seem like we're missing some startup handling for this - basically we need to check on startup if the ChannelMonitor was persisted (implying we've sent our initial commitment_signed and thus we must not restart negotiation), but (a) it doesn't matter for inbound not-locally-funded channels and (b) maybe its fine just because the Channel will be dropped if its pre-ChannelMonitor (need a test/to check this, but I don't think so, since we mark the channel as funded in internal_tx_complete, at which point we'll persist the Channel even though it doesn't have a monitor yet).

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.

Yeah this was a mistake to mark it funded at that point. Only after receiving an initial commitment_signed and getting a monitor do we need to persist. I'll fix the states up in the follow-up.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch 3 times, most recently from 0b75814 to 8b7505dCompareNovember 19, 2024 13:14

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

Few more comments, got through the bulk of it. Basically the only issue(s) I think need fixing are the persistence of Channels before we have a ChannelMonitor which is gonna cause issues on restart. It can be fixed in a followup, though. Still need to review the tests but I can do that after this lands.

"Dual-funded channels not supported".to_owned(),
msg.channel_id.clone())), counterparty_node_id);
// Note that we never need to persist the updated ChannelManager for an inbound
// tx_complete message - interactive transaction construction does not need to

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.

But don't we send signatures in response to tx_complete (if we already received the peer's tx_complete and we're supposed to send first)? More generally, once the tx_completes have been exchanged, don't we at that point want to be able to resume the channel after restart (which implies a persistence, and also some additional handling cause we will currently FC on channel on startup if there's no ChannelMonitor which we won't have yet.

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.

After consecutive tx_complete exchange, we will only send then initial commitment_signed.

We will only send a tx_signatures once we've received an initial commitment_signed if we are up first to send tx_signatures. Once we've received a commitment_signed we persist.

I've fixed this in the follow-up I'll have up soon. No PR yet.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs
Comment threadlightning/src/ln/interactivetxs.rs
Comment threadpending_changelog/3137-accept-dual-funding-without-contributing.txt Outdated
@dunxen

Copy link
Copy Markdown
ContributorAuthor

Few more comments, got through the bulk of it. Basically the only issue(s) I think need fixing are the persistence of Channels before we have a ChannelMonitor which is gonna cause issues on restart. It can be fixed in a followup, though. Still need to review the tests but I can do that after this lands.

Thanks! Going to address a few more things you brought up throughout tonight and tomorrow morning for me and then I'll open an issue with remaining follow-ups. So unless something major prevents this from landing, we could land it tomorrow?

@dunxen
dunxenforce-pushed the 2024-06-non-public-API-v2-channels branch from 8b7505d to dd190aeCompareNovember 20, 2024 12:28
@dunxen

Copy link
Copy Markdown
ContributorAuthor

I've pushed up a few fixes. There are some nits that could be fixed here, but I'll include them in a followup to start unblocking other PRs.

@jkczyz, if CI and you are happy, we can go ahead and get this in when you're ready. Then I'll create the follow-up issue and tag it to make sure it's a blocker for next release.

@jkczyz

Copy link
Copy Markdown
Contributor

I've pushed up a few fixes. There are some nits that could be fixed here, but I'll include them in a followup to start unblocking other PRs.

@jkczyz, if CI and you are happy, we can go ahead and get this in when you're ready. Then I'll create the follow-up issue and tag it to make sure it's a blocker for next release.

Sure, let's land this now and address the rest in follow-ups. Incremental mutants has been running for five hours, but no need to wait on it.

@jkczyz
jkczyz merged commit 0c31021 into lightningdevkit:mainNov 20, 2024
@jkczyzjkczyz mentioned this pull request Nov 25, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@dunxen@codecov-commenter@optout21@TheBlueMatt@jkczyz