Skip to content

Commit 55449b4

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 f8e424f commit 55449b4

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

lightning/src/ln/channel.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8699,32 +8699,46 @@ impl<SP: Deref> FundedChannel<SP> where
86998699
Ok((None, timed_out_htlcs, announcement_sigs))
87008700
}
87018701

8702-
/// Indicates the funding transaction is no longer confirmed in the main chain. This may
8702+
/// Checks if any funding transaction is no longer confirmed in the main chain. This may
87038703
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
8704-
/// before the channel has reached channel_ready and we can just wait for more blocks.
8705-
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8706-
if self.funding.funding_tx_confirmation_height != 0 {
8707-
// We handle the funding disconnection by calling best_block_updated with a height one
8708-
// below where our funding was connected, implying a reorg back to conf_height - 1.
8709-
let reorg_height = self.funding.funding_tx_confirmation_height - 1;
8710-
// We use the time field to bump the current time we set on channel updates if its
8711-
// larger. If we don't know that time has moved forward, we can just set it to the last
8712-
// time we saw and it will be ignored.
8713-
let best_time = self.context.update_time_counter;
8714-
8715-
self.funding.funding_tx_confirmation_height = 0;
8716-
8717-
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8718-
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8719-
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8720-
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8721-
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8722-
Ok(())
8723-
},
8724-
Err(e) => Err(e)
8704+
/// before the channel has reached channel_ready or splice_locked, and we can just wait for more
8705+
/// blocks.
8706+
pub fn transaction_unconfirmed<L: Deref>(
8707+
&mut self, txid: &Txid, logger: &L,
8708+
) -> Result<(), ClosureReason>
8709+
where
8710+
L::Target: Logger,
8711+
{
8712+
let unconfirmed_funding = core::iter::once(&mut self.funding)
8713+
.chain(self.pending_funding.iter_mut())
8714+
.find(|funding| funding.get_funding_txid() == Some(*txid));
8715+
8716+
if let Some(funding) = unconfirmed_funding {
8717+
if funding.funding_tx_confirmation_height != 0 {
8718+
// We handle the funding disconnection by calling best_block_updated with a height one
8719+
// below where our funding was connected, implying a reorg back to conf_height - 1.
8720+
let reorg_height = funding.funding_tx_confirmation_height - 1;
8721+
// We use the time field to bump the current time we set on channel updates if its
8722+
// larger. If we don't know that time has moved forward, we can just set it to the last
8723+
// time we saw and it will be ignored.
8724+
let best_time = self.context.update_time_counter;
8725+
8726+
funding.funding_tx_confirmation_height = 0;
8727+
8728+
match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&dyn NodeSigner, &UserConfig)>, logger) {
8729+
Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
8730+
assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
8731+
assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
8732+
assert!(announcement_sigs.is_none(), "We can't generate an announcement_sigs with 0 confirmations?");
8733+
Ok(())
8734+
},
8735+
Err(e) => Err(e),
8736+
}
8737+
} else {
8738+
// We never learned about the funding confirmation anyway, just ignore
8739+
Ok(())
87258740
}
87268741
} else {
8727-
// We never learned about the funding confirmation anyway, just ignore
87288742
Ok(())
87298743
}
87308744
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11689,11 +11689,8 @@ where
1168911689
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
1169011690
self, || -> NotifyOption { NotifyOption::DoPersist });
1169111691
self.do_chain_event(None, |channel| {
11692-
if let Some(funding_txo) = channel.funding.get_funding_txo() {
11693-
if funding_txo.txid == *txid {
11694-
channel.funding_transaction_unconfirmed(&&WithChannelContext::from(&self.logger, &channel.context, None)).map(|()| (None, Vec::new(), None))
11695-
} else { Ok((None, Vec::new(), None)) }
11696-
} else { Ok((None, Vec::new(), None)) }
11692+
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
11693+
channel.transaction_unconfirmed(txid, &&logger).map(|()| (None, Vec::new(), None))
1169711694
});
1169811695
}
1169911696
}

0 commit comments

Comments
 (0)