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 10 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 33.19328% with 159 lines in your changes missing coverage. Please review.

Project coverage is 89.27%. Comparing base (aaef672) to head (0f61264).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/interactivetxs.rs 6.60% 99 Missing ⚠️
lightning/src/ln/channel.rs 54.28% 43 Missing and 5 partials ⚠️
lightning/src/ln/channelmanager.rs 35.29% 8 Missing and 3 partials ⚠️
lightning/src/ln/dual_funding_tests.rs 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3637      +/-   ##
==========================================
+ Coverage   89.23%   89.27%   +0.03%     
==========================================
  Files         155      155              
  Lines      119329   121895    +2566     
  Branches   119329   121895    +2566     
==========================================
+ Hits       106488   108817    +2329     
- Misses      10243    10473     +230     
- Partials     2598     2605       +7     

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

@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
@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 3 times, most recently from e510273 to 2fa5802 Compare March 17, 2025 12:08
@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.

Comment on lines 7031 to 7058
let commitment_update = if !session.counterparty_sent_tx_signatures() && msg.next_local_commitment_number == 0 {
// if it has not received tx_signatures for that funding transaction AND
// if next_commitment_number is zero:
// MUST retransmit its commitment_signed for that funding transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume for splicing this will need to be generalized to return a commitment_signed for the current commitment number (still 0 for the open case). Is it worth taking care of that now?

Copy link
Contributor Author

@dunxen dunxen Mar 20, 2025

Choose a reason for hiding this comment

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

For splicing this seems a bit up in the air still, but yes will have to generalise. Discussion here: https://github.com/lightning/bolts/pull/1214/files#discussion_r1882436204

(None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
}
} else {
return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state".into()));
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't close the channel here. It seems possible that we clear the session because we exchanged tx_signatures from our PoV, but they still need us to retransmit tx_signatures because they didn't receive it the first time around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think it's then just fine to warn here since we are broadcasting the funding tx anyway. Unfortunately we don't have tx_signatures to send them since the session is cleared.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, that sounds like a protocol violation then, no? It'd be weird for the counterparty to not have received the message but then see the channel confirm. We might need to guarantee the send, either by not clearing the session until a later point, or reconstructing the tx_signatures message from the fully-signed transaction we plan to broadcast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reconstructing may not be possible as we would have forgotten which inputs are the holder's at this point, so best to not clear until 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.

Ok in latest push we now only clear the session later.

Copy link
Contributor

Choose a reason for hiding this comment

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

By not clearing this, when we process tx_signatures again, won't we add duplicative witness data?

self.unsigned_tx.add_remote_witnesses(tx_signatures.witnesses.clone());

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch 2 times, most recently from d226021 to 20514fb Compare March 19, 2025 10:55
@dunxen
Copy link
Contributor Author

dunxen commented Mar 19, 2025

Just pushed the change for full persistence of InteractiveTxConstructor. Still addressing other feedback.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch 3 times, most recently from af75699 to 9676dd5 Compare March 24, 2025 11:48
@wpaulino
Copy link
Contributor

@dunxen let us know when this is ready for another round

Comment on lines +1269 to +1191
{1, Local} => (),
{3, Remote} => (),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typically we use:

(1, Local) => {},
(3, Remote) => {},

Also, can number these 0 and 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case these are both tuple variants, so the () => {} syntax doesn't work as it won't include the the 0 field of the tuple, so it doesn't compile. That syntax would only work for unit/struct variants, I believe.

Comment on lines +1314 to +1237
{1, Single} => (),
{3, SharedControlFullyOwned} => (),
{5, Shared} => (),
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

Comment on lines +479 to +438
impl_writeable_tlv_based!(InteractiveTxSigningSession, {
(1, unsigned_tx, required),
(3, holder_sends_tx_signatures_first, required),
(5, has_received_commitment_signed, required),
(7, holder_tx_signatures, required),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, when introducing a new serialization, we can number these starting at 0 and use both even and odd given no previous versions understand this. Likewise elsewhere.

Copy link
Contributor

@jkczyz jkczyz Mar 25, 2025

Choose a reason for hiding this comment

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

Actually, given @wpaulino's comment on another PR, I'm not sure if this would be desirable. @TheBlueMatt What are the best practices when adding serialization for a new struct? IIRC, you had once suggested just numbering with both even and add. But Wilmer's comment of only using odd makes sense to me.

@dunxen dunxen force-pushed the 2025-02-interactivesigningstate branch from 9676dd5 to 11e52b8 Compare March 26, 2025 08:36
dunxen added 10 commits March 27, 2025 14:41
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
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).
… funding tx when signed & clear signing session on channel_ready received
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 11e52b8 to b78d5dc Compare March 27, 2025 12:41
@dunxen
Copy link
Contributor Author

dunxen commented Mar 27, 2025

@wpaulino, @jkczyz, sorry for the delay. This is ready for another round.

@dunxen dunxen requested review from jkczyz and wpaulino March 27, 2025 12:43
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