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 force-pushed the 2024-11-async-signing-v2 branch from c3f5063 to 8dfa6d2 Compare November 20, 2024 18:10
@jkczyz jkczyz marked this pull request as ready for review November 20, 2024 18:10
The errs Vec in ChannelManager::claim_payment_internal hasn't been
populated since commit fea6393. Drop it
along with the code that consumed it.
@jkczyz jkczyz force-pushed the 2024-11-async-signing-v2 branch from 8dfa6d2 to 6db89d7 Compare November 21, 2024 20:25
@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:

"Failed to get signatures for new commitment_signed".to_owned(),
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
)))
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasoning for discarding error info here? The signer may return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signer returning an error indicates async signing. At least that's how the other async signing operates. Looks like the EcdsaChannelSigner::sign_counterparty_commitment docs weren't updated like ChannelSigner::get_per_commitment_point were. Let me do that in this PR.

@TheBlueMatt Wonder if we should change the interface to use an Option instead of a Resultonce async_signing configuration parameter is dropped?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably clean up the API, yea, but lets not conflict with #3109 if at all possible.

ChannelPhase::UnfundedOutboundV2(chan) => {
chan.funding_tx_constructed(&mut signing_session, &self.logger)
*chan.interactive_tx_signing_session_mut() = Some(signing_session);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a setter method would be more idiomatic in this case.


macro_rules! finish_tx_complete {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this be more straightforward if we do the state transition immediately and only send the message later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... possibly. Maybe we should wait on #3423 before moving forward with this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with that, might also reduce the risk of #3109 being conflicted.

None => {
let per_peer_state = self.per_peer_state.read().unwrap();
let mut channels = Vec::with_capacity(per_peer_state.len());
for (counterparty_node_id, peer_state_mutex) in per_peer_state.iter() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand why we need to do a two-pass here, we don't drop the locks during the loop in the second pass so we should be able to just do a straight iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

finish_tx_complete! removes and re-inserts the entry, which you can't do while iterating. See TODO above that loop.

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
4 participants