Skip to content

Commit 8245245

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 5edb1c5 commit 8245245

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9270,12 +9270,17 @@ where
92709270
&self.context.channel_id,
92719271
);
92729272

9273-
let announcement_sigs = self
9274-
.maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9273+
let funding_promoted = self.maybe_promote_splice_funding(
9274+
splice_locked.splice_txid, confirmed_funding_index, logger,
9275+
);
9276+
let funding_txo = funding_promoted
9277+
.then(|| self.funding.get_funding_txo())
9278+
.flatten();
9279+
let announcement_sigs = funding_promoted
92759280
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
92769281
.flatten();
92779282

9278-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
9283+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
92799284
}
92809285
}
92819286

@@ -9433,16 +9438,21 @@ where
94339438
if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
94349439
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
94359440

9436-
let announcement_sigs = self
9437-
.maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9441+
let funding_promoted = self.maybe_promote_splice_funding(
9442+
splice_locked.splice_txid, confirmed_funding_index, logger,
9443+
);
9444+
let funding_txo = funding_promoted
9445+
.then(|| self.funding.get_funding_txo())
9446+
.flatten();
9447+
let announcement_sigs = funding_promoted
94389448
.then(|| chain_node_signer
94399449
.and_then(|(chain_hash, node_signer, user_config)|
94409450
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
94419451
)
94429452
)
94439453
.flatten();
94449454

9445-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
9455+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
94469456
}
94479457
}
94489458

@@ -9936,7 +9946,7 @@ where
99369946
pub fn splice_locked<NS: Deref, L: Deref>(
99379947
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
99389948
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9939-
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9949+
) -> Result<(Option<OutPoint>, Option<msgs::AnnouncementSignatures>), ChannelError>
99409950
where
99419951
NS::Target: NodeSigner,
99429952
L::Target: Logger,
@@ -9969,13 +9979,15 @@ where
99699979
&self.context.channel_id,
99709980
);
99719981
promote_splice_funding!(self, funding);
9972-
return Ok(self.get_announcement_sigs(
9982+
let funding_txo = self.funding.get_funding_txo();
9983+
let announcement_sigs = self.get_announcement_sigs(
99739984
node_signer,
99749985
chain_hash,
99759986
user_config,
99769987
best_block.height,
99779988
logger,
9978-
));
9989+
);
9990+
return Ok((funding_txo, announcement_sigs));
99799991
}
99809992

99819993
let err = "unknown splice funding txid";
@@ -9999,7 +10011,7 @@ where
999910011
}
1000010012

1000110013
pending_splice.received_funding_txid = Some(msg.splice_txid);
10002-
Ok(None)
10014+
Ok((None, None))
1000310015
}
1000410016

1000510017
// Send stuff to our remote peers:
@@ -10726,11 +10738,6 @@ where
1072610738
}
1072710739
}
1072810740

10729-
#[cfg(splicing)]
10730-
pub fn has_pending_splice(&self) -> bool {
10731-
self.pending_splice.is_some()
10732-
}
10733-
1073410741
pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
1073510742
let end = self
1073610743
.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)