Skip to content

Commit 22b578b

Browse files
committed
Return new funding_txo with splice_locked
When sending or receiving splice_locked results in promoting a FundingScope, return the new funding_txo to ChannelManager. This is used to determine if Event::ChannelReady should be emitted. This is deemed safer than checking the channel if there are any pending splices after it handles splice_locked or after checking funding confirmations.
1 parent 5170373 commit 22b578b

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,6 @@ impl PendingSplice {
21882188
},
21892189
}
21902190
}
2191-
21922191
}
21932192

21942193
/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
@@ -9279,12 +9278,18 @@ where
92799278
&self.context.channel_id,
92809279
);
92819280

9282-
let announcement_sigs = self
9283-
.maybe_promote_splice_funding(confirmed_funding_index, logger)
9281+
let funding_promoted =
9282+
self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9283+
let funding_txo = funding_promoted.then(|| {
9284+
self.funding
9285+
.get_funding_txo()
9286+
.expect("Splice FundingScope should always have a funding_txo")
9287+
});
9288+
let announcement_sigs = funding_promoted
92849289
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
92859290
.flatten();
92869291

9287-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
9292+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
92889293
}
92899294
}
92909295

@@ -9442,16 +9447,22 @@ where
94429447
if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
94439448
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
94449449

9445-
let announcement_sigs = self
9446-
.maybe_promote_splice_funding(confirmed_funding_index, logger)
9450+
let funding_promoted =
9451+
self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9452+
let funding_txo = funding_promoted.then(|| {
9453+
self.funding
9454+
.get_funding_txo()
9455+
.expect("Splice FundingScope should always have a funding_txo")
9456+
});
9457+
let announcement_sigs = funding_promoted
94479458
.then(|| chain_node_signer
94489459
.and_then(|(chain_hash, node_signer, user_config)|
94499460
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
94509461
)
94519462
)
94529463
.flatten();
94539464

9454-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
9465+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
94559466
}
94569467
}
94579468

@@ -9945,7 +9956,7 @@ where
99459956
pub fn splice_locked<NS: Deref, L: Deref>(
99469957
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
99479958
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9948-
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9959+
) -> Result<(Option<OutPoint>, Option<msgs::AnnouncementSignatures>), ChannelError>
99499960
where
99509961
NS::Target: NodeSigner,
99519962
L::Target: Logger,
@@ -9978,13 +9989,18 @@ where
99789989
&self.context.channel_id,
99799990
);
99809991
promote_splice_funding!(self, funding);
9981-
return Ok(self.get_announcement_sigs(
9992+
let funding_txo = self
9993+
.funding
9994+
.get_funding_txo()
9995+
.expect("Splice FundingScope should always have a funding_txo");
9996+
let announcement_sigs = self.get_announcement_sigs(
99829997
node_signer,
99839998
chain_hash,
99849999
user_config,
998510000
best_block.height,
998610001
logger,
9987-
));
10002+
);
10003+
return Ok((Some(funding_txo), announcement_sigs));
998810004
}
998910005

999010006
let err = "unknown splice funding txid";
@@ -10008,7 +10024,7 @@ where
1000810024
}
1000910025

1001010026
pending_splice.received_funding_txid = Some(msg.splice_txid);
10011-
Ok(None)
10027+
Ok((None, None))
1001210028
}
1001310029

1001410030
// Send stuff to our remote peers:
@@ -10735,11 +10751,6 @@ where
1073510751
}
1073610752
}
1073710753

10738-
#[cfg(splicing)]
10739-
pub fn has_pending_splice(&self) -> bool {
10740-
self.pending_splice.is_some()
10741-
}
10742-
1074310754
pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
1074410755
let end = self
1074510756
.funding

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10166,10 +10166,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1016610166
&self.best_block.read().unwrap(),
1016710167
&&logger,
1016810168
);
10169-
let announcement_sigs_opt =
10169+
let (funding_txo, announcement_sigs_opt) =
1017010170
try_channel_entry!(self, peer_state, result, chan_entry);
1017110171

10172-
if !chan.has_pending_splice() {
10172+
if funding_txo.is_some() {
1017310173
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1017410174
insert_short_channel_id!(short_to_chan_info, chan);
1017510175

@@ -10179,9 +10179,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1017910179
channel_id: chan.context.channel_id(),
1018010180
user_channel_id: chan.context.get_user_id(),
1018110181
counterparty_node_id: chan.context.get_counterparty_node_id(),
10182-
funding_txo: chan
10183-
.funding
10184-
.get_funding_txo()
10182+
funding_txo: funding_txo
1018510183
.map(|outpoint| outpoint.into_bitcoin_outpoint()),
1018610184
channel_type: chan.funding.get_channel_type().clone(),
1018710185
},
@@ -12224,7 +12222,7 @@ where
1222412222
pub(super) enum FundingConfirmedMessage {
1222512223
Establishment(msgs::ChannelReady),
1222612224
#[cfg(splicing)]
12227-
Splice(msgs::SpliceLocked),
12225+
Splice(msgs::SpliceLocked, Option<OutPoint>),
1222812226
}
1222912227

1223012228
impl<
@@ -12298,8 +12296,8 @@ where
1229812296
}
1229912297
},
1230012298
#[cfg(splicing)]
12301-
Some(FundingConfirmedMessage::Splice(splice_locked)) => {
12302-
if !funded_channel.has_pending_splice() {
12299+
Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)) => {
12300+
if funding_txo.is_some() {
1230312301
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
1230412302
insert_short_channel_id!(short_to_chan_info, funded_channel);
1230512303

@@ -12308,7 +12306,7 @@ where
1230812306
channel_id: funded_channel.context.channel_id(),
1230912307
user_channel_id: funded_channel.context.get_user_id(),
1231012308
counterparty_node_id: funded_channel.context.get_counterparty_node_id(),
12311-
funding_txo: funded_channel.funding.get_funding_txo().map(|outpoint| outpoint.into_bitcoin_outpoint()),
12309+
funding_txo: funding_txo.map(|outpoint| outpoint.into_bitcoin_outpoint()),
1231212310
channel_type: funded_channel.funding.get_channel_type().clone(),
1231312311
}, None));
1231412312
}

0 commit comments

Comments
 (0)