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

Introduce interactive signing state flags for funded states. #3637

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

Conversation

dunxen
Copy link
Contributor

@dunxen dunxen commented Mar 3, 2025

This PR includes some deferred follow-ups extracted from #3423 and introduces new state flags to track interactive signing along with persistence of the minimum information needed from a signing session to reconstruct it.

A top-level state flag was avoided so that this work is compatible with splicing as well as V2 channel establishment (dual-funding).

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 3, 2025

👋 Thanks for assigning @wpaulino 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.

@dunxen dunxen marked this pull request as draft March 3, 2025 18:50
@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch 2 times, most recently from 4c6b6ab to c1f430a Compare March 4, 2025 09:02
@dunxen dunxen changed the title DRAFT: Introduce interactive signing state flags for funded states. Introduce interactive signing state flags for funded states. Mar 4, 2025
@dunxen dunxen marked this pull request as ready for review March 4, 2025 09:03
@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from c1f430a to e89ba58 Compare March 4, 2025 11:09
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.

Did you want to include test coverage for restarts here?

@dunxen
Copy link
Contributor Author

dunxen commented Mar 4, 2025

Did you want to include test coverage for restarts here?

Not yet. Tracked in #3636. Will need to be able to contribute inputs first to test a useful order of message exchange + restart.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from e89ba58 to 3b2ac55 Compare March 5, 2025 10:05
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 56.81818% with 76 lines in your changes missing coverage. Please review.

Project coverage is 88.99%. Comparing base (c4d23bc) to head (aaaeb22).

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 56.09% 50 Missing and 4 partials ⚠️
lightning/src/ln/channelmanager.rs 45.45% 8 Missing and 4 partials ⚠️
lightning/src/ln/interactivetxs.rs 46.66% 8 Missing ⚠️
lightning/src/ln/dual_funding_tests.rs 87.50% 1 Missing ⚠️
lightning/src/util/ser.rs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3637      +/-   ##
==========================================
- Coverage   89.04%   88.99%   -0.05%     
==========================================
  Files         155      155              
  Lines      122019   122116      +97     
  Branches   122019   122116      +97     
==========================================
+ Hits       108652   108683      +31     
- Misses      10701    10764      +63     
- Partials     2666     2669       +3     

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

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 3b2ac55 to 5110ecc Compare March 5, 2025 14:20
@wpaulino
Copy link
Contributor

wpaulino commented Mar 5, 2025

@dunxen re-request when this is ready for review again, feel free to squash as well

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 5110ecc to 1d96044 Compare March 6, 2025 12:43
@dunxen dunxen requested review from TheBlueMatt and wpaulino March 6, 2025 12:44
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @TheBlueMatt @jkczyz @wpaulino! 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.

@dunxen dunxen added weekly goal Someone wants to land this this week Dual-funding labels Mar 6, 2025
@@ -6924,11 +6933,72 @@ impl<SP: Deref> FundedChannel<SP> where
log_debug!(logger, "Reconnected channel {} with no loss", &self.context.channel_id());
}

// if next_funding_txid is set:
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, would be nice to get some test coverage in now for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be tricky at the moment, but makes sense to try do that now 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still tricky, but working on this now currently. I'll let you know if we'll have to defer this to a PR after "create outbound dual-funded channel" is complete.

@TheBlueMatt TheBlueMatt removed their request for review March 6, 2025 23:01
@TheBlueMatt
Copy link
Collaborator

Taking myself off since @wpaulino and @jkczyz are on this one. Aside from my first comment I don't have any more high-level feedback.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 1d96044 to 55e5f6f Compare March 11, 2025 11:42
@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 5291edc to c99182e Compare April 3, 2025 11:10
@dunxen dunxen requested review from jkczyz and wpaulino April 3, 2025 11:20
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz @wpaulino! 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.

1 similar comment
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz @wpaulino! 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.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from c99182e to aaaeb22 Compare April 7, 2025 08:09
@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @jkczyz @wpaulino! 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.

1 similar comment
@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @jkczyz @wpaulino! 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.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from aaaeb22 to 206faf0 Compare April 7, 2025 11:27
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Feel free to squash

update_fail_malformed_htlcs: vec![],
update_fee: None,
})
self.get_last_commitment_update_for_send(logger).ok()
Copy link
Contributor

@wpaulino wpaulino Apr 8, 2025

Choose a reason for hiding this comment

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

Maybe we should drop this commit for now, and revisit splicing support as a follow-up cc @jkczyz. maybe_get_next_funding_txid will have to look at the pending FundingScopes for splices/RBF, and get_last_commitment_update_for_send now returns a batch of commitment_signeds when this should just send the one for the FundingScope in question.

