Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support async signing for V2 channel establishment #3411

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

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Nov 15, 2024

When handling a tx_complete message, allow signers to return an error indicating that the signer has not yet complete. This will leave the ChannelPhase in an unfunded variant until the signer becomes unblocked. The user calls ChannelManager::signer_unblocked to indicate that signing is complete, which will attempt to finish handling the tx_complete message again.

Based on #3137.
Fixes #3404.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Seems good to me, but I'm not 100% familiar with the async signing stuff. Seems mostly straightforward though.

@@ -8862,6 +8891,7 @@ pub(super) struct InboundV2Channel<SP: Deref> where SP::Target: SignerProvider {
pub dual_funding_context: DualFundingChannelContext,
/// The current interactive transaction construction session under negotiation.
interactive_tx_constructor: Option<InteractiveTxConstructor>,
signing_session: Option<InteractiveTxSigningSession>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, honestly I'm not sure how to avoid the Option without introducing a new state variant, which is something we'd prefer to avoid, as discussed.

Comment on lines +9603 to +9597
// Finish any tx_complete handling waiting on async signing.
//
// TODO: Move this into the earlier channel iteration to avoid duplication and the Vec
// allocation once ChannelPhase is refactored into Channel. This can't be avoided with the
// current data model because tx_complete handling requires removing the entry from the
// channel_by_id map and re-inserting it, which can't be done while iterating over the map.
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done with the ChannelPhase into Channel refactor, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that's what the comment is referring to.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh i missed a whole line when reading. Stated the exact same thing 🤦‍♂️

To support async signing, the InteractiveTxSigningSession returned when
handling tx_complete needs to be saved in order to retry the
funding_tx_constructed method when the signer is unblocked. This
unfortunately means an Option as needed since the unfunded V2 channel
phase variant is left unfunded until the signer completes.
When handling a tx_complete message, allow signers to return an error
indicating that the signer has not yet complete. This will leave the
ChannelPhase in an unfunded variant until the signer becomes unblocked.
These methods always return Ok, so there is no need to use a Result.
Expand ChannelManager::signer_unblocked to finish handling tx_complete
messages. This completes support for async signing in V2 channel
establishment.
@jkczyz jkczyz marked this pull request as ready for review November 20, 2024 18:10
@jkczyz
Copy link
Contributor Author

jkczyz commented Nov 21, 2024

Fixed a couple rustfmt issues in dual_funding_tests.rs. Also, removed a ton of unnecessary drains from channelmanager.rs for good measure since I was looking at related code and noticed a Vec wasn't being used, which I removed in another commit, too.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 66.91176% with 45 lines in your changes missing coverage. Please review.

Project coverage is 89.23%. Comparing base (0c31021) to head (6db89d7).

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 64.61% 16 Missing and 7 partials ⚠️
lightning/src/ln/channel.rs 62.50% 20 Missing and 1 partial ⚠️
lightning/src/ln/interactivetxs.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3411      +/-   ##
==========================================
+ Coverage   89.22%   89.23%   +0.01%     
==========================================
  Files         130      130              
  Lines      106965   106958       -7     
  Branches   106965   106958       -7     
==========================================
+ Hits        95438    95446       +8     
+ Misses       8734     8725       -9     
+ Partials     2793     2787       -6     

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


🚨 Try these New Features:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support async signing for V2 (dual_funded) channels
2 participants