Skip to content

Commit a93df89

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 63b2004 commit a93df89

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

lightning/src/ln/channel.rs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,6 @@ impl FundingScope {
19181918
self.channel_transaction_parameters.funding_outpoint
19191919
}
19201920

1921-
#[cfg(splicing)]
19221921
fn get_funding_txid(&self) -> Option<Txid> {
19231922
self.channel_transaction_parameters.funding_outpoint.map(|txo| txo.txid)
19241923
}
@@ -8867,32 +8866,46 @@ impl<SP: Deref> FundedChannel<SP> where
88678866
Ok((None, timed_out_htlcs, announcement_sigs))
88688867
}
88698868

8870-
/// Indicates the funding transaction is no longer confirmed in the main chain. This may
8869+
/// Checks if any funding transaction is no longer confirmed in the main chain. This may
88718870
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
8872-
/// before the channel has reached channel_ready and we can just wait for more blocks.
8873-
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8874-
if self.funding.funding_tx_confirmation_height != 0 {
8875-
// We handle the funding disconnection by calling best_block_updated with a height one
8876-
// below where our funding was connected, implying a reorg back to conf_height - 1.
8877-
let reorg_height = self.funding.funding_tx_confirmation_height - 1;
8878-
// We use the time field to bump the current time we set on channel updates if its
8879-
// larger. If we don't know that time has moved forward, we can just set it to the last
8880-
// time we saw and it will be ignored.
8881-
let best_time = self.context.update_time_counter;
8882-
8883-
self.funding.funding_tx_confirmation_height = 0;
8884-
8885-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8886-
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8887-
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8888-
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8889-
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8890-
Ok(())
8891-
},
8892-
Err(e) => Err(e)
8871+
/// before the channel has reached channel_ready or splice_locked, and we can just wait for more
8872+
/// blocks.
8873+
pub fn transaction_unconfirmed<L: Deref>(
8874+
&mut self, txid: &Txid, logger: &L,
8875+
) -> Result<(), ClosureReason>
8876+
where
8877+
L::Target: Logger,
8878+
{
8879+
let unconfirmed_funding = core::iter::once(&mut self.funding)
8880+
.chain(self.pending_funding.iter_mut())
8881+
.find(|funding| funding.get_funding_txid() == Some(*txid));
8882+
8883+
if let Some(funding) = unconfirmed_funding {
8884+
if funding.funding_tx_confirmation_height != 0 {
8885+
// We handle the funding disconnection by calling best_block_updated with a height one
8886+
// below where our funding was connected, implying a reorg back to conf_height - 1.
8887+
let reorg_height = funding.funding_tx_confirmation_height - 1;
8888+
// We use the time field to bump the current time we set on channel updates if its
8889+
// larger. If we don't know that time has moved forward, we can just set it to the last
8890+
// time we saw and it will be ignored.
8891+
let best_time = self.context.update_time_counter;
8892+
8893+
funding.funding_tx_confirmation_height = 0;
8894+
8895+
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8896+
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8897+
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8898+
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8899+
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8900+
Ok(())
8901+
},
8902+
Err(e) => Err(e),
8903+
}
8904+
} else {
8905+
// We never learned about the funding confirmation anyway, just ignore
8906+
Ok(())
88938907
}
88948908
} else {
8895-
// We never learned about the funding confirmation anyway, just ignore
88968909
Ok(())
88978910
}
88988911
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11699,11 +11699,8 @@ where
1169911699
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
1170011700
self, || -> NotifyOption { NotifyOption::DoPersist });
1170111701
self.do_chain_event(None, |channel| {
11702-
if let Some(funding_txo) = channel.funding.get_funding_txo() {
11703-
if funding_txo.txid == *txid {
11704-
channel.funding_transaction_unconfirmed(&&WithChannelContext::from(&self.logger, &channel.context, None)).map(|()| (None, Vec::new(), None))
11705-
} else { Ok((None, Vec::new(), None)) }
11706-
} else { Ok((None, Vec::new(), None)) }
11702+
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
11703+
channel.transaction_unconfirmed(txid, &&logger).map(|()| (None, Vec::new(), None))
1170711704
});
1170811705
}
1170911706
}

0 commit comments

Comments
 (0)