Skip to content

Commit ac1d0fb

Browse files
committed
f 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 9176956 commit ac1d0fb

3 files changed

Lines changed: 38 additions & 13 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: 21 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,
@@ -6865,8 +6865,8 @@ pub struct FundingTxSigned {
68656865
/// Signatures that should be sent to the counterparty, if necessary.
68666866
pub tx_signatures: Option<msgs::TxSignatures>,
68676867

6868-
/// The fully-signed funding transaction to be broadcast.
6869-
pub funding_tx: Option<Transaction>,
6868+
/// The fully-signed funding transaction to be broadcast, along with the transaction type.
6869+
pub funding_tx: Option<(Transaction, TransactionType)>,
68706870

68716871
/// Information about the completed funding negotiation.
68726872
pub splice_negotiated: Option<SpliceFundingNegotiated>,
@@ -9178,6 +9178,15 @@ where
91789178
(None, None)
91799179
};
91809180

9181+
let funding_tx = funding_tx.map(|tx| {
9182+
let tx_type = if splice_negotiated.is_some() {
9183+
TransactionType::Splice { channel_id: self.context.channel_id }
9184+
} else {
9185+
TransactionType::Funding { channel_ids: vec![self.context.channel_id] }
9186+
};
9187+
(tx, tx_type)
9188+
});
9189+
91819190
Ok(FundingTxSigned { tx_signatures, funding_tx, splice_negotiated, splice_locked })
91829191
}
91839192

@@ -9245,6 +9254,15 @@ where
92459254
(None, None)
92469255
};
92479256

9257+
let funding_tx = funding_tx.map(|tx| {
9258+
let tx_type = if splice_negotiated.is_some() {
9259+
TransactionType::Splice { channel_id: self.context.channel_id }
9260+
} else {
9261+
TransactionType::Funding { channel_ids: vec![self.context.channel_id] }
9262+
};
9263+
(tx, tx_type)
9264+
});
9265+
92489266
Ok(FundingTxSigned {
92499267
tx_signatures: holder_tx_signatures,
92509268
funding_tx,

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6459,10 +6459,11 @@ where
64596459
splice_negotiated,
64606460
splice_locked,
64616461
}) => {
6462-
if let Some(funding_tx) = funding_tx {
6462+
if let Some((funding_tx, tx_type)) = funding_tx {
64636463
self.broadcast_interactive_funding(
64646464
chan,
64656465
&funding_tx,
6466+
Some(tx_type),
64666467
&self.logger,
64676468
);
64686469
}
@@ -6539,18 +6540,19 @@ where
65396540
}
65406541

65416542
fn broadcast_interactive_funding(
6542-
&self, channel: &mut FundedChannel<SP>, funding_tx: &Transaction, logger: &L,
6543+
&self, channel: &mut FundedChannel<SP>, funding_tx: &Transaction,
6544+
transaction_type: Option<TransactionType>, logger: &L,
65436545
) {
65446546
let logger = WithChannelContext::from(logger, channel.context(), None);
65456547
log_info!(
65466548
logger,
65476549
"Broadcasting signed interactive funding transaction {}",
65486550
funding_tx.compute_txid()
65496551
);
6550-
self.tx_broadcaster.broadcast_transactions(&[(
6551-
funding_tx,
6552-
TransactionType::Funding { channel_ids: vec![channel.context().channel_id()] },
6553-
)]);
6552+
let tx_type = transaction_type.unwrap_or_else(|| TransactionType::Funding {
6553+
channel_ids: vec![channel.context().channel_id()],
6554+
});
6555+
self.tx_broadcaster.broadcast_transactions(&[(funding_tx, tx_type)]);
65546556
{
65556557
let mut pending_events = self.pending_events.lock().unwrap();
65566558
emit_channel_pending_event!(pending_events, channel);
@@ -10287,8 +10289,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1028710289
splice_negotiated,
1028810290
splice_locked,
1028910291
}) => {
10290-
if let Some(funding_tx) = funding_tx {
10291-
self.broadcast_interactive_funding(channel, &funding_tx, &self.logger);
10292+
if let Some((funding_tx, tx_type)) = funding_tx {
10293+
self.broadcast_interactive_funding(channel, &funding_tx, Some(tx_type), &self.logger);
1029210294
}
1029310295

1029410296
if let Some(splice_negotiated) = splice_negotiated {
@@ -11400,8 +11402,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1140011402
msg: splice_locked,
1140111403
});
1140211404
}
11403-
if let Some(ref funding_tx) = funding_tx {
11404-
self.broadcast_interactive_funding(chan, funding_tx, &self.logger);
11405+
if let Some((ref funding_tx, ref tx_type)) = funding_tx {
11406+
self.broadcast_interactive_funding(chan, funding_tx, Some(tx_type.clone()), &self.logger);
1140511407
}
1140611408
if let Some(splice_negotiated) = splice_negotiated {
1140711409
self.pending_events.lock().unwrap().push_back((

0 commit comments

Comments
 (0)