Skip to content

Commit 2aae372

Browse files
committed
Check unconfirmation of pending funding transactions
When a splice funding transaction is unconfirmed, update the corresponding FundingScope just as is done when the initial funding transaction is unconfirmed.
1 parent c6c9756 commit 2aae372

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

lightning/src/ln/channel.rs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,6 @@ impl FundingScope {
20612061
self.channel_transaction_parameters.funding_outpoint
20622062
}
20632063

2064-
#[cfg(splicing)]
20652064
fn get_funding_txid(&self) -> Option<Txid> {
20662065
self.channel_transaction_parameters.funding_outpoint.map(|txo| txo.txid)
20672066
}
@@ -9267,7 +9266,7 @@ where
92679266

92689267
#[cfg(splicing)]
92699268
if let Some(confirmed_funding_index) = confirmed_funding_index {
9270-
let pending_splice = match self.pending_splice.as_ref() {
9269+
let pending_splice = match self.pending_splice.as_mut() {
92719270
Some(pending_splice) => pending_splice,
92729271
None => {
92739272
// TODO: Move pending_funding into pending_splice
@@ -9276,8 +9275,26 @@ where
92769275
return Err(ClosureReason::ProcessingError { err });
92779276
},
92789277
};
9279-
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9278+
let funding = self.pending_funding.get_mut(confirmed_funding_index).unwrap();
9279+
9280+
// Check if the splice funding transaction was unconfirmed
9281+
if funding.get_funding_tx_confirmations(height) == 0 {
9282+
funding.funding_tx_confirmation_height = 0;
9283+
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
9284+
if Some(sent_funding_txid) == funding.get_funding_txid() {
9285+
log_warn!(
9286+
logger,
9287+
"Unconfirming sent splice_locked txid {} for channel {}",
9288+
sent_funding_txid,
9289+
&self.context.channel_id,
9290+
);
9291+
pending_splice.sent_funding_txid = None;
9292+
}
9293+
}
9294+
}
92809295

9296+
let pending_splice = self.pending_splice.as_ref().unwrap();
9297+
let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
92819298
if let Some(splice_locked) = self.check_get_splice_locked(pending_splice, funding, height) {
92829299
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
92839300

@@ -9300,31 +9317,45 @@ where
93009317
Ok((None, timed_out_htlcs, announcement_sigs))
93019318
}
93029319

9303-
/// Indicates the funding transaction is no longer confirmed in the main chain. This may
9320+
/// Checks if any funding transaction is no longer confirmed in the main chain. This may
93049321
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
9305-
/// before the channel has reached channel_ready and we can just wait for more blocks.
9306-
#[rustfmt::skip]
9307-
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
9308-
if self.funding.funding_tx_confirmation_height != 0 {
9309-
// We handle the funding disconnection by calling best_block_updated with a height one
9310-
// below where our funding was connected, implying a reorg back to conf_height - 1.
9311-
let reorg_height = self.funding.funding_tx_confirmation_height - 1;
9312-
// We use the time field to bump the current time we set on channel updates if its
9313-
// larger. If we don't know that time has moved forward, we can just set it to the last
9314-
// time we saw and it will be ignored.
9315-
let best_time = self.context.update_time_counter;
9316-
9317-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9318-
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9319-
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9320-
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9321-
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9322-
Ok(())
9323-
},
9324-
Err(e) => Err(e)
9322+
/// before the channel has reached channel_ready or splice_locked, and we can just wait for more
9323+
/// blocks.
9324+
#[rustfmt::skip]
9325+
pub fn transaction_unconfirmed<L: Deref>(
9326+
&mut self, txid: &Txid, logger: &L,
9327+
) -> Result<(), ClosureReason>
9328+
where
9329+
L::Target: Logger,
9330+
{
9331+
let unconfirmed_funding = core::iter::once(&mut self.funding)
9332+
.chain(self.pending_funding.iter_mut())
9333+
.find(|funding| funding.get_funding_txid() == Some(*txid));
9334+
9335+
if let Some(funding) = unconfirmed_funding {
9336+
if funding.funding_tx_confirmation_height != 0 {
9337+
// We handle the funding disconnection by calling best_block_updated with a height one
9338+
// below where our funding was connected, implying a reorg back to conf_height - 1.
9339+
let reorg_height = funding.funding_tx_confirmation_height - 1;
9340+
// We use the time field to bump the current time we set on channel updates if its
9341+
// larger. If we don't know that time has moved forward, we can just set it to the last
9342+
// time we saw and it will be ignored.
9343+
let best_time = self.context.update_time_counter;
9344+
9345+
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
9346+
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
9347+
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
9348+
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
9349+
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
9350+
Ok(())
9351+
},
9352+
Err(e) => Err(e),
9353+
}
9354+
} else {
9355+
// We never learned about the funding confirmation anyway, just ignore
9356+
Ok(())
93259357
}
93269358
} else {
9327-
// We never learned about the funding confirmation anyway, just ignore
93289359
Ok(())
93299360
}
93309361
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11966,11 +11966,8 @@ where
1196611966
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
1196711967
self, || -> NotifyOption { NotifyOption::DoPersist });
1196811968
self.do_chain_event(None, |channel| {
11969-
if let Some(funding_txo) = channel.funding.get_funding_txo() {
11970-
if funding_txo.txid == *txid {
11971-
channel.funding_transaction_unconfirmed(&&WithChannelContext::from(&self.logger, &channel.context, None)).map(|()| (None, Vec::new(), None))
11972-
} else { Ok((None, Vec::new(), None)) }
11973-
} else { Ok((None, Vec::new(), None)) }
11969+
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
11970+
channel.transaction_unconfirmed(txid, &&logger).map(|()| (None, Vec::new(), None))
1197411971
});
1197511972
}
1197611973
}

0 commit comments

Comments
 (0)