-
Notifications
You must be signed in to change notification settings - Fork 436
Refactor BroadcasterInterface to include TransactionType
#4353
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
base: main
Are you sure you want to change the base?
Conversation
|
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
4f6a8a4 to
be02cec
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs need a lot of love
| /// A single funding transaction may establish multiple channels when using batch funding. | ||
| channel_ids: Vec<ChannelId>, | ||
| }, | ||
| /// A cooperative close transaction mutually agreed upon by both parties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean all transactions are mutually agreed upon by both parties? Maybe describe what a coop close tx means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, changed it up a bit, but let me know what exactly is missing for you.
be02cec to
4f6a8a4
Compare
4f6a8a4 to
fb8378c
Compare
fb8378c to
54b52f3
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4353 +/- ##
==========================================
+ Coverage 85.98% 85.99% +0.01%
==========================================
Files 156 156
Lines 102641 102734 +93
Branches 102641 102734 +93
==========================================
+ Hits 88258 88349 +91
- Misses 11873 11875 +2
Partials 2510 2510
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] | ||
| pub enum BroadcastType { | ||
| /// A funding transaction establishing a new channel. | ||
| Funding, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splice transactions should have their own variant, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, hence the question above regarding which variants we want. So, post #4261 we'll now three variants (SpliceIn/SpliceOut/SpliceInAndOut)?
And AFAICT we need to track the TransactionType across the entire flow (i.e., inititally set in SpliceContribution, track in SpliceInstructions, PendingFunding, and then return via FundingTxSigned to hand it to broadcast_interactive_funding? Or do you see a way to shortcut or re-derive the type of splice contribution at the last step somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, post #4261 we'll now three variants (SpliceIn/SpliceOut/SpliceInAndOut)?
If we want more splicing context we should include the splice metadata in the splice variant rather than having a separate variant for each splice init logic. This feels like a followup though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify a bit - the differentiation between "splice out" and "splice in" at the top-level API is a bug that we're fixing - there is only a "splice" which can have constituent parts that are in + out. Its a useful differentiation when building splicing instructions but after that it should dissapear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And AFAICT we need to track the TransactionType across the entire flow (i.e., inititally set in SpliceContribution, track in SpliceInstructions, PendingFunding, and then return via FundingTxSigned to hand it to broadcast_interactive_funding? Or do you see a way to shortcut or re-derive the type of splice contribution at the last step somehow?
The raw transaction is already available since we're broadcasting it so they can inspect its inputs and outputs if they want to distinguish between splice in/out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The raw transaction is already available since we're broadcasting it so they can inspect its inputs and outputs if they want to distinguish between splice in/out.
Will this also work going forward with dual funding, given that then we might reuse the same broadcast_interactive_funding path? Or would we get wrong classifications then, if we don't track the 'intent' from the beginning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but for the user it still makes a fundamental difference, no? So in the actual API we still want to discern in/out, right?
Sure at the constructor level we have utilities that allow you to only do one, but the right API definitely isn't a tri-state where the third state is "both". Rather, where we want to expose it it should be a "does this splice have inputs from me" and "does this splice have outputs I added" methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this also work going forward with dual funding, given that then we might reuse the same broadcast_interactive_funding path? Or would we get wrong classifications then, if we don't track the 'intent' from the beginning?
Dual-funding should keep the Funding type and we can just return that along with the transaction since the ChannelManager doesn't have enough context to determine the correct one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline: for now, just add a Splice variant. While we want to add more context (in/out etc) to the Splice variant soon, for now we just need to return and hand through the TransactionType together with the Transaction from its origin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now updated accordingly.
54b52f3 to
5912fd4
Compare
|
FWIW, I also now pushed a fixup renaming to |
BroadcasterInterface to include BroadcastTypeBroadcasterInterface to include TransactionType
a499b27 to
06377a0
Compare
|
This needs a rebase now, feel free to squash. There's one pending comment from Matt left that still needs to be addressed. |
9ab7f14 to
302599d
Compare
Rebased and also added a commit that adds some test coverage for the |
TheBlueMatt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few comments on the docs, otherwise feel free to squash.
302599d to
5c5d180
Compare
Squashed with the following changes: diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs
index cbac84aaf..90f4aa13e 100644
--- a/lightning/src/chain/chaininterface.rs
+++ b/lightning/src/chain/chaininterface.rs
@@ -41,5 +41,6 @@ pub enum TransactionType {
/// A transaction cooperatively closing a channel.
///
- /// A transaction of this type will be broadcast when cooperatively closing a channel via [`ChannelManager::close_channel`].
+ /// A transaction of this type will be broadcast when cooperatively closing a channel via
+ /// [`ChannelManager::close_channel`] or if the counterparty closes the channel.
///
/// [`ChannelManager::close_channel`]: crate::ln::channelmanager::ChannelManager::close_channel
@@ -50,5 +51,7 @@ pub enum TransactionType {
/// A transaction being broadcast to force-close the channel.
///
- /// A transaction of this type will be broadcast when unilaterally closing a channel via [`ChannelManager::force_close_broadcasting_latest_txn`].
+ /// A transaction of this type will be broadcast when unilaterally closing a channel via
+ /// [`ChannelManager::force_close_broadcasting_latest_txn`] or if the counterparty force-closes
+ /// the channel..
///
/// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn
@@ -67,5 +70,15 @@ pub enum TransactionType {
channel_id: ChannelId,
},
- /// A transaction claiming outputs from a commitment transaction (HTLC claims, penalty/justice).
+ /// A transaction which is resolving an output spendable by both us and our counterparty.
+ ///
+ /// When a channel closes via the unilateral close path, there may be transaction outputs which
+ /// are spendable by either our counterparty or us and represent some lightning state. In order
+ /// to resolve that state, the [`ChannelMonitor`] will spend any such outputs, ensuring funds
+ /// are only available to us prior to generating an [`Event::SpendableOutputs`]. This
+ /// transaction is one such transaction - resolving in-flight HTLCs or punishing our
+ /// counterparty if they broadcasted an outdated state.
+ ///
+ /// [`ChannelMonitor`]: crate::chain::ChannelMonitor
+ /// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
Claim {
/// The ID of the channel from which outputs are being claimed. |
Add a `TransactionType` enum to provide context about the type of transaction being broadcast. This information can be useful for logging, filtering, or prioritization purposes. The `TransactionType` variants are: - `Funding`: A funding transaction establishing a new channel - `CooperativeClose`: A cooperative close transaction - `UnilateralClose`: A force-close transaction - `AnchorBump`: An anchor transaction for CPFP fee-bumping - `Claim`: A transaction claiming outputs from commitment tx - `Sweep`: A transaction sweeping spendable outputs to wallet Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
Add parallel `txn_types` vector to `TestBroadcaster` to track `TransactionType` alongside broadcast transactions. Existing `txn_broadcast()` API remains unchanged for backward compatibility. New `txn_broadcast_with_types()` API allows tests to verify transaction types. Also add a `clear()` helper method and update test files to use it instead of directly manipulating `txn_broadcasted`, ensuring the two vectors stay in sync. Update splice tests to use the new API and verify that splice transactions are broadcast with the correct `TransactionType`. Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
Co-Authored-By: HAL 9000
5c5d180 to
0715f4a
Compare
Fixes #3566.
and: