Skip to content

Allow sending closing tx signatures asynchronously #3153

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

Merged

Conversation

alecchendev
Copy link
Contributor

Another async signing PR, this time for sign_closing_transaction!

If you've reviewed the other PRs, you know the drill: try to go about business as usual, if we fail to get the signature, do everything except for send the message, and mark our signer_pending_closing flag. The user then needs to call signer_unblocked, and we'll try again to get the signature, then create + send the message. In this case we not only need to send the message, but also 1. broadcast the fully signed closing tx, 2. broadcast a channel update, and 3. remove the channel from our map.

I added some additional state to track everything we need to do everything we need (rebuild the tx, fully sign, send our closing_signed msg, etc.) upon the signer being unblocked. This state is not persisted.

@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 86.36364% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.12%. Comparing base (33e6995) to head (6e2071a).
Report is 108 commits behind head on main.

Files Patch % Lines
lightning/src/ln/channel.rs 92.98% 3 Missing and 1 partial ⚠️
lightning/src/util/test_channel_signer.rs 0.00% 1 Missing and 3 partials ⚠️
lightning/src/ln/channelmanager.rs 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3153      +/-   ##
==========================================
+ Coverage   89.78%   91.12%   +1.33%     
==========================================
  Files         123      126       +3     
  Lines      102330   114900   +12570     
  Branches   102330   114900   +12570     
==========================================
+ Hits        91876   104701   +12825     
+ Misses       7763     7708      -55     
+ Partials     2691     2491     -200     

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

@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch from a46812a to a37c656 Compare July 3, 2024 20:23
@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch from a37c656 to ca1a389 Compare July 11, 2024 18:11
@alecchendev
Copy link
Contributor Author

rebased because of conflicts

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

A few nits asking for more tests, but LGTM I think. @valentinewallace ?

@valentinewallace valentinewallace self-requested a review August 6, 2024 21:26
@valentinewallace
Copy link
Contributor

Taking a look!

@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch 2 times, most recently from 934ec75 to dcf4ad8 Compare August 14, 2024 21:53
@alecchendev
Copy link
Contributor Author

rebased because of conflicts as well

@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch from dcf4ad8 to 44e95c2 Compare August 15, 2024 16:17
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

I'm good with a squash then landing this!

@TheBlueMatt
Copy link
Collaborator

Feel free to squash, lets get this over the line!

@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch from 44e95c2 to b0f7efa Compare August 19, 2024 18:36
@alecchendev
Copy link
Contributor Author

addressed latest nits and squashed

{
if matches!(self.context.channel_state, ChannelState::ShutdownComplete) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh, I think this is gonna cause issues - we currently assume that ShutdownComplete means a channel can't exist after its set and assert it a few other places. Currently, what if a user calls force_shutdown on a channel while its pending, I think we'll panic, but also in some message handlers we assert that the state is ChannelReady and could similarly panic after a peer sends us the wrong message. Instead, I think we should leave the channel as ChannelReady and just check the state in the shutdown messages (other things, IIRC, already check if the state has shutdown_sent).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, made sure not the set ShutdownComplete in the pending signatures case, and added a helper to check whether we're basically shutdown but waiting on the signature, which is used in the check here + debug asserts, lmk if that works

Copy link
Collaborator

@TheBlueMatt TheBlueMatt Aug 23, 2024

Choose a reason for hiding this comment

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

Thanks, feel free to squash.

@TheBlueMatt
Copy link
Collaborator

Sorry for the delay, release process is always fun. I think this LGTM.

@alecchendev alecchendev force-pushed the 2024-07-async-closing-signed branch from c3a2d8b to 6e2071a Compare August 23, 2024 18:02
@alecchendev
Copy link
Contributor Author

squashed

},
_ => panic!("Unexpected event: {:?}", events[0]),
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a followup, can we simulate a reconnect here? We should make sure a disconnect/reconnect here doesn't cause failure to finish the closing signed dance.

@TheBlueMatt TheBlueMatt merged commit ff0874a into lightningdevkit:main Aug 26, 2024
17 of 19 checks passed
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.

4 participants