Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 480
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
Merged
TheBlueMatt
merged 3 commits into
lightningdevkit:main
from
tnull:2026-01-broadcast-type-refactorFeb 5, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -15,10 +15,97 @@ | ||
| use core::{cmp, ops::Deref}; | ||
| use crate::ln::types::ChannelId; | ||
| use crate::prelude::*; | ||
| use bitcoin::transaction::Transaction; | ||
| /// Represents the class of transaction being broadcast. | ||
| /// | ||
| /// This is used to provide context about the type of transaction being broadcast, which may be | ||
| /// useful for logging, filtering, or prioritization purposes. | ||
| #[derive(Clone, Debug, Hash, PartialEq, Eq)] | ||
| pub enum TransactionType { | ||
| /// A funding transaction establishing a new channel. | ||
| /// | ||
| /// If we initiated the channel the transaction given to | ||
| /// [`ChannelManager::funding_transaction_generated`] will be broadcast with this type. | ||
| /// | ||
| /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated | ||
| Funding { | ||
| /// The IDs of the channels being funded. | ||
| /// | ||
| /// A single funding transaction may establish multiple channels when using batch funding. | ||
| channel_ids: Vec<ChannelId>, | ||
| }, | ||
| /// A transaction cooperatively closing a channel. | ||
TheBlueMatt marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /// | ||
| /// 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 | ||
| CooperativeClose { | ||
| /// The ID of the channel being closed. | ||
| channel_id: ChannelId, | ||
| }, | ||
| /// 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`] or if the counterparty force-closes | ||
| /// the channel. | ||
| /// | ||
| /// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn | ||
| UnilateralClose { | ||
| /// The ID of the channel being force-closed. | ||
| channel_id: ChannelId, | ||
| }, | ||
| /// An anchor bumping transaction used for CPFP fee-bumping a closing transaction. | ||
| /// | ||
| /// This will be broadcast after an anchor channel has been closed. See | ||
| /// [`BumpTransactionEvent`] for more information. | ||
| /// | ||
| /// [`BumpTransactionEvent`]: crate::events::bump_transaction::BumpTransactionEvent | ||
| AnchorBump { | ||
| /// The ID of the channel whose closing transaction is being fee-bumped. | ||
| channel_id: ChannelId, | ||
| }, | ||
| /// 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. | ||
| channel_id: ChannelId, | ||
| }, | ||
| /// A transaction generated by the [`OutputSweeper`], sweeping [`SpendableOutputDescriptor`]s | ||
| /// to the user's wallet. | ||
| /// | ||
| /// [`OutputSweeper`]: crate::util::sweep::OutputSweeper | ||
| /// [`SpendableOutputDescriptor`]: crate::sign::SpendableOutputDescriptor | ||
| Sweep { | ||
| /// The IDs of the channels from which outputs are being swept, if known. | ||
| /// | ||
| /// A single sweep transaction may aggregate outputs from multiple channels. | ||
| channel_ids: Vec<ChannelId>, | ||
| }, | ||
| /// A splice transaction modifying an existing channel's funding. | ||
| /// | ||
| /// A transaction of this type will be broadcast as a result of a [`ChannelManager::splice_channel`] operation. | ||
| /// | ||
| /// [`ChannelManager::splice_channel`]: crate::ln::channelmanager::ChannelManager::splice_channel | ||
| Splice { | ||
| /// The ID of the channel being spliced. | ||
| channel_id: ChannelId, | ||
| }, | ||
| } | ||
| // TODO: Define typed abstraction over feerates to handle their conversions. | ||
| pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 { | ||
| (fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value()) | ||
| @@ -45,11 +132,14 @@ pub trait BroadcasterInterface { | ||
| /// | ||
| /// Bitcoin transaction packages are defined in BIP 331 and here: | ||
| /// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md> | ||
| fn broadcast_transactions(&self, txs: &[&Transaction]); | ||
| /// | ||
| /// Each transaction is paired with a [`TransactionType`] indicating the class of transaction | ||
| /// being broadcast, which may be useful for logging, filtering, or prioritization. | ||
| fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]); | ||
| } | ||
| impl<T: BroadcasterInterface + ?Sized, B: Deref<Target = T>> BroadcasterInterface for B { | ||
| fn broadcast_transactions(&self, txs: &[&Transaction]) { | ||
| fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]) { | ||
| self.deref().broadcast_transactions(txs) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
oops, note that because we're still not living in a funding-v2-required world
ChannelIds aren't the right unique indicator of a specific channel. We need the counterparty node id as well. We should also (obviously) provide theuser_channel_idhere.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, good point regarding the
counterparty_node_id, though it seems we then first need it to add to a few other places. For example, we don't track it in theSpendableOutputsevent (onlychannel_id) and therefore we also don't track it inOutputSweeper.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.
Done in #4393