// if it also sets `next_funding_txid` in its own `channel_reestablish`, but the values don't match:
if let Some(our_next_funding_txid) = self.maybe_get_next_funding_txid().filter(|txid| txid != &next_funding_txid) {
// MUST send an `error` and fail the channel.
return Err(ChannelError::Close((format!(
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 actual requirement? We seem to have two conflicting ones: here we fail if there's a mismatch, but below we send TxAbort instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in the current splicing PR. This one is fail and below is tx_abort:

    - if it also sets `next_funding_txid` in its own `channel_reestablish`, but the
      values don't match:
      - MUST send an `error` and fail the channel.
    - otherwise:
      - MUST send `tx_abort` to let the sending node know that they can forget
        this funding transaction.

https://github.com/lightning/bolts/blob/4e82adcd848466b36a6d8a717b195eabe24de216/02-peer-protocol.md?plain=1#L3338

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 206faf0 to d9a8527 Compare April 8, 2025 11:38
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

Looks like there's some breakages in the full_stack fuzz test.

@dunxen
Copy link
Contributor Author

dunxen commented Apr 9, 2025

Looks like there's some breakages in the full_stack fuzz test.

Thanks, will address those. Honestly haven't paid much attention as fuzz had been broken for a while on main I believe.

dunxen added 2 commits April 9, 2025 11:14
Instead of having an explicit `ChannelContext::next_funding_txid` to set
and read, we can get this value on the fly when it is appropriate to do
so.
This follows the the specification closely in branching without being
too verbose, so that it should be easy to follow the logic.

See: https://github.com/lightning/bolts/blob/aa5207a/02-peer-protocol.md?plain=1#L2520-L2531
@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from d9a8527 to aec4e43 Compare April 9, 2025 13:31
@dunxen dunxen requested review from jkczyz and wpaulino April 9, 2025 13:33
@jkczyz
Copy link
Contributor

jkczyz commented Apr 9, 2025

Hmm... when possible please avoid rebasing unless necessary. Otherwise, it makes it difficult to view new changes related to the PR. If needed, doing two separate pushes would be ideal.

@jkczyz
Copy link
Contributor

jkczyz commented Apr 9, 2025

Thanks, will address those. Honestly haven't paid much attention as fuzz had been broken for a while on main I believe.

Locally, it still should work. CI has just been timing out (unfortunately) but will catch actual failures, AFAICT.

@dunxen
Copy link
Contributor Author

dunxen commented Apr 9, 2025

Locally, it still should work. CI has just been timing out (unfortunately) but will catch actual failures, AFAICT.

Oh yeah I see this was just related to the new bool in config.

@dunxen
Copy link
Contributor Author

dunxen commented Apr 9, 2025

Hmm... when possible please avoid rebasing unless necessary.

Sorry, bad habit I do sometimes. I'll keep it in mind again.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from aec4e43 to 4f6192f Compare April 9, 2025 15:02
@@ -5809,7 +5848,6 @@ impl<SP: Deref> FundedChannel<SP> where
log_info!(logger, "Received initial commitment_signed from peer for channel {}", &self.context.channel_id());

let need_channel_ready = self.check_get_channel_ready(0, logger).is_some();
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
self.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to check for channel ready here because it should be impossible to send splice_locked if tx_signatures has not been exchanged. It does mean we'll have to check it once we receive tx_signatures though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove the check here.

We don't return a channel monitor update in tx_signatures so it doesn't make sense to pause. We'd check on next block at least. Note we do not support 0conf for dual-funded channels yet.

where L::Target: Logger
{
if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_)) {
if !matches!(self.context.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. This should probably ignore any duplicate tx_signatures messages so we don't close the channel if they resend as part of reestablish. I think they may also resend it as part of reestablish even when we're no longer in FundingNegotiated.

dunxen added 3 commits April 11, 2025 08:05
This intoduces the INTERACTIVE_SIGNING, THEIR_TX_SIGNATURES_SENT, and
OUR_TX_SIGNATURES_SENT funded state flags.

A top-level state flag for INTERACTIVE_SIGNING was avoided so that this
work is compatible with splicing as well as V2 channel establishment
(dual-funding).
We fully persist `InteractiveTxSigningSession` as it provides the full
context of the constructed transaction which is still needed for signing.
When this config field is enabled, the dual_fund feature bit will be
set which determines support when receiving `open_channel2` messages.
@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 4f6192f to 21a25fb Compare April 11, 2025 06:08
@dunxen
Copy link
Contributor Author

dunxen commented Apr 11, 2025

Changes:

git diff-tree -U1 4f6192f 21a25fb3f
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index b43e47e68..a60f3f293 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -5849,4 +5849,3 @@ impl<SP: Deref> FundedChannel<SP> where

-               let need_channel_ready = self.check_get_channel_ready(0, logger).is_some();
-               self.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
+               self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());

@@ -6496,3 +6495,3 @@ impl<SP: Deref> FundedChannel<SP> where
                if !matches!(self.context.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing()) {
-                       return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
+                       return Err(ChannelError::Ignore("Ignoring tx_signatures received outside of interactive signing".to_owned()));
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dual-funding weekly goal Someone wants to land this this week
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants