Skip to content

Commit ba60013

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 c49f632 commit ba60013

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
@@ -8711,32 +8711,46 @@ impl<SP: Deref> FundedChannel<SP> where
87118711
Ok((None, timed_out_htlcs, announcement_sigs))
87128712
}
87138713

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

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)