Skip to content

Commit 98ee8b1

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 a8f9d10 commit 98ee8b1

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
@@ -9260,12 +9260,17 @@ where
92609260
&self.context.channel_id,
92619261
);
92629262

9263-
let announcement_sigs = self
9264-
.maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9263+
let funding_promoted = self.maybe_promote_splice_funding(
9264+
splice_locked.splice_txid, confirmed_funding_index, logger,
9265+
);
9266+
let funding_txo = funding_promoted
9267+
.then(|| self.funding.get_funding_txo())
9268+
.flatten();
9269+
let announcement_sigs = funding_promoted
92659270
.then(|| self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger))
92669271
.flatten();
92679272

9268-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
9273+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), announcement_sigs));
92699274
}
92709275
}
92719276

@@ -9426,16 +9431,21 @@ where
94269431

94279432
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
94289433

9429-
let announcement_sigs = self
9430-
.maybe_promote_splice_funding(splice_locked.splice_txid, confirmed_funding_index, logger)
9434+
let funding_promoted = self.maybe_promote_splice_funding(
9435+
splice_locked.splice_txid, confirmed_funding_index, logger,
9436+
);
9437+
let funding_txo = funding_promoted
9438+
.then(|| self.funding.get_funding_txo())
9439+
.flatten();
9440+
let announcement_sigs = funding_promoted
94319441
.then(|| chain_node_signer
94329442
.and_then(|(chain_hash, node_signer, user_config)|
94339443
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
94349444
)
94359445
)
94369446
.flatten();
94379447

9438-
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), timed_out_htlcs, announcement_sigs));
9448+
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked, funding_txo)), timed_out_htlcs, announcement_sigs));
94399449
}
94409450
}
94419451

@@ -9929,7 +9939,7 @@ where
99299939
pub fn splice_locked<NS: Deref, L: Deref>(
99309940
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,
99319941
user_config: &UserConfig, best_block: &BestBlock, logger: &L,
9932-
) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
9942+
) -> Result<(Option<OutPoint>, Option<msgs::AnnouncementSignatures>), ChannelError>
99339943
where
99349944
NS::Target: NodeSigner,
99359945
L::Target: Logger,
@@ -9962,13 +9972,15 @@ where
99629972
&self.context.channel_id,
99639973
);
99649974
promote_splice_funding!(self, funding);
9965-
return Ok(self.get_announcement_sigs(
9975+
let funding_txo = self.funding.get_funding_txo();
9976+
let announcement_sigs = self.get_announcement_sigs(
99669977
node_signer,
99679978
chain_hash,
99689979
user_config,
99699980
best_block.height,
99709981
logger,
9971-
));
9982+
);
9983+
return Ok((funding_txo, announcement_sigs));
99729984
}
99739985

99749986
let err = "unknown splice funding txid";
@@ -9992,7 +10004,7 @@ where
999210004
}
999310005

999410006
pending_splice.received_funding_txid = Some(msg.splice_txid);
9995-
Ok(None)
10007+
Ok((None, None))
999610008
}
999710009

999810010
// Send stuff to our remote peers:
@@ -10719,11 +10731,6 @@ where
1071910731
}
1072010732
}
1072110733

10722-
#[cfg(splicing)]
10723-
pub fn has_pending_splice(&self) -> bool {
10724-
self.pending_splice.is_some()
10725-
}
10726-
1072710734
pub fn remove_legacy_scids_before_block(&mut self, height: u32) -> alloc::vec::Drain<u64> {
1072810735
let end = self
1072910736
.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)