Skip to content

Commit 71182e1

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 4c0d7cd commit 71182e1

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

lightning/src/ln/channel.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9279,12 +9279,16 @@ where
92799279
&self.context.channel_id,
92809280
);
92819281

9282-
let announcement_sigs = self
9283-
.maybe_promote_splice_funding(confirmed_funding_index, logger)
9282+
let funding_promoted =
9283+
self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9284+
let funding_txo = funding_promoted
9285+
.then(|| self.funding.get_funding_txo())
9286+
.flatten();
9287+
let announcement_sigs = funding_promoted
92849288
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
92859289
.flatten();
92869290

9287-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
9291+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
92889292
}
92899293
}
92909294

@@ -9442,16 +9446,20 @@ where
94429446
if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
94439447
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
94449448

9445-
let announcement_sigs = self
9446-
.maybe_promote_splice_funding(confirmed_funding_index, logger)
9449+
let funding_promoted =
9450+
self.maybe_promote_splice_funding(confirmed_funding_index, logger);
9451+
let funding_txo = funding_promoted
9452+
.then(|| self.funding.get_funding_txo())
9453+
.flatten();
9454+
let announcement_sigs = funding_promoted
94479455
.then(|| chain_node_signer
94489456
.and_then(|(chain_hash, node_signer, user_config)|
94499457
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
94509458
)
94519459
)
94529460
.flatten();
94539461

9454-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
9462+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
94559463
}
94569464
}
94579465

@@ -9945,7 +9953,7 @@ where
99459953
pub fn splice_locked<NS: Deref, L: Deref>(
99469954
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
99479955
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9948-
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9956+
) -> Result<(Option<OutPoint>, Option<msgs::AnnouncementSignatures>), ChannelError>
99499957
where
99509958
NS::Target: NodeSigner,
99519959
L::Target: Logger,
@@ -9978,13 +9986,15 @@ where
99789986
&self.context.channel_id,
99799987
);
99809988
promote_splice_funding!(self, funding);
9981-
return Ok(self.get_announcement_sigs(
9989+
let funding_txo = self.funding.get_funding_txo();
9990+
let announcement_sigs = self.get_announcement_sigs(
99829991
node_signer,
99839992
chain_hash,
99849993
user_config,
99859994
best_block.height,
99869995
logger,
9987-
));
9996+
);
9997+
return Ok((funding_txo, announcement_sigs));
99889998
}
99899999

999010000
let err = "unknown splice funding txid";
@@ -10008,7 +10018,7 @@ where
1000810018
}
1000910019

1001010020
pending_splice.received_funding_txid = Some(msg.splice_txid);
10011-
Ok(None)
10021+
Ok((None, None))
1001210022
}
1001310023

1001410024
// Send stuff to our remote peers:
@@ -10735,11 +10745,6 @@ where
1073510745
}
1073610746
}
1073710747

10738-
#[cfg(splicing)]
10739-
pub fn has_pending_splice(&self) -> bool {
10740-
self.pending_splice.is_some()
10741-
}
10742-
1074310748
pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
1074410749
let end = self
1074510750
.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)