Skip to content

Commit b8682c5

Browse files
committed
Add TransactionType::Splice variant for splice transactions
Add a new `Splice` variant to `TransactionType` to distinguish splice transactions from regular funding transactions when broadcasting. Update `FundingTxSigned` to include the transaction type alongside the funding transaction, allowing the channel manager to broadcast with the correct type information for both initial funding and splice operations. Co-Authored-By: HAL 9000
1 parent 59aaa89 commit b8682c5

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

lightning/src/chain/chaininterface.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ pub enum TransactionType {
6363
/// A single sweep transaction may aggregate outputs from multiple channels.
6464
channel_ids: Vec<ChannelId>,
6565
},
66+
/// A splice transaction modifying an existing channel's funding.
67+
Splice {
68+
/// The ID of the channel being spliced.
69+
channel_id: ChannelId,
70+
},
6671
}
6772

6873
// TODO: Define typed abstraction over feerates to handle their conversions.

lightning/src/ln/channel.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use bitcoin::{secp256k1, sighash, FeeRate, Sequence, TxIn};
2828

2929
use crate::blinded_path::message::BlindedMessagePath;
3030
use crate::chain::chaininterface::{
31-
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
31+
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator, TransactionType,
3232
};
3333
use crate::chain::channelmonitor::{
3434
ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, CommitmentHTLCData,
@@ -2103,6 +2103,8 @@ where
21032103
},
21042104
};
21052105

2106+
let channel_id = context.channel_id;
2107+
21062108
let signing_session = if let Some(signing_session) =
21072109
context.interactive_tx_signing_session.as_mut()
21082110
{
@@ -2213,6 +2215,15 @@ where
22132215
(None, None)
22142216
};
22152217

2218+
let funding_tx = funding_tx.map(|tx| {
2219+
let tx_type = if splice_negotiated.is_some() {
2220+
TransactionType::Splice { channel_id }
2221+
} else {
2222+
TransactionType::Funding { channel_ids: vec![channel_id] }
2223+
};
2224+
(tx, tx_type)
2225+
});
2226+
22162227
// If we have a pending splice with a buffered initial commitment signed from our
22172228
// counterparty, process it now that we have provided our signatures.
22182229
let counterparty_initial_commitment_signed_result =
@@ -6919,8 +6930,8 @@ pub(super) struct FundingTxSigned {
69196930
/// Signatures that should be sent to the counterparty, if necessary.
69206931
pub tx_signatures: Option<msgs::TxSignatures>,
69216932

6922-
/// The fully-signed funding transaction to be broadcast.
6923-
pub funding_tx: Option<Transaction>,
6933+
/// The fully-signed funding transaction to be broadcast, along with the transaction type.
6934+
pub funding_tx: Option<(Transaction, TransactionType)>,
69246935

69256936
/// Information about the completed funding negotiation.
69266937
pub splice_negotiated: Option<SpliceFundingNegotiated>,
@@ -9143,6 +9154,15 @@ where
91439154
(None, None)
91449155
};
91459156

9157+
let funding_tx = funding_tx.map(|tx| {
9158+
let tx_type = if splice_negotiated.is_some() {
9159+
TransactionType::Splice { channel_id: self.context.channel_id }
9160+
} else {
9161+
TransactionType::Funding { channel_ids: vec![self.context.channel_id] }
9162+
};
9163+
(tx, tx_type)
9164+
});
9165+
91469166
Ok(FundingTxSigned {
91479167
commitment_signed: None,
91489168
counterparty_initial_commitment_signed_result: None,

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,13 +6429,14 @@ impl<
64296429
splice_negotiated,
64306430
splice_locked,
64316431
}) => {
6432-
if let Some(funding_tx) = funding_tx {
6432+
if let Some((funding_tx, tx_type)) = funding_tx {
64336433
let funded_chan = chan.as_funded_mut().expect(
64346434
"Funding transactions ready for broadcast can only exist for funded channels",
64356435
);
64366436
self.broadcast_interactive_funding(
64376437
funded_chan,
64386438
&funding_tx,
6439+
Some(tx_type),
64396440
&self.logger,
64406441
);
64416442
}
@@ -6563,18 +6564,19 @@ impl<
65636564
}
65646565

65656566
fn broadcast_interactive_funding(
6566-
&self, channel: &mut FundedChannel<SP>, funding_tx: &Transaction, logger: &L,
6567+
&self, channel: &mut FundedChannel<SP>, funding_tx: &Transaction,
6568+
transaction_type: Option<TransactionType>, logger: &L,
65676569
) {
65686570
let logger = WithChannelContext::from(logger, channel.context(), None);
65696571
log_info!(
65706572
logger,
65716573
"Broadcasting signed interactive funding transaction {}",
65726574
funding_tx.compute_txid()
65736575
);
6574-
self.tx_broadcaster.broadcast_transactions(&[(
6575-
funding_tx,
6576-
TransactionType::Funding { channel_ids: vec![channel.context().channel_id()] },
6577-
)]);
6576+
let tx_type = transaction_type.unwrap_or_else(|| TransactionType::Funding {
6577+
channel_ids: vec![channel.context().channel_id()],
6578+
});
6579+
self.tx_broadcaster.broadcast_transactions(&[(funding_tx, tx_type)]);
65786580
{
65796581
let mut pending_events = self.pending_events.lock().unwrap();
65806582
emit_channel_pending_event!(pending_events, channel);
@@ -11402,8 +11404,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1140211404
msg: splice_locked,
1140311405
});
1140411406
}
11405-
if let Some(ref funding_tx) = funding_tx {
11406-
self.broadcast_interactive_funding(chan, funding_tx, &self.logger);
11407+
if let Some((ref funding_tx, ref tx_type)) = funding_tx {
11408+
self.broadcast_interactive_funding(chan, funding_tx, Some(tx_type.clone()), &self.logger);
1140711409
}
1140811410
if let Some(splice_negotiated) = splice_negotiated {
1140911411
self.pending_events.lock().unwrap().push_back((

0 commit comments

Comments
 (0)